displaying inherited button

C

cameljs18

Should be easy don't know y i cant get it to work please help.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}


public class mybutton : Button
{

}
}
I also need to find out how to override the properties to create a
different shape eg. a round button.Thanks
 
D

DSK Chakravarthy

When you look at the system defined controls like Button, they have
predefined sizes inherited from System.Drawing.Size. This Point has only 3
overloads such as
1) Default - resulting 0 width and 0 length
2) System.Drawing.Point( oneInputParameter) - resulting width = length =
oneInputParameter
3) Width and length - both as the different input parameters

So, by looking at the above information, I doubt you can over ride the shape
information.

But apart of that, you still can do the intention behind having a separate
shape.

Step 1) First create an ENum of all shapes
Step 2) Create a property for the derived button as "DifferentShape"
Step 3) At the property try to change the shape of the button with a kind of
image on the button at runtime, with the help of System.Drawing dynamically

HTH

Chakravarthy
 
N

Nicholas Paldino [.NET/C# MVP]

Well, you should probably declare the button somewhere outside of your
Form1 class, unless the myButton class is tied specifically to Form1.

Also, you will need to override the OnPaint method to change the
appearance of the button.
 
P

Peter Duniho

Well, you should probably declare the button somewhere outside of
your Form1 class, unless the myButton class is tied specifically to
Form1.

Also, you will need to override the OnPaint method to change the
appearance of the button.

Keeping mind that if the Button control is like many of the other Forms
controls, overriding OnPaint() doesn't actually prevent the original
Button drawing from happening, because the control doesn't actually use
OnPaint() for its drawing.

I don't actually know specifically whether the Button control is one of
those, but many Forms controls require a lot more work to override their
default drawing behavior than just overriding OnPaint(). It's certainly
worth a try, but it may be more complicated than that.

Pete
 
N

Nicholas Paldino [.NET/C# MVP]

I agree. Specifically, the OP will have to override the WndProc method
and handle the WM_PAINT message, and not call the base implementation if
they want to paint the button themselves.

You can override OnPaint if what needs to be painted paints over the
existing graphics.

Honestly, though, Windows Forms/GDI just doesn't support this scenario
well. WPF, however, handles it very well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top