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

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

可以测试一下

程序代码:
DECLARE long GetDC          IN user32 long
DECLARE long ReleaseDC      IN user32 long,long
DECLARE long DrawTextExW    IN user32 long,long,long,string,long,string@
DECLARE long SetParent      IN user32 long,long
DECLARE long PostMessageA   IN user32 long,long,long,long

DECLARE long wcscpy IN msvcrt long,string
DECLARE long wcslen IN msvcrt long
DECLARE long malloc IN msvcrt long
DECLARE long free   IN msvcrt as freebuffer 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
#define DT_NOFULLWIDTHCHARBREAK    0x00080000

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

cText = STRCONV(cText, 5)

    * 如果不想保持数字号码或字母单词的完整性,这样右边界会较整齐点。
    * 使用 DT_NOFULLWIDTHCHARBREAK 格式防止遇到数字号码或字母单词后空格(单词分隔符)自动换行。
    * 使用 DT_NOFULLWIDTHCHARBREAK 格式时当遇到半角空格(U+0020)、制表符(U+0009)时会自动换行,
    * 此时,要将半角空格(U+0020)、制表符(U+0009)替换为全角空格(U+00A0)。
cText = STRTRAN(cText, 0h2000, 0hA000) 
cText = STRTRAN(cText, 0h0900, REPLICATE(0hA000,4))

pText = malloc(LEN(cText))
wcscpy(pText, cText)

of = CREATEOBJECT("form1")
of.show(1)
freebuffer(pText)
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, 3, 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,DT_NOFULLWIDTHCHARBREAK) 
    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, pText, -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, pText, -1, rec, this.fmtDrawn, NULL)
        this. = .t.
        this.oParent.button1.Enabled = .t.
    ENDPROC
ENDDEFINE

使用 DT_NOFULLWIDTHCHARBREAK 格式防止遇到数字号码、字母单词后空格(单词分隔符)自动换行的问题?



[此贴子已经被作者于2025-11-5 23:57编辑过]

5 天前 23:13
schtg
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:Usa
等 级:贵宾
威 望:67
帖 子:2307
专家分:4810
注 册:2012-2-29
收藏
得分:0 
回复 12楼 吹水佬
学习啦,谢谢!
4 天前 05:24
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10831
专家分:43438
注 册:2014-5-20
收藏
得分:0 
12楼修复缩放问题
4 天前 08:50
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10831
专家分:43438
注 册:2014-5-20
收藏
得分:0 
12楼修复窗口最大化、最小化缩放重新绘制问题
4 天前 23:44
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10831
专家分:43438
注 册:2014-5-20
收藏
得分:0 
code标签贴代码也会出现乱码?
改了一下重新补贴上
3 天前 16:28
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10831
专家分:43438
注 册:2014-5-20
收藏
得分:0 
12楼代码探讨一下:
如果不想保持数字号码或字母单词的完整性,使用 DT_NOFULLWIDTHCHARBREAK 格式防止遇到数字号码、字母单词后空格(单词分隔符)自动换行的问题?
前天 22:30
sych
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:7
帖 子:449
专家分:703
注 册:2019-10-11
收藏
得分:0 
每天来群里转一圈,天天有收获,谢谢吹版付出
昨天 11:06
wxzd123
Rank: 2
等 级:论坛游民
帖 子:474
专家分:96
注 册:2012-9-6
收藏
得分:0 
给吹版点赞
昨天 12:38
快速回复:请教编辑框自动通过改变字号显示全部文字,不出现滚动条,如何实现?辛 ...
数据加载中...
 
   



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

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