TaleofTimes
TaleofTimes

Reputation:

C# Custom Button

I'm attempting to write a custom button user control. I have run into a challenge when drawing the image.

Is there a simple way to draw the image accounting for the ImageAlign and TextImageRelation? (Kind of like StringFormat makes text aligning a breeze)

Or do I have to do all the aligning logic and stuff manually?

Thanks

Upvotes: 1

Views: 2231

Answers (2)

driis
driis

Reputation: 164341

What functionality are you trying to achieve? Perhaps it should instead inherit from the Button class (asssuming WinForms), and override appropiate methods. Depending on what you need to do, you will propably get much of the lower levels of functionality in the button for free, if you do this.

To get back to your question; No, if you need to draw stuff yourself, there is no magic easy way to determine where the individual pixels should go :-) One great helper in doing this, that you should be aware of, is the Graphics.DrawString method. It lets you measure the dimensions of a given text string when drawn on the control with the selected font and size.

Upvotes: 1

Paul Ruane
Paul Ruane

Reputation: 38620

I do not know of anything that does this stuff for you, but be aware of the ControlPaint class as that has a bunch of handy utility methods for painting controls.

Upvotes: 0

Related Questions