473,657 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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()
{
InitializeCompo nent();

}
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 1621
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.co m

<ca*******@yaho o.comwrote in message
news:cb******** *************** ***********@s19 g2000prg.google groups.com...
Should be easy don't know y i cant get it to work please help.
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();

}
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( oneInputParamet er) - resulting width = length =
oneInputParamet er
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*******@yaho o.comwrote in message
news:cb******** *************** ***********@s19 g2000prg.google groups.com...
Should be easy don't know y i cant get it to work please help.
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();

}
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.c omwrote:
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.co m

"Peter Duniho" <Np*********@nn owslpianmk.comw rote 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.c omwrote:
> 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
1283
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 Inherited Control. Is there anyway to do this? For example, I have an ADD button which is inherited and a EXIT button which is inherited. The reason I made them inherited is because I want to use the function of these buttons in other forms and don't...
3
1795
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 is that doing so, if I put a new control inside my inherited ascx and put code behind this new control,this code will not execute. So is there a way to create a child control an have the specific code behind it execute and not just is parent...
3
1266
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) Me.Region = New Region(New Rectangle(5, 5, Width - 10, Height - 10)) End Sub ///
13
2224
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) Whilst playing with inherited forms, I created a simple base form containing a single button. I set this buttons' Click event to be public overridable and put "me.Close" in the code.
8
6699
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 contains a few controls anchored to the sides of the form. "frmChild" inherits from "frmBase"... and the controls appear on the inherited form as expected. However things start going wrong when I place addition controls on the "frmChild" form. When I...
4
2648
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 MessageBox.Show( "Inherited form" ). I run my application, and load the clild form, click the button it show both message !!! Is there any way to control the event sequence so that it only show the child form event, or i can control whether to...
4
1939
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 parent form and this button is visible to me on inherited form. The problem is: I have written a click event of the button1 on both of the forms. tell me the way if i click the button on inherited form only parents' click event will be called and...
3
1813
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
3498
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' properties are read-only. I need to change AddButton's Name and Text properties to Edit. I change Modifier property of the parent control to public, but it doesn't solve. Can anybody help me? Thanks.
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.