Results 1 to 12 of 12

Thread: [RESOLVED] [2.0] Easy question for someone who knows what they are doing...

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Resolved [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.
    Last edited by ThisIsMyUserName; Jun 5th, 2006 at 12:38 AM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    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.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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#.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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.
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    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.

  8. #8
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] Easy question for someone who knows what they are doing...

    this zip file contains a working sample
    Attached Files Attached Files
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    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.

  10. #10
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    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.
    Last edited by ThisIsMyUserName; Jun 6th, 2006 at 03:59 AM.

  12. #12
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [RESOLVED] [2.0] Easy question for someone who knows what they are doing...

    Which reference is the null one?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width