Reputation: 2689
I am currently writing a little helper-app for my "big" WinForms-Project. In this little app I am showing a UserControl with a few Buttons on it. Now there are those standard-text-to-button-margins.
What I mean is, that Buttons look like this:
~~~~~~~~~~~~~
~ ~
~ ButtonText ~
~ ~
~~~~~~~~~~~~~
But I want that the ButtonText nearly "touches" the buttonbounds. In other words: The standard space between ButtonText and Buttonbounds is too big for my needs. Is it possible to change this behaviour?
Upvotes: 1
Views: 3517
Reputation: 13424
You can override the paint event on the button and use ControlPaint.DrawButton(...)
along with regular string drawing to control the button layout to your needs. You will have to hook MoseDown, MouseUp, etc. to get the button drawn the correct state (depressed, hot, etc.).
Upvotes: 1
Reputation: 62377
To achieve this, you could create a UserControl
that contains a docked button, then you can override the behaviour of your UserControl
so that when it auto-sizes, it sizes smaller than the button would normally require and thus forces the button text to sit closer to the edge. However, you'll need to use some trial an error to ensure that the text is visible for all DPI settings.
You could also consider using ToolStripButton
s instead, with an appropriate renderer that makes them look like regular buttons. These often size smaller and you should have more control over the padding and margins of the text within the button, depending on how much customization you provide.
Upvotes: 0