none
Making instances from classes RRS feed

  • Question

  • I'm making a program to control my sprinklers. I want 2 forms and I want the user to jump from Form1 to Form2 and back. I think what I need are instances for both forms. Microsoft thinks everybody is a C# expert. When I read how to do it, the examples are so different than what I need its unusable. Would somebody please show me some code that I can use to make instances of my 2 forms.

    I will learn a lot from it. Thanks, Larry

    Friday, April 6, 2018 10:27 PM

All replies

  • https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    It's the same principles no matter if it's C# or Java, because OO is OO.

    When you make a C# Windows form project, then Visual Studio through you can set what form is the startup form that is instanced once the program starts. But without you telling VS, that is the form that automatically created when the Windows form project is created.

    So yes, you can add other forms to the project and those forms will have to be instanced by whatever form that is already instanced that wants to call another forum

    Form1 has been already instanced at program startup and code within form1 wants to call form2.

    Form2 frm2= new Form2().

     frm2.Show(); //the other form form2 has the control and is showing. You close out of form2, then form1 code has the control at the point where form2 was called with form1 showing again.

     

    Saturday, April 7, 2018 12:15 AM
  • I'll give this a try tomorrow.

    Thanks, Larry

    Saturday, April 7, 2018 6:38 AM
  • What does "jump from Form1 to Form2" mean? The answer to the question depends on understanding what you mean.

    If both forms need to be shown continuously during the application then showing the other form from the main (first) form is not likely to be the best solution. There is a way (that most Windows Forms programmers are not familiar with) to have more than one top-level (desktop) forms for an application.

    For the future, this is not a C# language question The answer is not in the C# language documentation. I assume (although you don't say explicitly that) you are using Windows Forms so this question should be in the forum for Windows Forms.



    Sam Hobbs
    SimpleSamples.Info

    Saturday, April 7, 2018 3:55 PM
  • https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    It's the same principles no matter if it's C# or Java, because OO is OO.

    I don't see where the question is asking about creating classes; the question is about creating forms.


    Sam Hobbs
    SimpleSamples.Info

    Saturday, April 7, 2018 3:59 PM
  • https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    It's the same principles no matter if it's C# or Java, because OO is OO.

    I don't see where the question is asking about creating classes; the question is about creating forms.


    Sam Hobbs
    SimpleSamples.Info


    I don't even know what you are talking about. Can't you see that the OP doesn't understand the basics? Can't you read between the lines as old as you are?
    Sunday, April 8, 2018 1:09 AM
  • What does "jump from Form1 to Form2" mean? The answer to the question depends on understanding what you mean.

    If both forms need to be shown continuously during the application then showing the other form from the main (first) form is not likely to be the best solution. There is a way (that most Windows Forms programmers are not familiar with) to have more than one top-level (desktop) forms for an application.

    For the future, this is not a C# language question The answer is not in the C# language documentation. I assume (although you don't say explicitly that) you are using Windows Forms so this question should be in the forum for Windows Forms.



    Sam Hobbs
    SimpleSamples.Info


    This is too complicated for the OP. Can't you read between the lines, as old as you are?
    Sunday, April 8, 2018 1:10 AM