设置RichTextbox行间距(转)

RichTextbox虽然内置的功能已经很强大了,但是还是有些功能没有提供,就比如“行间距”,不知道其内置的功能是否可以实现,这里在网上找到一个使用win32来设置的

 

 

复制代码
 1  public   const   int  WM_USER  =   0x0400 ;
 2           public   const   int  EM_GETPARAFORMAT  =  WM_USER  +   61 ;
 3           public   const   int  EM_SETPARAFORMAT  =  WM_USER  +   71 ;
 4           public   const   long  MAX_TAB_STOPS  =   32 ;
 5           public   const   uint  PFM_LINESPACING  =   0x00000100 ;
 6          [StructLayout(LayoutKind.Sequential)]
 7           private   struct  PARAFORMAT2
 8          {
 9               public   int  cbSize;
10               public   uint  dwMask;
11               public   short  wNumbering;
12               public   short  wReserved;
13               public   int  dxStartIndent;
14               public   int  dxRightIndent;
15               public   int  dxOffset;
16               public   short  wAlignment;
17               public   short  cTabCount;
18              [MarshalAs(UnmanagedType.ByValArray, SizeConst  =   32 )]
19               public   int [] rgxTabs;
20               public   int  dySpaceBefore;
21               public   int  dySpaceAfter;
22               public   int  dyLineSpacing;
23               public   short  sStyle;
24               public   byte  bLineSpacingRule;
25               public   byte  bOutlineLevel;
26               public   short  wShadingWeight;
27               public   short  wShadingStyle;
28               public   short  wNumberingStart;
29               public   short  wNumberingStyle;
30               public   short  wNumberingTab;
31               public   short  wBorderSpace;
32               public   short  wBorderWidth;
33               public   short  wBorders;
34          }
35 
36          [DllImport( " user32 " , CharSet  =  CharSet.Auto)]
37           private   static   extern  IntPtr SendMessage(HandleRef hWnd,  int  msg,  int  wParam,  ref  PARAFORMAT2 lParam);
38 
39           ///   <summary>
40           ///  设置行距
41           ///   </summary>
42           ///   <param name="ctl"> 控件 </param>
43           ///   <param name="dyLineSpacing"> 间距 </param>
44           public   static   void  SetLineSpace(Control ctl,  int  dyLineSpacing)
45          {
46              PARAFORMAT2 fmt  =   new  PARAFORMAT2();
47              fmt.cbSize  =  Marshal.SizeOf(fmt);
48              fmt.bLineSpacingRule  =   4 ; //  bLineSpacingRule;
49              fmt.dyLineSpacing  =  dyLineSpacing;
50              fmt.dwMask  =  PFM_LINESPACING;
51               try
52              {
53                  SendMessage( new  HandleRef(ctl, ctl.Handle), EM_SETPARAFORMAT,  0 ref  fmt);
54              }
55               catch
56              {
57 
58              }
59          }
复制代码

 

然后可以在Form_Load事件里面调用,代码如下:

       

SetLineSpace(txt_content,  300 );

 

第一个参数是一个Control类型的比如richtextbox1,第二个就是行间距了,哈哈,很简单吧。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值