473,395 Members | 1,581 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,395 software developers and data experts.

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 1768
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*****@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.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*****@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.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*****@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.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_MouseDoubleClick(object sender, MouseEventArgs e)
{}
private void MeetyForm_MouseMove(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.Add(pnlUsers);
pnlUsers.BringtoFront();

to show a panel, and

this.Controls.Remove(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_MouseDoubleClick(object sender, MouseEventArgs e)
{}
private void MeetyForm_MouseMove(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
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...
20
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...
2
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...
28
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...
3
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
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)...
4
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...
2
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...
7
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
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,...

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.