473,806 Members | 2,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I separate form code and put it into classes?? inheritance?

hey, how do I take form code and put it into separate classes? more
specifically,
I want to create like a panel class, and put buttons in it and give these
buttons click events. and all my form has to show is the empty panel. then
tell the panel to inherit from the panel class so it has all those buttons
and click events... that way I can make like 10 panel classes, and when I
want to display a panel, I just tell it to inherit from one of the classes.

I know that the base class is going to have to inherit from the UserControl
class, but how exactly do I do it? any help? thanks.
Feb 28 '07 #1
5 1787
You'd make a control that inherits from panel.

Then you stick all your butons on and do your requirements and make some
events accessbile from outside so that when you use it they can hook to that
event and fire code based ont he clicks of the buttons.

Then when done, include that dll of it in any app and it will appear in the
designer. just drag and drop it into a form.

You don't get your form to inherit the panel itself tho.

"roger_27" <ro*****@discus sions.microsoft .comwrote in message
news:9D******** *************** ***********@mic rosoft.com...
hey, how do I take form code and put it into separate classes? more
specifically,
I want to create like a panel class, and put buttons in it and give these
buttons click events. and all my form has to show is the empty panel. then
tell the panel to inherit from the panel class so it has all those buttons
and click events... that way I can make like 10 panel classes, and when I
want to display a panel, I just tell it to inherit from one of the
classes.

I know that the base class is going to have to inherit from the
UserControl
class, but how exactly do I do it? any help? thanks.

Mar 1 '07 #2
You don't really want to do this. Inheritance is a way of defining classes.
A class definition is not the same thing as a class instance. A Control in
an application is not a class, but an instance of a class. So, let's say you
have an empty Panel. You want to populate it with some Controls. If you
create an instance of some Control that inherits that Panel class, you are
creating a new Control, rather than populating the Panel that existed in the
first place. As to what you *should* do, I can't say, because you haven't
identified your requirements clearly.

--
HTH,

Kevin Spencer
Microsoft MVP

Help test our new betas,
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"roger_27" <ro*****@discus sions.microsoft .comwrote in message
news:9D******** *************** ***********@mic rosoft.com...
hey, how do I take form code and put it into separate classes? more
specifically,
I want to create like a panel class, and put buttons in it and give these
buttons click events. and all my form has to show is the empty panel. then
tell the panel to inherit from the panel class so it has all those buttons
and click events... that way I can make like 10 panel classes, and when I
want to display a panel, I just tell it to inherit from one of the
classes.

I know that the base class is going to have to inherit from the
UserControl
class, but how exactly do I do it? any help? thanks.

Mar 1 '07 #3
I just want to have as little code in the presentation layer as possible. how
could this be accomplished then? any articles or tips ? thanks.

"Kevin Spencer" wrote:
You don't really want to do this. Inheritance is a way of defining classes.
A class definition is not the same thing as a class instance. A Control in
an application is not a class, but an instance of a class. So, let's say you
have an empty Panel. You want to populate it with some Controls. If you
create an instance of some Control that inherits that Panel class, you are
creating a new Control, rather than populating the Panel that existed in the
first place. As to what you *should* do, I can't say, because you haven't
identified your requirements clearly.

--
HTH,

Kevin Spencer
Microsoft MVP

Help test our new betas,
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"roger_27" <ro*****@discus sions.microsoft .comwrote in message
news:9D******** *************** ***********@mic rosoft.com...
hey, how do I take form code and put it into separate classes? more
specifically,
I want to create like a panel class, and put buttons in it and give these
buttons click events. and all my form has to show is the empty panel. then
tell the panel to inherit from the panel class so it has all those buttons
and click events... that way I can make like 10 panel classes, and when I
want to display a panel, I just tell it to inherit from one of the
classes.

I know that the base class is going to have to inherit from the
UserControl
class, but how exactly do I do it? any help? thanks.


Mar 1 '07 #4
roger_27 wrote:
hey, how do I take form code and put it into separate classes? more
specifically,
I want to create like a panel class, and put buttons in it and give
these buttons click events. and all my form has to show is the empty
panel. then tell the panel to inherit from the panel class so it has
all those buttons and click events... that way I can make like 10
panel classes, and when I want to display a panel, I just tell it to
inherit from one of the classes.

I know that the base class is going to have to inherit from the
UserControl class, but how exactly do I do it? any help? thanks.

create a standard windows form ...
public partial class Meety : Form

override the events you require for example
private void Meety_MouseDoub leClick(object sender, MouseEventArgs e)
{}
private void MeetyForm_Mouse Move(object sender, MouseEventArgs e)
{}

save the project and then create a new "inherited form"

public partial class Login : MeetyForm (assuming both forms are in the same
namespace).

anything that is on the super form will appear on the child .... buttons
events methods ......

Have fun

--
Regards JJ (UWA)
--
Regards JJ (UWA)

Mar 2 '07 #5
awesome!! I did it, but I used inherited controls. instead of using an
inherited form. I used panels.

so now I have one form, and I just use

this.Controls.A dd(pnlUsers);
pnlUsers.Bringt oFront();

to show a panel, and

this.Controls.R emove(pnlUsers) ;

to hide the panel and show a different one.

thanks!

"j1mb0jay" wrote:
roger_27 wrote:
hey, how do I take form code and put it into separate classes? more
specifically,
I want to create like a panel class, and put buttons in it and give
these buttons click events. and all my form has to show is the empty
panel. then tell the panel to inherit from the panel class so it has
all those buttons and click events... that way I can make like 10
panel classes, and when I want to display a panel, I just tell it to
inherit from one of the classes.

I know that the base class is going to have to inherit from the
UserControl class, but how exactly do I do it? any help? thanks.


create a standard windows form ...
public partial class Meety : Form

override the events you require for example
private void Meety_MouseDoub leClick(object sender, MouseEventArgs e)
{}
private void MeetyForm_Mouse Move(object sender, MouseEventArgs e)
{}

save the project and then create a new "inherited form"

public partial class Login : MeetyForm (assuming both forms are in the same
namespace).

anything that is on the super form will appear on the child .... buttons
events methods ......

Have fun

--
Regards JJ (UWA)
--
Regards JJ (UWA)

Mar 2 '07 #6

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

Similar topics

9
3870
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing users, and listing assignments use similar type commands. Is there a "better" way I can organize my code?
20
23118
by: Steve Jorgensen | last post by:
A while back, I started boning up on Software Engineering best practices and learning about Agile programming. In the process, I've become much more committed to removing duplication in code at a much finer level. As such, it's very frustrating to be working in VBA which lacks inheritance, one of the more powerful tools for eliminating duplication at the level I'm talking about. I've recently come up with a technique to emulate one...
2
1619
by: vb6dev | last post by:
Hi, I have code such as: Form01 f1 = new Form01(); where Form01 is a form in my project. then I have Form02 f2 = new Form02(); etc. I have 50 forms. Can I use Form f = new Form(); and then assign FormXX to f? It must be simple, but I can't find how to assign one of my 50 forms to my
28
4380
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I added a class to project and it's named XmlApi(). In the XmlAPI() class I have simple code as following XmlAPI() { string str = "Some Text";
3
1837
by: Simon | last post by:
Hi all, I'm hoping that some of you clever chaps could offer me some advice on code reuse. You see, whenever I make applications, I typically only find very limited
171
7826
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
4
2643
by: John Goche | last post by:
Hello, I have been going through several header source files which define classes with inline functions. In the case where the inline functions are not defined in place, the inline functions from all classes within the header file are included via a separate file, at the end of the file, with a directive of the form: #include <foo.inl>
2
2355
by: Wilson | last post by:
Hi, a very simple question. I am trying to understand inheritance using c++ and dont cee how i could use three classes to create an accounting program using inheritance. e.g one class containing members for both, and then a class for checking accounts and a class for savings. Finally could you just clarify that this is the correct use of i nheritance because i am thoroughly confused.
7
3134
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like "myList" as in the example below ? #include "Sector.h" using namespace boost;
0
9719
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
9597
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
10620
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
10372
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,...
1
7650
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.