| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 874 人关注过本帖
标题:请教编辑框自动通过改变字号显示全部文字,不出现滚动条,如何实现?辛苦老 ...
只看楼主 加入收藏
hsfisher
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:160
专家分:131
注 册:2009-4-26
收藏
得分:0 
2025-05-18 12:56
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10823
专家分:43424
注 册:2014-5-20
收藏(1)
得分:0 
回复 9楼 csyx
如果只是显示用也可以不用editbox,直接用form就无需转来转去,且可以使用Unicode。

图片附件: 游客没有浏览图片的权限,请 登录注册

可以测试一下

程序代码:
cText = '在Visual FoxPro (VFP)中,AutoYield 属性用于控制程序在执行代码时' ;
      + '是否允许处理Windows事件(如鼠标点击、键盘输入等)。默认情况下,' ;
      + 'AutoYield是开启的(.T.),这意味着VFP会在代码执行期间定期处理事件。';
      + 0h0d0a0d0a ;
      + 'DrawTextEx是一个在Windows图形设备接口(GDI)中用于绘制复杂文本的函数。' ;
      + '它提供了多种文本格式化选项,如文字换行、字体选择、对齐方式等,' ;
      + '允许开发者精确控制文本在屏幕或打印输出上的显示效果。'+0h00

DECLARE long  GetDC          IN user32 long
DECLARE long  ReleaseDC      IN user32 long,long
DECLARE long  DrawTextExW    IN user32 long,string,long,string,long,string
DECLARE long  SetParent      IN user32 long,long
DECLARE long  PostMessageA   IN user32 long,long,long,long

#define MY_MESSAGE                 0x0401
#define DT_WORDBREAK               0x00000010
#define DT_EXPANDTABS              0x00000040
#define DT_TABSTOP                 0x00000080
#define DT_NOCLIP                  0x00000100
#define DT_EXTERNALLEADING         0x00000200
#define DT_CALCRECT                0x00000400
#define DT_NOPREFIX                0x00000800
#define DT_EDITCONTROL             0x00002000

of = CREATEOBJECT("form1")
of.show(1)
CLEAR ALL
RETURN

DEFINE CLASS form1 as Form
    width = 500
    height = 330
    minwidth = 200
    minheight = 200
    AutoCenter  = .t.
    AllowOutput = .f.
    
    oChild       = 0
    leftMargin   = 0
    topMargin    = 0
    rightMargin  = 0
    bottomMargin = 0
    cFontStyle   = "N"
    
    ADD OBJECT combo1  as combobox      WITH left=10, top=10,width=200,height=24,Style=2
    ADD OBJECT button1 as commandbutton WITH left=220,top=10,width=100,height=24,caption="SetFont"
        
    PROCEDURE init
        BINDEVENT(this.hWnd, MY_MESSAGE, this, "msgPaint")
        this.oChild = CREATEOBJECT("formChild", 10, 50, 400, 200, 0, 8, this)
        SetParent(this.oChild.hWnd, this.hWnd)
        this.leftMargin   = this.oChild.Left - this.Left
        this.topMargin    = this.oChild.Top  - this.Top
        this.rightMargin  = this.Left+this.Width  - this.oChild.left - this.oChild.width
        this.bottomMargin = this.Top +this.Height - this.oChild.Top  - this.oChild.Height
        this.oChild.show
    ENDPROC
    
    PROCEDURE ReSize 
        this.oChild.width  = this.Width  - this.leftMargin - this.rightMargin
        this.oChild.height = this.Height - this.topMargin  - this.bottomMargin
        PostMessageA(this.hWnd, MY_MESSAGE, 0, 0)
    ENDPROC
    
    PROCEDURE Destroy
        UNBINDEVENTS(this.hWnd)
    ENDPROC
    
    PROCEDURE combo1.init 
        AFONT(arr)
        FOR i=1 TO ALEN(arr)
            this.AddItem(arr[i])
        ENDFOR
        this.value = "宋体"
    ENDPROC
    
    PROCEDURE combo1.InteractiveChange
        thisform.oChild.fontname = ALLTRIM()
        PostMessageA(thisform.hWnd, MY_MESSAGE, 0, 0)
    ENDPROC
    
    PROCEDURE button1.click
        IF ALINES(arr,GETFONT(thisform.oChild.fontname,thisform.oChild.fontsize,thisform.cFontStyle),5,",") == 3
            thisform.oChild.FontName   = arr[1]
            thisform.oChild.FontBold   = IIF(INLIST(arr[3],"B","BI"), .t., .f.)
            thisform.oChild.FontItalic = IIF(INLIST(arr[3],"I","BI"), .t., .f.)
             = arr[1]
            thisform.cFontStyle   = arr[3]
            PostMessageA(thisform.hWnd, MY_MESSAGE, 0, 0)
        ENDIF  
    ENDPROC 
    
    FUNCTION msgPaint(hWnd, uMsg, wParam, lParam)
        this.oChild.cls    && 会触发paint事件重绘
    ENDPROC 
ENDDEFINE

DEFINE CLASS formChild as Form
    Backcolor   = 0x00FFFFFF
    BorderStyle = 1
    TitleBar    = 0
    FontName    = "宋体"
    AllowOutput = .f.
    
    margin      = 0
    minFontSize = 8
    oParent     = 0
    hdc         = 0
    fmtDrawn    = BITOR(DT_EDITCONTROL,DT_EXPANDTABS,DT_EXTERNALLEADING,DT_NOCLIP,DT_NOPREFIX,DT_TABSTOP,DT_WORDBREAK) 
    fmtNotDrawn = BITOR(this.fmtDrawn, DT_CALCRECT) 
    
    PROCEDURE Destroy
        ReleaseDC(this.hWnd, this.hdc)
    ENDPROC
    
    PROCEDURE init(nLeft, nTop, nWidth, nHeight, nMargin, nMinFontSize, oParent)
        this.Left        = nLeft
        this.Top         = nTop
        this.Width       = nWidth
        this.Height      = nHeight
        this.margin      = nMargin
        this.minFontSize = nMinFontSize
        this.oParent     = oParent
        this.hdc         = GetDC(this.hWnd)
    ENDPROC 
    
    PROCEDURE paint
        this. = .f.
        this.oParent.button1.Enabled = .f.
        rec = BINTOC(this.margin,"4rs")+BINTOC(this.margin,"4rs")+BINTOC(this.width-this.margin,"4rs")+BINTOC(this.height-this.margin,"4rs")
        nDrawnHeight = this.height - this.margin*2
        this.FontSize = this.minFontSize   
        DO WHILE (this.FontSize < 128) AND (nDrawnHeight >= DrawTextExW(this.hdc, STRCONV(cText,5), -1, rec, this.fmtNotDrawn, NULL)) 
            this.oParent.caption = " 稍候... FontSize: "+TRANSFORM(this.FontSize)
            this.FontSize = this.FontSize + 1
        ENDDO
        this.FontSize = this.FontSize - 1
        this.oParent.caption = " FontSize: "+TRANSFORM(this.FontSize)
        DrawTextExW(this.hdc, STRCONV(cText,5), -1, rec, this.fmtDrawn, NULL) 
        this. = .t.
        this.oParent.button1.Enabled = .t.
    ENDPROC
ENDDEFINE

修复窗口最大化、最小化缩放重新绘制问题

[此贴子已经被作者于2025-11-4 16:25编辑过]

3 天前 23:13
schtg
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:Usa
等 级:贵宾
威 望:67
帖 子:2301
专家分:4810
注 册:2012-2-29
收藏
得分:0 
回复 12楼 吹水佬
学习啦,谢谢!
前天 05:24
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10823
专家分:43424
注 册:2014-5-20
收藏
得分:0 
12楼修复缩放问题
前天 08:50
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10823
专家分:43424
注 册:2014-5-20
收藏
得分:0 
12楼修复窗口最大化、最小化缩放重新绘制问题
前天 23:44
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10823
专家分:43424
注 册:2014-5-20
收藏
得分:0 
code标签贴代码也会出现乱码?
改了一下重新补贴上
昨天 16:28
快速回复:请教编辑框自动通过改变字号显示全部文字,不出现滚动条,如何实现?辛 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024617 second(s), 11 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved