I have created a simple gui using a windows form, which consists of some checkboxes, radiobuttons and textboxes. I also have my logic code which consists of several switch case statement and I want to know how to put my logic code into the gui I have created.

Does anyone know of any tutorials that show how to do this with visual studio 2010? or could someone give me and example for one of the case statement, that I can follow with the rest?

Paste in one of your case statements and a screenshot of your control (if available), and someone should be able to run you through it. You might be able to shortcut some of your logic based on the characteristics of the controls.

Once you drag + drop a "control" on your "form" you can select the control and in the properties pane at the top there is an "events" button you will want to click.

Those events are most likely relevant to using your logic with your GUI. Find one, such as the "MouseClick" event, double click the white part of the drop-down to have the editor generate one for you.

Paste in one of your case statements and a screenshot of your control (if available), and someone should be able to run you through it. You might be able to shortcut some of your logic based on the characteristics of the controls.

Ok here is a screenshot of the gui I have created and a couple of examples of my case statements.

[IMG]http://i762.photobucket.com/albums/xx263/syler_/gui_test.jpg[/IMG]

case 4:
    myvec.at(1).at(3) = "some string"; //checkbox control
    break;
case 16:
    getline(cin, user_input, '\n'); //textbox control
    break;

There's going to be some difficulty right off the bat when you are mixing the unmanaged C++ (the std::vector ) and the managed form (which uses an offbeat dialect of C++ called C++/CLI, so some of the data structures and syntax are different).

The GUI uses something called event-driven programming (which isn't unique to Winforms, most GUIs use it in some way), but essentially, you're not moving through your code linearly, you are doing something in response to someone clicking a checkbox, typing in a textbox, or clicking a button. So, rather than getline, you could, for example, have the user type something in the textbox, and once they select a radiobutton, your code will read the text into variable xyz.

Instead of using a vector (which is theoretically possible, but requires some juggling in most cases), you should use a cli::array (see http://www.functionx.com/cppcli/index.htm) for some decent tutorials) or a .NET List object.

So, that's probably a lot to digest... A lot of the good tutorials for .NET are written for C#, but you can still reference them, as the classes and member methods are all the same, except for the -> and :: notation used in C++ with pointers and namespaces.

Post back as you run into any issues.

commented: Nice explanation, but I still hate the word GUI! :) +14

Thanks for the explanation, I've got some reading to do.

I have now change my code over to c++\cli, I have tried bits of it out in the gui and it works to some extent. I would like to know if I can have the user select\fill in, the checkboxes, radio buttons and textboxes, but only have the logic for them controls carried out and in a specific order, when you user clicks an apply button, any clues?

Yes. All of the controls have an .Enabled property that will allow them to be active or inactive (grayed out). You can also use the .Visible property to take them out of the form temporarily.

Having the logic carried out in a particular order could be done simply by checking to see if there is anything in the TextBox.Text property before allowing the user to change the radiobutton, or as sophisticated as setting a boolean variable during one of the Textbox events, and ultimately checking if it's true in the CheckChanged event of the radio button.

Start playing around with some of the simpler aspects of the UI (how do I gray out or hide one button by pushing another), or if you're beyond that point, take a crack at some of what you describe and post back with specific problems.

Thanks, I think I can do what I want now, I will mark this solved and start a new thread if I have any specific problems, thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.