Reputation: 3751
I am working on a vb.net winform application. By default the text on a button starts after a little space. I need to start the text from the border itself without any space. And also i want to control the spacing by adding some indentation value.
But there are no button properties to control this. Can you please suggest some ways to achieve this. Below is the image to demonstrate the requirement.
Button 1 represents how the text appears by default. And Button 2 is the output to achieve.
Upvotes: 1
Views: 2615
Reputation: 3698
You need to handle Paint event of button to draw string on Button.
Like:
Private Sub Button1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
Button1.Text = String.Empty
e.Graphics.DrawString("Test", Button1.Font, Brushes.Black, New Point(0, 5))
End Sub
And Set FlatStyle, BorderColor, BorderSize Properties:
Output of Button UI:
Upvotes: 3
Reputation: 4170
there is no need to drive your own class there is a property on Button class in C# and VB both..
VB
Me.Button2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
C#
this.button1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
Happy Coding and Sharing .. :)
Upvotes: -1
Reputation: 9416
Fot that kind of customization, you will need to create a custom winforms control.
Check this CP article http://www.codeproject.com/Articles/4871/Divider-Panel-A-tutorial-on-creating-a-custom-Wind
Upvotes: 1
Reputation: 212
I would suggest you to use image instead of using text. Set image as buttons background image or simple button image and then you can move text to any corner by using alignment property.
Upvotes: 0