[RESOLVED] [2.0] Easy question for someone who knows what they are doing...
I have a main form.
I have a second form.
I have a third form.
The second form is an options form. It has various textboxes and sliders that control the properties of the third form (the location, opacity, etc.).
When the third form moves (I already have an event to handle this), I want the text boxes in the second form to update with the new location.
In addition to that, if I change the text boxes in the second form, I'd like the third form to update its position.
In the end, the problem is figuring out how to communicate between forms.
For the initial startup and show/hide routines in the main form, I simply delcared the second and third forms like so:
frmOptions formOptions = new frmOptions()
Then I did: formOptions.Show() or formOptions.Hide() , etc..
This is working ok, but I can't seem to access controls of a form I'm not currently working in, in addition to edit the properties of the form.
Re: [2.0] Easy question for someone who knows what they are doing...
Change windows desinger generated code (controls) from private to internal
p.s. Change only the controls you want to modify
Re: [2.0] Easy question for someone who knows what they are doing...
That allows me to access the controls (yay), but the changes are not taking effect?
Here's what I did exactly:
Inside the Ruler designer ->
Code:
internal System.Windows.Forms.TextBox txtRulerOverlayX;
internal System.Windows.Forms.TextBox txtRulerOverlayY;
Inside the Ruler form code, under the class declaration ->
Code:
frmOptions formOptions = new frmOptions();
Inside the Ruler form code, under the move event ->
Code:
formOptions.txtRulerOverlayX.Text = this.Location.X.ToString();
formOptions.txtRulerOverlayY.Text = this.Location.Y.ToString();
Result:
The Ruler form moves (the event is working), however the text box in the Options form does not update with the new location.
Re: [2.0] Easy question for someone who knows what they are doing...
it worked fine with me, so I guess there is something in your code changes it back or restricts modification
Re: [2.0] Easy question for someone who knows what they are doing...
I suggest that you read the Forms in VB.NET tutorial in my signature. The code used is all VB but the principles are all exactly the same in C#. You can use one of the code converters in my signature to convert the VB code to C#.
Re: [2.0] Easy question for someone who knows what they are doing...
Quote:
Originally Posted by jmcilhinney
I suggest that you read the Forms in VB.NET tutorial in my signature. The code used is all VB but the principles are all exactly the same in C#. You can use one of the code converters in my signature to convert the VB code to C#.
You really have everything in your signature.
Re: [2.0] Easy question for someone who knows what they are doing...
ComputerJy,
Can you link your working code then? I even started a new project and did exactly what I mentioned in a previous post.
Simple project. 2 forms and 2 text boxes.
Form1 has the 2x text boxes.
Form2 does nothing except update the 2 textboxes with the form's location on the form_move event.
Result: Nothing happens to the text boxes.
jm,
I'll check it out now.
1 Attachment(s)
Re: [2.0] Easy question for someone who knows what they are doing...
this zip file contains a working sample
Re: [2.0] Easy question for someone who knows what they are doing...
Ok, I see what I did wrong. I wasn't "talking" with the same instance of the form, I think.
Thanks for the sample, this cleared up exactly how to communicate with a different form.
Re: [2.0] Easy question for someone who knows what they are doing...
You are very welcome.
Now please mark the thread resolved if you are done
Re: [RESOLVED] [2.0] Easy question for someone who knows what they are doing...
**EDIT**
Fixed it. But I'll leave the question in place, since it might help someone. It was confusing as heck.
The function that was taking the menu list and filling the combo box was inside of the options form constructor. I guess it was trying to fill the combo box with nothing because the menu itself on the main form didn't exist. I changed it to do my startup routines on form_load rather than in the constructor.
** EDIT**
Hmm, ran into a road block which is making no sense to me.
Here is my code inside of the Options form:
Code:
string mnuItem;
for (int i = 0; i < formMain.cMenu.Items.Count; i++)
{
mnuItem = formMain.cMenu.Items[i].Text;
if (mnuItem.Length != 0) cboMenuItem.Items.Add(mnuItem);
}
The IDE says it's a null reference and explodes (the first line where it gets the count). If I comment all that code out, and replace it with: formMain.Opacity = 0.50;
Then the main form's opacity changes to 50% (as far as I know it's working then).
Any idea why I can't get the context menu's contents?
I did a quick hack for now, by passing the form object directly to the function that's handling this but that doesn't seem right.
I set the cMenu to internal as well as try setting all the menu items to internal, that didn't do it.
Re: [RESOLVED] [2.0] Easy question for someone who knows what they are doing...
Which reference is the null one?