473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

displaying inherited button

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
Dec 13 '07 #1
4 1613
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ca*******@yahoo.comwrote in message
news:cb**********************************@s19g2000 prg.googlegroups.com...
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
Dec 13 '07 #2
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
<ca*******@yahoo.comwrote in message
news:cb**********************************@s19g2000 prg.googlegroups.com...
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
Dec 13 '07 #3
On Thu, 13 Dec 2007 07:02:21 -0800, Nicholas Paldino [.NET/C# MVP]
<mv*@spam.guard.caspershouse.comwrote:
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
Dec 13 '07 #4
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Thu, 13 Dec 2007 07:02:21 -0800, Nicholas Paldino [.NET/C# MVP]
<mv*@spam.guard.caspershouse.comwrote:
> 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
Dec 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Terrance | last post by:
Hello all I have a question I'm hoping someone can shed some light on. I have 2 user Inherited Controls on a form. When I click 1 inherited control I would like to change the text of the other...
3
by: Jordan | last post by:
I have created an ascx control that is a kind of custom panel with specific code behind and a custom design. I have then created a new ascx that inherit from my first ascx. The problem that I have...
3
by: Mick Doherty | last post by:
Minimal Code and steps needed to show problem. Inherit from Button and set Region as below. \\\ Protected Overrides Sub OnPaint(ByVal pevent as PaintEventArgs) MyBase.OnPaint(pevent)...
13
by: Lorne Smith | last post by:
Hi, First, sorry for the crosspost, but it seemed appropriate... :) I've come accross what I consider to be a bug, but I don't know if it's already known or not. (VS .Net 2003 Pro - VB.Net) ...
8
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
4
by: JC Voon | last post by:
Hi: My base form has a button, when click it will call MessageBox.Show( "Base form" ). I inherite a child form from the base and assign a button click event to the same button which will call...
4
by: asad.naeem | last post by:
hi to all this is the problem about inheritence. I have designed a form with some essential controls which are required for every form which will inherited from it. for example i have Button1 on...
3
by: polocar | last post by:
Hi, I'm writing a C# program (using Visual Studio 2005 Professional Edition). I have defined a class MyPanel in the following way: class MyPanel : Panel { ... }
4
by: EmilH | last post by:
Hi. I couldn't find it in msdn. I have a form AddCategory. Now I need EditCategory form which should look exactlay like AddCategory. I add an inherited form to the project. Now all controls'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.