View Single Post
  #1 (permalink)  
Old May 31st, 2013, 11:33 PM
John S John S is offline
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default ColorForm Figure 9-4 and associated lesson

I had a LOT of trouble trying to understand the code for this one (top of page 108), even though I've read through two other C# training books (with minimal success)

I am somewhat comfortable with the concept:

Object dog = new Object();

The problem I had is that the lesson in your book uses the terms "ColorForm" , "RemoteForm", "remoteColorForm" in various ways.

The namespace is named "RemoteForm" and the Form1 has a Text = "RemoteForm"

The secondary form has a resource name of ColorForm.cs, and a (Name) = ColorForm, and Text = ColorForm, however in the Form1.cs code it is referred to a "remoteColorForm" ... even though the primary form is titled "RemoteForm" !!!

This was way too much duplication for me to figure out what was doing what!!

If the form has a (Name) = ColorForm, how can the code call it up by using "remoteColorForm" ??

Where is the secondary form associated with the name "remoteColorForm"??

Finally I took your code:

"// The remote form we will manipulate.
ColorForm remoteColorForm;

// Create and display the remote form.
private void Form1_Load(object sender, EventArgs e)
{
remoteColorForm = new ColorForm();
remoteColorForm.Show();
}

// Make the color form red.
private void redButton_Click(object sender, EventArgs e)
{
remoteColorForm.BackColor = Color.Red;
remoteColorForm.ForeColor = Color.Pink;
} "

and replaced the "remoteColorForm" with "dummyForm" (which I made up), like this:

"
// The remote form we will manipulate.
ColorForm dummyForm;

// Create and display the remote form.
private void Form1_Load(object sender, EventArgs e)
{
dummyForm = new ColorForm();
dummyForm.Show();
}

// Make the color form red.
private void redButton_Click(object sender, EventArgs e)
{
dummyForm.BackColor = Color.Red;
dummyForm.ForeColor = Color.Pink;
} "

and the Solution still worked!

But I don't know how.

The ColorForm form has a (Name) = ColorForm, and Text= ColorForm, so how does calling it up as "dummyForm" work??

If:

ColorForm dummyForm = new ColorForm();

should not the (Name) of the secondary form be "dummyForm" ??


In your code, why does " remoteColorForm.Show" display a form that is not named remoteColorForm? Why does this not throw an error??

thanks