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 );
}