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

Forms Inheritance

Hi,

I have some forms that they need to have access to some public variables. to
solve this problem I decided to have a RootForm and all other forms are
drived from this form. I can set my public variables on this RootForm and
use them in the drived forms. sounds good? but there is a problem here. I
don't have access to the public variables in RootForm!!! the RootForm is
like this:

namespace myprog
public class RootForm : System.Windows.Forms.Form
{
public string myvar = "test";
.....
}

now the other form I defined like this:

namespace myprog
public class OtherForm : myprog.RootForm
{
....
MessageBox.Show(this, RootForm.myvar);
....
}

but I don't have access to RootForm.myvar. what's the problem and how can I
use public variable in my program?

thanks
Nov 16 '05 #1
1 1385
Mojtaba,

When you say:

RootForm.myvar

You are looking for a static instance of the string on the RootForm
type. However, you don't want this, you want to access the instance
variable for your instance, which you would do by just using "myvar".

Your definition would look like this:

MessageBox.Show(this, myvar);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have some forms that they need to have access to some public variables.
to solve this problem I decided to have a RootForm and all other forms are
drived from this form. I can set my public variables on this RootForm and
use them in the drived forms. sounds good? but there is a problem here. I
don't have access to the public variables in RootForm!!! the RootForm is
like this:

namespace myprog
public class RootForm : System.Windows.Forms.Form
{
public string myvar = "test";
....
}

now the other form I defined like this:

namespace myprog
public class OtherForm : myprog.RootForm
{
...
MessageBox.Show(this, RootForm.myvar);
...
}

but I don't have access to RootForm.myvar. what's the problem and how can
I use public variable in my program?

thanks

Nov 16 '05 #2

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

Similar topics

1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
2
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can...
2
by: Jeff Levinson [mcsd] | last post by:
I guess I would have to know what you mean by "not being able to edit the forms". Does this mean you get an error in the designer when you try to display an inherited form? Does this mean the...
20
by: Michael Maes | last post by:
Hello, I have a BaseForm with (eg) one Timer in the Components'collection & one Button in the Controls'Collection Also there are three Subs: Load, ScanControls & ScanComponents. The BaseForm is...
12
by: Peter Van Wilrijk | last post by:
Hi, In VB6 I have the following code ... Dim frmLink As Form Set frmLink = Forms.Add(stringformname) frmLink.Show 'wait until all data has been loaded Do Until frmLink.Loaded = 21 DoEvent
0
by: fds | last post by:
Hello! I have a very specific question and that is about how to inherit a control for example the control System.Windows.Forms.TextBox without causing the environment to delete the control when...
0
by: Tony Johansson | last post by:
Hello! I have a very specific question and that is about how to inherit a visual control for example the control System.Windows.Forms.TextBox without causing the environment to delete the...
1
by: tony | last post by:
Hello! Assume I have three window forms called Frm1, Frm2 and Frm3 each of these have a method called foo1 and foo2. Now instead of having this foo1 and foo2 in each of the three window forms...
5
by: jandhondt | last post by:
In VS2005 with VB.NET when a form or usercontrol is inherited: it is terribly annoying that the code view shows as Public Class statement without the inherits statement. You have to go to the...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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
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,...
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.