CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  控件

如何控制 Text 控件中文本的行间距?

楼主ayusay(阿于)2002-03-15 15:18:35 在 VB / 控件 提问

如何控制   Text   控件中文本的行间距?  
  不是用   RTF   ,而是Text。  
  请高手指点,不胜感谢!!! 问题点数:100、回复次数:35Top

1 楼ayusay(阿于)回复于 2002-03-15 16:33:45 得分 0

有人回答吗?Top

2 楼kailong(凯龙)回复于 2002-03-15 16:38:43 得分 0

利用chr(13)+chr(10)的次数。试试。行吗?Top

3 楼dongdong(阿东)回复于 2002-03-15 16:51:34 得分 0

如果没有搞错,理论上好像不行的。:(Top

4 楼Bardo(巴顿(永远只有一个))回复于 2002-03-15 18:54:43 得分 0

用API创建iFontDisp对象  
  使文本框使用这一字体即可!  
  不过很复杂!!!!Top

5 楼xxlroad(土八路)回复于 2002-03-15 19:43:35 得分 0

我也想得到这种效果Top

6 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2002-03-15 20:17:34 得分 50

创建字体的例子:  
   
  'In   general   section  
  Private   Declare   Function   CreateFontIndirect   Lib   "gdi32"   Alias   "CreateFontIndirectA"   (lpLogFont   As   LOGFONT)   As   Long  
  Private   Declare   Function   SelectObject   Lib   "gdi32"   (ByVal   hdc   As   Long,   ByVal   hObject   As   Long)   As   Long  
  Private   Const   LF_FACESIZE   =   32  
  Private   Type   LOGFONT  
          lfHeight   As   Long  
          lfWidth   As   Long  
          lfEscapement   As   Long  
          lfOrientation   As   Long  
          lfWeight   As   Long  
          lfItalic   As   Byte  
          lfUnderline   As   Byte  
          lfStrikeOut   As   Byte  
          lfCharSet   As   Byte  
          lfOutPrecision   As   Byte  
          lfClipPrecision   As   Byte  
          lfQuality   As   Byte  
          lfPitchAndFamily   As   Byte  
          lfFaceName(LF_FACESIZE)   As   Byte  
  End   Type  
  'In   form  
  Private   Sub   Form_Load()  
          'KPD-Team   1998  
          'URL:   http://www.allapi.net/  
          'E-Mail:   KPDTeam@Allapi.net  
   
          Dim   RotateMe   As   LOGFONT  
          'Set   graphic-mode   to   'persistent   graphic'  
          Me.AutoRedraw   =   True  
          'Rotate   degrees  
          Deg   =   270  
          'Size   (in   points)  
          Size   =   20  
          'Set   the   rotation   degree  
          RotateMe.lfEscapement   =   Deg   *   10  
          'Set   the   height   of   the   font  
          RotateMe.lfHeight   =   (Size   *   -20)   /   Screen.TwipsPerPixelY  
          'Create   the   font  
          rFont   =   CreateFontIndirect(RotateMe)  
          'Select   the   font   n   the   Form's   device   context  
          Curent   =   SelectObject(Me.hdc,   rFont)  
          'Print   some   text   ...  
          Me.CurrentX   =   500  
          Me.CurrentY   =   200  
          Me.Print   ":-)"  
  End   SubTop

7 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2002-03-15 20:18:44 得分 0

至于设置字体,应该是发送“WM_SETFONT”消息。  
  MSDN:  
   
  WM_SETFONT  
  An   application   sends   a   WM_SETFONT   message   to   specify   the   font   that   a   control   is   to   use   when   drawing   text.    
   
  WM_SETFONT    
  wParam   =   (WPARAM)   hfont;                         //   handle   of   font    
  lParam   =   MAKELPARAM(fRedraw,   0);         //   redraw   flag    
     
  Parameters  
  hfont    
  Value   of   wParam.   Handle   to   the   font.   If   this   parameter   is   NULL,   the   control   uses   the   default   system   font   to   draw   text.    
  fRedraw    
  Value   of   lParam.   Specifies   whether   the   control   should   be   redrawn   immediately   upon   setting   the   font.   Setting   the   fRedraw   parameter   to   TRUE   causes   the   control   to   redraw   itself.    
  Return   Values  
  This   message   does   not   return   a   value.    
   
  Remarks  
  The   WM_SETFONT   message   applies   to   all   controls,   not   just   those   in   dialog   boxes.    
   
  The   best   time   for   the   owner   of   a   dialog   box   control   to   set   the   font   of   the   control   is   when   it   receives   the   WM_INITDIALOG   message.   The   application   should   call   theDeleteObject   function   to   delete   the   font   when   it   is   no   longer   needed;   for   example,   after   it   destroys   the   control.    
   
  The   size   of   the   control   does   not   change   as   a   result   of   receiving   this   message.   To   avoid   clipping   text   that   does   not   fit   within   the   boundaries   of   the   control,   the   application   should   correct   the   size   of   the   control   window   before   it   sets   the   font.    
   
  When   a   dialog   box   uses   the   DS_SETFONT   style   to   set   the   text   in   its   controls,   the   system   sends   the   WM_SETFONT   message   to   the   dialog   box   procedure   before   it   creates   the   controls.   An   application   can   create   a   dialog   box   that   contains   the   DS_SETFONT   style   by   calling   any   of   the   following   functions:    
   
  CreateDialogIndirect    
  CreateDialogIndirectParam    
  DialogBoxIndirect    
  DialogBoxIndirectParam    
  QuickInfo  
      Windows   NT:   Requires   version   3.1   or   later.  
      Windows:   Requires   Windows   95   or   later.  
      Windows   CE:   Requires   version   1.0   or   later.  
      Header:   Declared   in   winuser.h.  
   
  See   Also  
  Controls   Overview,   Control   Messages,   CreateDialogIndirect,   CreateDialogIndirectParam,DeleteObject,   DialogBoxIndirect,   DialogBoxIndirectParam,   WM_INITDIALOG,   DLGTEMPLATE    
   
  Top

8 楼ayusay(阿于)回复于 2002-03-15 22:41:23 得分 0

能说详细点吗?我不是特别懂啊Top

9 楼ayusay(阿于)回复于 2002-03-16 20:00:19 得分 0

能说详细点吗?我不是特别懂啊  
   
  Top

10 楼ayusay(阿于)回复于 2002-03-17 16:34:41 得分 0

有人能说详细点吗?Top

11 楼wgku(云霄)回复于 2002-03-17 17:05:09 得分 0

你是不是说要英文翻译???Top

12 楼ayusay(阿于)回复于 2002-03-18 14:28:01 得分 0

我现在只想实现空制文本间距的功能,至于原理,实在没有时间研究了,肯请高手留步,帮帮小弟吧,急用啊~~~~~~~~~~~~~~~~~~~``Top

13 楼Quady515(柱子)回复于 2002-03-18 14:39:19 得分 0

这到没听说过,值得关注Top

14 楼sxychee(一笑)回复于 2002-03-22 15:03:09 得分 0

创建字体的方法,我已试过,可以实现旋转宽高比的设定,可能否设为某一种字体,比如我就要楷体,宽是高的80%,怎么设置,能否详细说一个,另,创建的字体,能否将标签LABEL设置创建的字体?Top

15 楼happybeyond(衣带渐宽怎不悔,VB消得人憔悴~)回复于 2002-03-22 15:18:28 得分 0

upTop

16 楼ayusay(阿于)回复于 2002-03-22 19:06:45 得分 0

高手留步啊~~~~~~~~~~  
   
  不是高手也来看看啊~~~~~~~~~~~~~~~Top

17 楼Bardo(巴顿(永远只有一个))回复于 2002-03-22 19:47:57 得分 50

以下即是创建字体与设置字体的代码:  
  不过这是用的PictureBox  
  Option   Explicit  
   
        Private   Declare   Function   CreateFontIndirect   Lib   "gdi32"   Alias   _  
            "CreateFontIndirectA"   (lpLogFont   As   LOGFONT)   As   Long  
        Private   Declare   Function   SelectObject   Lib   "gdi32"   (ByVal   hdc   _  
            As   Long,   ByVal   hObject   As   Long)   As   Long  
        Private   Declare   Function   DeleteObject   Lib   "gdi32"   (ByVal   _  
            hObject   As   Long)   As   Long  
        Private   Const   LF_FACESIZE   =   32  
   
        Private   Type   LOGFONT  
            lfHeight   As   Long  
            lfWidth   As   Long  
            lfEscapement   As   Long  
            lfOrientation   As   Long  
            lfWeight   As   Long  
            lfItalic   As   Byte  
            lfUnderline   As   Byte  
            lfStrikeOut   As   Byte  
            lfCharSet   As   Byte  
            lfOutPrecision   As   Byte  
            lfClipPrecision   As   Byte  
            lfQuality   As   Byte  
            lfPitchAndFamily   As   Byte  
            lfFaceName   as   String   *   LF_FACESIZE  
        End   Type  
   
        Sub   Command1_Click()  
            Dim   font   As   LOGFONT  
            Dim   prevFont   As   Long,   hFont   As   Long,   ret   As   Long  
            Const   FONTSIZE   =   10   '   Desired   point   size   of   font  
            font.lfEscapement   =   1800         '   180-degree   rotation  
            font.lfFaceName   =   "Arial"   &   Chr$(0)   'Null   character   at   end  
          '   Windows   expects   the   font   size   to   be   in   pixels   and   to  
            '   be   negative   if   you   are   specifying   the   character   height  
            '   you   want.  
            font.lfHeight   =   (FONTSIZE   *   -20)   /   Screen.TwipsPerPixelY  
            hFont   =   CreateFontIndirect(font)  
            prevFont   =   SelectObject(Picture1.hdc,   hFont)  
            Picture1.CurrentX   =   Picture1.ScaleWidth  
            Picture1.CurrentY   =   Picture1.ScaleHeight   /   2  
            Picture1.Print   "Rotated   Text"  
            '   Clean   up   by   restoring   original   font.  
            ret   =   SelectObject(Picture1.hdc,   prevFont)  
            ret   =   DeleteObject(hFont)  
            Picture1.CurrentY   =   Picture1.ScaleHeight   /   2  
            Picture1.Print   "Normal   Text"  
        End   Sub    
   
  Top

18 楼sxychee(一笑)回复于 2002-03-23 09:11:10 得分 0

能否将此字体赋给标签LABEL!标签没有HDC属性!Top

19 楼sxychee(一笑)回复于 2002-03-23 09:37:29 得分 0

让宽是高的80%:  
  font.lfHeight   =   (FONTSIZE   *   -20)   /   Screen.TwipsPerPixelY  
  font.lfWidth   =   (FONTSIZE   *   -20)   *   0.8   *   0.5   /   Screen.TwipsPerPixelX  
  不知是为什么?Top

20 楼ayusay(阿于)回复于 2002-03-24 19:39:31 得分 0

不能编辑吗?那对我来说没有任何意义啊,  
  希望巴大哥再帮帮小弟Top

21 楼vallan(贝贝)回复于 2002-03-24 20:25:08 得分 0

关注  
  Top

22 楼xxlroad(土八路)回复于 2002-03-24 20:43:15 得分 0

还是不用text吧   改用picture吧    
  不过也很麻烦Top

23 楼xxlroad(土八路)回复于 2002-03-24 20:44:01 得分 0

不过我还不能实现  
  只能在打印的时候实现Top

24 楼ayusay(阿于)回复于 2002-03-30 18:12:31 得分 0

还有别的办法吗?Top

25 楼sippey(sippey)回复于 2002-03-30 18:41:29 得分 0

为什么不能用RTBOXTop

26 楼ayusay(阿于)回复于 2002-03-30 19:05:12 得分 0

因为界面需要,我需要Text能够透明Top

27 楼ayusay(阿于)回复于 2002-03-30 23:46:57 得分 0

我顶!Top

28 楼ayusay(阿于)回复于 2002-04-01 18:19:00 得分 0

没有回了吗?Top

29 楼printer(打印机)回复于 2002-04-01 18:55:21 得分 0

文本框能够透明?我还没有这样用过,倒想请教一二Top

30 楼ayusay(阿于)回复于 2002-04-01 21:44:21 得分 0

可以用Form2.0里的文本框啊,Form2.0里的控件都可设置为透明Top

31 楼ayusay(阿于)回复于 2002-04-08 18:09:54 得分 0

upTop

32 楼bestofbest(咖啡)回复于 2002-04-08 18:40:09 得分 0

upTop

33 楼ayusay(阿于)回复于 2002-04-09 16:24:43 得分 0

谢谢   bestofbest(咖啡)   兄帮我顶     :)Top

34 楼ayusay(阿于)回复于 2002-04-11 11:54:43 得分 0

upTop

35 楼ayusay(阿于)回复于 2002-05-23 17:53:30 得分 0

唉……Top

相关问题

  • 关于静态文本控件(Static Text)
  • 如何在text或richtext控件中加入文本?
  • text文本框控件如何拦截“PgUp、PgDn、Up、DoWn”事件
  • 有没有办法调整text控件中的文本行距?
  • 如何给一个textarea(文本峪)控件的“TEXT”附值
  • 如何禁止用户在text控件中选择文本
  • 文本控件的问题
  • 文本控件的困惑
  • 在TEXT文本框(数组控件)中只某个控件只允许输入数字,如何实现?
  • 如何设置meomo控件行间距?

关键词

  • .net
  • 字体
  • 间距
  • 控件
  • 文本
  • facesize
  • logfont
  • fredraw
  • setfont
  • gdi32

得分解答快速导航

  • 帖主:ayusay
  • zyl910
  • Bardo

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo