Adjust the line spacing of RichTextBox

Source: Internet
Author: User

Today, I made a prompt and needed to control the line spacing of text display. I originally wanted to use label for it. Later I found that there are no relevant properties to set. I searched the internet for it, the only method seems to be to control the re-painting by yourself, so I didn't want to use such troublesome processing. So I tried another control RichTextBox and found that there was still no attribute that could be directly set, however, it can be implemented through APIS. The implementation method is as follows:

// Define constants:

// I do not know what to use

Public const int wm_user = 0x0400;
Public const int em_getparaformat = wm_user + 61;
Public const int em_setparaformat = wm_user + 71;
Public const long max_tab_stops = 32;
Public const uint pfm_linespacing = 0x00000100;

// Define the struct. Why is this definition unknown?

[Structlayout (layoutkind. Sequential)]
Private struct paraformat2 {
Public int cbsize;
Public uint dwmask;
Public short wnumbering;
Public short wreserved;
Public int dxstartindent;
Public int dxrightindent;
Public int dxoffset;
Public short walignment;
Public short ctabcount;
[Financialas (unmanagedtype. byvalarray, sizeconst = 32)]
Public int [] rgxtabs;
Public int dyspacebefore;
Public int dyspaceafter;
Public int dylinespacing;
Public short sstyle;
Public byte blinespacingrule;
Public byte boutlinelevel;
Public short wshadingweight;
Public short wshadingstyle;
Public short wnumberingstart;
Public short wnumberingstyle;
Public short wnumberingtab;
Public short wborderspace;
Public short wborderwidth;
Public short wborders ;}

// Define a function

[Dllimport ("USER32", charset = charset. Auto)]
Private Static extern intptr sendmessage (handleref hwnd, int MSG, int wparam, ref paraformat2 iparam );

// Call the following method:

Private void setlinespace (INT linespace)

{

Paraformat2 pformat = new paraformat2 ();
Pformat. cbsize = marshal. sizeof (pformat );
Pformat. blinespacingrule = 4;
Pformat. dylinespacing = linespace;

Pformat. dwmask = pfm_linespacing;
Sendmessage (New handleref (this. richtextbox1, richtextbox1.handle ),

Em_setparaformat, 4, ref pformat );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.