DialogBox in C++/CLI
-
Hi, I can't find any decent example on how to create a DialogBox using C++/CLI and on how to deal with the different responses triggered by the diffent buttons being pressed. I've created graphically the DialogBox (form2) which has 2 buttons "A" and "B" but I can't understand how I can pass different values to the main form (form1) when each button is selected. Is it possible to do it without creating a new class. How? Any example code would be highly appreciated.
-
Hi, I can't find any decent example on how to create a DialogBox using C++/CLI and on how to deal with the different responses triggered by the diffent buttons being pressed. I've created graphically the DialogBox (form2) which has 2 buttons "A" and "B" but I can't understand how I can pass different values to the main form (form1) when each button is selected. Is it possible to do it without creating a new class. How? Any example code would be highly appreciated.
J_E_D_I wrote:
I can't understand how I can pass different values to the main form (form1) when each button is selected.
You can add public properties and/or methods to the form1 class that can be used like any other class properties/methods. You could also use events if a publisher/subscriber scenario is more appropriate. This is basic C++ and not particular to the UI...
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi, I can't find any decent example on how to create a DialogBox using C++/CLI and on how to deal with the different responses triggered by the diffent buttons being pressed. I've created graphically the DialogBox (form2) which has 2 buttons "A" and "B" but I can't understand how I can pass different values to the main form (form1) when each button is selected. Is it possible to do it without creating a new class. How? Any example code would be highly appreciated.
J_E_D_I wrote:
but I can't understand how I can pass different values to the main form (form1) when each button is selected.
As Mark points out, these forms are classes so the same thing applies to them as any class. That said from a Design, Principles and Best Practices perspective, it is not advisable to have cohesion between UI views. See the Design Pattern Model View Controller[^].
-
Hi, I can't find any decent example on how to create a DialogBox using C++/CLI and on how to deal with the different responses triggered by the diffent buttons being pressed. I've created graphically the DialogBox (form2) which has 2 buttons "A" and "B" but I can't understand how I can pass different values to the main form (form1) when each button is selected. Is it possible to do it without creating a new class. How? Any example code would be highly appreciated.
Set some Button.DialogResult value for those buttons that should close the dialog and return something. :)