tags:

views:

1192

answers:

3
+1  Q: 

C# Custom Button

Hello,

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

A: 

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.

Paul Ruane
+1  A: 

What functionality are you trying to achieve ? Perhaps it would be a better fit to 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 yoy 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.

driis
A: 

Thanks for the help,

This is a WinForm control that inherits the Button class. I guess I will do the drawing image logic myself. I was hoping for a way to override drawing specific elements of the button (such as the background only for example).

Thanks again