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

Instance name Default of Form

AMP
Hello,
I am trying to find out the name of the default form and if Im doing
this right
Form2 ( is startup form, not form 1 ):

public class Form2 : System.Windows.Forms.Form
{
private Form1 myForm1 = null;
..........................................
public Form2()
{
InitializeComponent();

}
.................................................. .............
public void createform()
{
this.myForm1 = new Form1(this);
this.myForm1.Show();

}
private void button1_Click_1(object sender,
System.EventArgs e)
{
this.createform();
}
static void Main()
{
Application.Run(new Form2());
}

Form1:
public class Form1 : System.Windows.Forms.Form
{
private Form2 myForm2 = null;
.................................................. ...........................
public Form1(Form2 frm2)
{ myForm2=frm2;
InitializeComponent();
}

private void button2_Click(object sender,
System.EventArgs e)
{
myForm2.label1.Text = "diff";
}
So you know what I am doing(and it works):
a button on form2 creates form1 and a button on form1 changes some text
on form2

My questions are
The form I send to form1 I send as "this" and it works.Does it have
another instance name?
I have a reference in both forms to the other form, do I need that.It
doesnt seam to work withou it.And most of all....This this the most
professional method of doing this?
Thanks
Mike

Mar 14 '06 #1
3 1747
>From Form2, AFAIK you can only pass it as "this".

This approach is not a true OOP approach, in reality you would have
relationships setup between the two classes, that allows for loose
coupling.

It will work for what you need it to do, but is it the "correct" way?
Thats a matter of opionon.

At the very least you should have properties setup in each for a
unified way of accessing the references to the other form:

private Form2 _myForm2;
private Form2 MyForm2 {
get { return _myForm2; }
}

Form1(Form2 form2) {
_myForm2 = form2;
}

ALWAYS try to use properties to access references/values. Later down
the line, if you need to add some additional stuff to the _myForm2
reference, you can do so in the get accessor of MyForm2, this is called
encapsulation or "data-hiding". Always at the very least try to perform
some level of encapsulation, eventually it will make your life much
easier

Mar 14 '06 #2
AMP
Thanks dkode,
And the other questions? The default instant name?Do I NEED to
reference both forms in each other within the class def.?
Thanks
Mike

Mar 15 '06 #3
I dont know about a default instance name, I always use "this"

As far as the refernece to each other on both forms, Do you need to
access something on Form2 from Form1, do you need to acces something on
Form1 from Form2?

It depends on how they will relate to each other, if you dont need to
access anything on form1 from form2, then there is no need for a
reference to form1

Mar 15 '06 #4

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

Similar topics

2
by: AJ | last post by:
Currently I have a server that has two instances of SQL Server that are both heavily used. We are moving the databases that are on the default instance of this server to a new server. Since the...
2
by: Bill D | last post by:
In a simple Windows forms application, the main form is called Form1. Within this form's class, I refer to the the running instance of this main class as "this" as in this.Text = "NEW TEXT" I...
2
by: FredC | last post by:
OS Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1...
11
by: Jerome | last post by:
I keep getting this error!? It seems like the code can't find the control? Here's my code: --------------------------- <%@ Page Language="VB" ContentType="text/html" %> <%@ import...
12
by: Eric | last post by:
I have a custom component that can be dragged from the ToolBox onto a Windows Form (which means I can't modify it's constructor to add a name parameter). VS assigns it an instance name, but the...
6
by: wu jianhua | last post by:
hi. If I have a form, like FrmAbout, can I create a form instance only with a string "FrmAbout"? not like : Form frm = new FrmAbout(); I want the code : Form frm = createInstance( "FrmAbout" );...
1
by: David | last post by:
I am learning SQL Server 2005 and I was told to install a second instance of SQL Server 2005 on my machine. How can I install a second instance of SQL Server 2005 on my machine I already...
7
by: Simon Bunker | last post by:
Hi I have code similar to this: class Input(object): def __init__(self, val): self.value = val def __get__(self, obj, objtype): return self.value
3
by: Jon | last post by:
My main form opens up another form, and from this other form, I'd like to access things in the main form. The problem is that although I know the name of the class of the main form (FormMain) I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.