Harsh
Harsh

Reputation: 3751

Customizing button text appearance

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.

enter image description here

Button 1 represents how the text appears by default. And Button 2 is the output to achieve.

Upvotes: 1

Views: 2615

Answers (4)

Jignesh Thakker
Jignesh Thakker

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:

enter image description here

Output of Button UI:

enter image description here

Upvotes: 3

Deepak Sharma
Deepak Sharma

Reputation: 4170

there is no need to drive your own class there is a property on Button class in C# and VB both..

enter image description here

VB

Me.Button2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft

C#

this.button1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

Happy Coding and Sharing .. :)

Upvotes: -1

StackTrace
StackTrace

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

ZahidKakar
ZahidKakar

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

Related Questions