winform 自定义textbox,文字的四周间距问题 RRS feed

  • 问题

  • 文本框光标总是贴着边框,这个怎么解决?richtextbox好像可以通过SelectionIndent控制光标缩进,但是文字还是很靠上边缘,所以就是这个文本框的文字的边距问题怎么控制
    2016年8月15日 3:34


  • 可能要变通一下实现,将TextBox放到Panel中实现

    As you have most likely discovered, Winforms Textboxes do not have a padding property. Since Panels do expose a Padding property, one technique would be to:

    1. Create a Panel
    2. Set its border to match a Textbox (e.g., Fixed3D)
    3. Set its background color to match a Textbox (e.g., White or Window)
    4. Set its padding to your satisfaction (e.g., 10,3,10,3)
    5. Add a Textbox inside the panel
    6. Set the Textbox's border to none
    7. Play with the Textbox's Dock and Anchor properties do get desired effect

    This should get you started. You could also create a custom control that does the same thing as mentioned above.

    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2016年8月15日 6:07