Cannot check menu items checked isn't correctly

Hi guys,

I need your help, as I have a bit of troubleshoot with the source code. When I clicked on the menuitem1 to set the menuitem1 checked to true, and when I click on the button, the messagebox is show up on my screen that says "menuitem1 checked is set to true". so when I clicked on the menuitem2 to set the menuitem1 checked as false and set menuitem2 checked as true, and when I click on the button to get messagebox that says "menuitem2 checked is set to true" but I have got the same first messagebox as I have got when I first clicked on the button. If I click the menuitem2 to get the messagebox that says "menuitem2 checked is set to true", it would not make any difference due to the source code that acting like a loop.



Here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "StdAfx.h"
#include "Form2.h"
#include "Form1.h"

using namespace MyApplication;


System::Void Form2::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
  Form1 ^form1 = gcnew Form1();
  if (form1->menuItem1->Checked == true)
  {
    MessageBox::Show("menuitem1 checked is set to true");
  }
  if (form1->menuItem2->Checked == true)
  {
    MessageBox::Show("menuitem2 checked is set to true");
  }
}


Anyone who would give me advice to get this resolve, I would be much appreciate.

Thanks,
Mark
Last edited on
do anyone know how to do this?
24 hours and no one is reply. Please can someone help????????????
This is not standard C++. Is it Microsoft managed C++? I haven't used that in a while.

You need to post a small program that one can build in order for someone to help you in a reasonably way. You haven't provided enough information for anyone to help.
Why do you create a new form here? -> Form1 ^form1 = gcnew Form1();
Don't you want to check the menu items of your existing form?
Perhaps something like this:

1
2
3
4
5
6
7
8
  if (menuItem1->Checked == true)
  {
    MessageBox::Show("menuitem1 checked is set to true");
  }
  if (menuItem2->Checked == true)
  {
    MessageBox::Show("menuitem2 checked is set to true");
  }
Because that's I want to check the menu items from form2 event I am not using existing form.

If i use this:

1
2
3
4
5
6
7
8
if (form1->menuItem1->Checked == true)
  {
    MessageBox::Show("menuitem1 checked is set to true");
  }
  if (form1->menuItem2->Checked == true)
  {
    MessageBox::Show("menuitem2 checked is set to true");
  }



I will always getting the messagebox that says menuitem1 checked is set to true when the menuitem1 checked doesn't exist.

Any idea?
Topic archived. No new replies allowed.