[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WHY INHERIT SYSTEM.WINDOWS.FORMS.FORM?

Posted on 2006-05-26
10
Medium Priority
?
298 Views
Last Modified: 2010-04-23
my question is why to inherit system.windows.forms.form?
i've been doing it for all forms in all my projects, but i still dont understand why i should be doing it. seems that without it the form still works, so whats the advantage then?
thanks
0
Comment
Question by:newyuppie
  • 4
  • 3
  • 3
10 Comments
 
LVL 9

Expert Comment

by:tolgaong
ID: 16771213
Suppose that you have a project with 100 screens (screen = form)
At the end of the development, you decided to put your logo to each forms right bottom.
If you haven't used inheritance, you should edit all the forms (100 forms), otherwise it will be enough to only change the derived form.
This is  just a single case.
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16771271
i understand. so suppose i wanted to add my logo then, how would i do that supposing that on every form in my application i have used inherit system.windows.forms.form.
e.g. where do i find this top level system.windows.forms.form where all the other ones are inheriting from and how do i edit it?
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16771453
Hi newyuppie;

To your question, "my question is why to inherit system.windows.forms.form?"

If a class inherits from System.Windows.Forms.Form then that derived class will now have access to the UI which places the visable form on the screen and all the objects that come with it such as Windows title bar, min and max buttons and the X button to close the window. It also gives you the ability to drag and drop other controls to the form for your use as well as the properties and functions defined in the System.Windows.Forms.Form object.

To the other question, "i've been doing it for all forms in all my projects, but i still dont understand why i should be doing it. seems that without it the form still works, so whats the advantage then?"

Unless a class inherits from System.Windows.Forms.Form or a class derived from System.Windows.Forms.Form it can not function as a windows form.

To your statement, "seems that without it the form still works"

Can you post some code where a class has NOT inherited from System.Windows.Forms.Form and functions as a form.

Thanks;

Fernando
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16771558
Hi newyuppie;

In the situation that tolgaong gave you above you would need to create a new class which inherits from System.Windows.Forms.Form. Then add the company logo to this class and save it, Lets call it FormCompany.

Then in the 100 classes that you create those 100 classes should inherit from FormCompany. Now when you make changes to FormCompany it will be propagated down to the 100 classes.


Fernando
0
 
LVL 9

Assisted Solution

by:tolgaong
tolgaong earned 1000 total points
ID: 16771574
After reading FernandoSoto's post, I see that I got your question worng.

Let me clear myself.

The standart code contains the following code

public class Form1
   implements System.Windows.Forms.Form
... (Lots of code here)
End Class

Without the implements line, your code cannot be functional.

If you use "your inherited form" -Explained below-, you can use the benefits in my previous post.

Crate a new project.
Add a class.
write:

public Class MyForm
     implements system.windows.forms.form

    Private tempStr As String
    Public Property Tempa() As String
        Get
            Return tempStr
        End Get
        Set(ByVal value As String)
            tempStr = value
        End Set
    End Property

end class


Now, change your code

From:
public class Form1
   implements System.Windows.Forms.Form
... (Lots of code here)

To:
public class Form1
   implements MyForm
... (Lots of code here)
End Class
End Class
0
 
LVL 9

Expert Comment

by:tolgaong
ID: 16771581
Try the code on a seperate solution. Or take a backup ;)
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16771676
Fernando,
thanks for your explanation, i tried to make an example that didnt inherit and worked, but then i realized that the forms.designer partial class (where the buttons are drawn and usually hidden from the user) does inherit. i tried removing that line and nothing worked...
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 16771788
Hi newyuppie;

It sounds like you are using VS .Net 2005. In the code for the form you do not have to insert Inherits System.Windows.Forms.Form because that is alread set for you in the partial class code file which gets combined at compile time with the user code for the form. So in that case you do not need to insert the inherts statement because it has been done for you already in the designer code.

Fernando
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16771835
thanks to both of you for your very good answers. i will raise the question points to 500 so i can split 250 for each of you.
Fernando made me realise that without the inheritance forms won't work and also made me look further into my code and discover that the partial designer classes were indeed inheriting.

on the other hand, tolgaong assisted on this answer and gave me a very good piece of information and suggestion, which i will look into using on my next projects, i think it could be very useful.

thanks again,
P
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16771917
Glad I was able to help. :=)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question