Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditions)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditions)

  1. #1
    Join Date
    Jun 2014
    Posts
    4

    Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditions)

    Hello !

    I'm pretty much newbie in creating a succesful GUI in C++.
    Although, i managed to create 4 buttons that should show a certain form.
    Lets say, Form1 is my main form, therefore - Button 1 will open Form2, and Button 2 will open Form3.....
    But the conditions is - If there is a form that is already open, clicking again on the Button that should open it, will Close it, but all the forms (form1,2,3,4,5) can be enabled together.
    Also, a very important note is that whenever i close a form, in any way of closing it (Not the main form) It will "save" the changes i made (Such as ticking checkboxes and so..) and won't reopen it, it will just use "Visible" i guess ?
    I couldn't get it on google, really =/
    Please help me out !

    Notes :
    If i use Form2 ^form2show = gcnew Form2;
    and then Form2->Show();
    I will be able to simply ATTACK the button and open Billions of form2 ^_^
    Although, when i use Form2->ShowDialog();
    It won't let me open the form3,4,5.
    Which isn't so bad, but when i exit from the form2, it won't save my changes (Such as checkboxes..)
    Plaese, HELP ME =/

    I'm stucked so hard on this sht...

  2. #2
    Join Date
    Jul 2002
    Posts
    2,517

    Re: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditio

    Make Form2 ^form2show class member in the main form. When it is null, create and show it. If not null, do something else, for example, hide/show it.

    Then you need to override FormClosing event in Form2. If closing reason is user interaction, hide the form instead of closing it.
    Last edited by Alex F; June 12th, 2014 at 07:04 AM.

  3. #3
    Join Date
    Jun 2014
    Posts
    4

    Re: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditio

    Quote Originally Posted by Alex F View Post
    Make Form2 ^form2show class member in the main form. When it is null, create and show it. If not null, do something else, for example, hide/show it.
    so, my code will be :

    Form2 ^form2show= gcnew form2;
    if(form2show = NULL)
    {
    form2show->Show();
    }
    else
    {
    form2show->Hide();
    }

    In the first button.
    But it says it cannot convert int to Duffyduck::Form2 ^ with the operator '='...
    Also, i assume (without building the project) that whenever i'll press the ('X') button in the form2, it will exit and won't recover it well..

  4. #4
    Join Date
    Jun 2014
    Posts
    4

    Re: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditio

    Quote Originally Posted by Alex F View Post
    Then you need to override FormClosing event in Form2. If closing reason is user interaction, hide the form instead of closing it.
    To be honest, i already tried the FormClosing event...
    Never got it to work,
    If you have time to make a source with a button that does the conditions, it will really be greatful !
    And really thanks for helping me !

  5. #5
    Join Date
    Jul 2002
    Posts
    2,517

    Re: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditio

    Please read my post again: Make Form2 ^form2show class member in the main form

  6. #6
    Join Date
    Jun 2014
    Posts
    4

    Re: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditio

    Quote Originally Posted by Alex F View Post
    Please read my post again: Make Form2 ^form2show class member in the main form
    Alright, now i understood it better,
    Although, still can't understand a certain thing - How can i check if its null? or if the closing reason is actually a user interaction ? (To be honest, it doesnt matter for me, just need to hide it)..

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,591

    Re: Really need help with Opening Form2,3,4,5 with buttons from Form 1 (With conditio

    Quote Originally Posted by Duffyduck View Post
    How can i check if its null?
    The correct expresion to check for that condition is form2show == nullptr instead of form2show = NULL. The NULL macro is intended for use with native pointers, as opposed to the managed tracking handles used in .NET, and the single = operator is an assignment (i.e. it modifies the object at its left-hand side) rather than the equality test you want.

    or if the closing reason is actually a user interaction ?
    The event args parameter passed to your FormClosing event handler has a CloseReason property that indicates just what its name suggests: the reason why the form is about to be closed. One of its possible values is CloseReason::UserClosing. You then may set the event args object's Cancel property to true to prevent the form from actually being closed, if your checks indicate that it's appropriate.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center