i need help with basic things

Im new to visual C, but i know the fundimentals of prgramming, and i cant figure out how to make a form pop up or how to change the start screen to another form, any help

Answer this question

i need help with basic things

  • uTILLIty

    OK - the first thing is, have you created a forms app If not, then there's a bit of work to do to get the right libraries in there, you're better off starting again.

    Now, the Application.Start will occur in your app, you can search for it, and change the form that it uses to start the app, which was one of your questions

    Any form that you create will take the form of a class.  Any form can be created in your app, by creating an instance of it :

    myForm frm = new myForm();

    Once you have an instance of it, you can call the ShowDialog method, which means this form will be the only form in your app to accept input until it is closed.  When it closes, it returns a DialogResult, which is how you tell what button was pressed to close the form, basically.

    In the forms designer, you can add controls, like buttons.  In the properties, if you click on the lightning flash, you can add methods that will be called when a user interacts with the control, and if you double click on the control in the forms designer, a method is created for the default action, i.e. when a button is clicked.  If you do this, then you will be taken to your .cs file, and to the method that will be called.  If you add the code I gave you to this method, then when you click the button in the main form, this other form will be shown as a result.

  • svip

    Ok, im pretty sure everything works properly now, thanks for all your help.
  • miauru

    Im afraid youve lost me, bear in mind i am new.
  • Slesh

    What i meant by the first question, was how to change screens, like when you click a button it takes you to a different form.

    Unless you want the parent form to disappear, this is the way to do it ( the way I've shown you already ).  If you want the parent form to disappear, you could perhaps hide it before calling ShowDialog, although I'm not sure, child forms may become invisible.

    And does - myForm frm = new myForm(); - go in the button click event or somwhere else

    As I said before, it goes where-ever you want the form to be shown from, and in the case of your specific question, that's the button click event handler.




  • dork

    I presume you're using c# Express, if so heres a quick start guide to what you want:

    File-> New -> Project
    Windows Application.

    This will create an application with 1 blank form in it.

    To add a second form, on the right in the Solution explorer, right click on WindowsApplication1 (in bold), select Add -> New Item. Choose a Windows Form.

    You now have a second blank form, go back to the first by double clicking on "Form1" in the Solution explorer. Now from the toolbox on the left drag across a button (click and drag into the form bit you can see). This will create you a button on the form. Now back on the right go to properties, click the event button (top, lightning symbol) and double click in the blank box next to Click in order to create an onclick event handler. This will take you to the Code view, with the caret in the new function. Here you want:

    Form2 newForm = new Form2();
    newForm.Show();

    Now run the application and click the button, a new form opens.

    You'll find that VS does a lot of the hard work (theres a lot of code you dont see in creating a new form, so let VS handle it for you). Have a play about with VS, its got loads of cool timesaving stuff.


  • anydobbo

    Sorry, I thought that was self evident.  They don't *need* to be on a form, but they generally would be, because you'd generally bring up a child form in response to a UI event, such as a button click.  So, this code would more likely than not be in a click event of the parent form.

    Your app gets started in code like this:

    Application.Run( new MainForm() );

    where MainForm can be any form, I would have thought.



  • david hug

    You've asked in the C# forum, but you say you're using Visual C.  do you mean C#

    To create a form, you need to call it's ShowDialog method, or it's Show method if it's to be modeless.  Your entry point is static void main, this method creates the starting form and calls it.


  • zoranj

    It does work (tried it before I posted, just in case :) ).  He didnt actually specify he wanted any result from the new form or anything, so I just did a basic example :)

    for a splash screen (which he sort of references in his first post) he wouldn't need a Dialog (in fact that would be rather pointless wouldnt it :) ).


  • dcohen

    yeah its C#, ive found ShowDialogue in the help file but its doesnt explain anything, can anyone give an example
  • Snakebite

    MyDialog dlg = new MyDialog();

    DIalogResult result = dlg.ShowDialog();

    // Now check the result if necessary

  • DarshanSingh

    Form2 newForm = new Form2();
    newForm.Show();

    Does this work in C# In C++, newForm would drop out of scope, and the modeless dialog would disappear immediately.  Certainly, if it works, it creates a modeless dialog that the parent dialog cannot interact with.


    Did you mean ShowDialog() in your example



  • JohnFlemming

    What i meant by the first question, was how to change screens, like when you click a button it takes you to a different form.

    And does - myForm frm = new myForm(); - go in the button click event or somwhere else


  • HBN

    Wouldnt the functions Mydialog() and ShowDialog need to be somwhere in the form.
  • i need help with basic things