Rich Text Box padding between text and border

前端 未结 11 2172
我在风中等你
我在风中等你 2021-02-02 10:48

Is it possible to add padding into a Rich Text Box control between the text and the border?

I tried docking a rich text box inside of a panel, with its padding for all f

11条回答
  •  广开言路
    2021-02-02 11:08

    Here is a simple solution for setting the left and right margins of a RichTextBox that worked well for me in a C# Windows app. It sets both the right and left margins to 4 pixels.

    [DllImport("user32.dll")]
    static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);
    
    // both left and right margins set to 4 pixels with the last parm: 0x00040004
    SendMessage(richtextbox1.Handle, 0xd3, (UIntPtr)0x3, (IntPtr)0x00040004);
    

    I tried to make the SendMessage more proper below:

    const int EM_SETMARGINS = 0xd3;
    const int EC_LEFTMARGIN = 0x1;
    const int EC_RIGHTMARGIN = 0x2;
    
    SendMessage(richtextbox1.Handle, EM_SETMARGINS,
     (UIntPtr)(EC_LEFTMARGIN | EC_RIGHTMARGIN), (IntPtr)0x00040004);
    

    I figure this solution was not possible when the question was originally posted.

提交回复
热议问题