Brijesh Patel
Brijesh Patel

Reputation: 2958

how to give padding to the RichTextBox control in VB.Net?

I am developing windows application in vb.net. In that i have a RichTextBox Control in one of the form. Now i want some padding in the richtextbox. So my text will be start after some space (padding) like word document.

Text start from inner square.

So Can any one give some idea how to give padding to the RichTextBox control?

Thanks in Advance.

Upvotes: 1

Views: 5098

Answers (2)

Rich Miller
Rich Miller

Reputation: 11

I had a similar issue and this worked for me and least for the left margin. Basically I selected all of the text and set the indent.

With RTB        'This changes the left margin for the whole thing
  Dim OldSelStart As Integer = .SelectionStart
  Dim OldSelLen As Integer = .SelectionLength
  .SelectionStart = 0
  .SelectionLength = Len(.Text)
  .SelectionIndent = 10
  .SelectionStart = OldSelStart
  .SelectionLength = OldSelLen
End With

Upvotes: 1

Rob P.
Rob P.

Reputation: 15071

There is no built-in property to allow for padding. You could create your own control and handle the painting yourself (or find someone else who has - http://www.codeproject.com/Articles/21437/A-Padded-Rich-Text-Box-Subclass); but you might be able to easily achieve the look you want by docking the RichTextBox inside of a Panel.

Panel does have a Padding property.

If you use the same BackColor it might give the desired affect. Scroll bars might look 'off' though; if you need it to scroll things will get more complicated - I think you'd be able to use a VScrollBar - with the same height as the Panel but managing the scrolling will get complicated. You'd want to stop the RichTextBox from showing it's scroll bar; but you'll need to manage the scrolling with the VScrollBar.

If there aren't any better solutions offered up; I'll give this a try tonight and see if I can get it working :)

Upvotes: 3

Related Questions