玩酷之家

 找回密码
 给爷来个号
查看: 550|回复: 0

【VB.NET】调整 RichTextBox 行距(控件创建时调用才有效)

[复制链接]

20

主题

21

帖子

909

积分

高级会员

Rank: 4

积分
909
QQ
发表于 2020-2-6 10:17:22 | 显示全部楼层 |阅读模式
本帖最后由 1059-Studio 于 2020-2-6 10:19 编辑
  1.     Public Const WM_USER As Integer = &H400
  2.     Public Const EM_GETPARAFORMAT As Integer = WM_USER + 61
  3.     Public Const EM_SETPARAFORMAT As Integer = WM_USER + 71
  4.     Public Const MAX_TAB_STOPS As Long = 32
  5.     Public Const PFM_LINESPACING As UInteger = &H100

  6.     <StructLayout(LayoutKind.Sequential)> _
  7.     Private Structure PARAFORMAT2
  8.         Public cbSize As Integer
  9.         Public dwMask As UInteger
  10.         Public wNumbering As Short
  11.         Public wReserved As Short
  12.         Public dxStartIndent As Integer
  13.         Public dxRightIndent As Integer
  14.         Public dxOffset As Integer
  15.         Public wAlignment As Short
  16.         Public cTabCount As Short
  17.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
  18.         Public rgxTabs As Integer()
  19.         Public dySpaceBefore As Integer
  20.         Public dySpaceAfter As Integer
  21.         Public dyLineSpacing As Integer
  22.         Public sStyle As Short
  23.         Public bLineSpacingRule As Byte
  24.         Public bOutlineLevel As Byte
  25.         Public wShadingWeight As Short
  26.         Public wShadingStyle As Short
  27.         Public wNumberingStart As Short
  28.         Public wNumberingStyle As Short
  29.         Public wNumberingTab As Short
  30.         Public wBorderSpace As Short
  31.         Public wBorderWidth As Short
  32.         Public wBorders As Short
  33.     End Structure

  34.     <DllImport("user32", CharSet:=CharSet.Auto)> _
  35.     Private Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lParam As PARAFORMAT2) As IntPtr
  36.     End Function
复制代码
  1.     ''' <summary>
  2.     ''' 设置行距
  3.     ''' </summary>
  4.     ''' <param name="ctl">控件</param>
  5.     ''' <param name="dyLineSpacing">间距</param>
  6.     Public Sub SetLineSpace(ctl As Control, dyLineSpacing As Integer)
  7.         Dim fmt As New PARAFORMAT2()
  8.         fmt.cbSize = Marshal.SizeOf(fmt)
  9.         fmt.bLineSpacingRule = 4
  10.         ' bLineSpacingRule;
  11.         fmt.dyLineSpacing = dyLineSpacing
  12.         fmt.dwMask = PFM_LINESPACING
  13.         Try
  14.             SendMessage(New HandleRef(ctl, ctl.Handle), EM_SETPARAFORMAT, 0, fmt)
  15.         Catch
  16.         End Try
  17.     End Sub
复制代码
  1. SetLineSpace(Me.RichTextBox1, 300)
复制代码
湖边的稻草 1059 Studio
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 给爷来个号

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号-1 )|

GMT+8, 2020-8-6 05:35 , Processed in 1.092002 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表