Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Is form2.show not a thing anymore?

Working on a project, and trying to open my second form when a button is clicked. Only problem is that I can't seem to open said form because apparently form2.show isn't a thing anymore? Am I high or am I retarded? Help pls :)
Be a little more specific, what does the error say, what exactly happened... Something more than "form2.show isn't a thing anymore"
It was never a thing in C#... Learn how to instantiate classes and call methods properly. Only VB.NET has default instances.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Sep 6, 2018 07:35 PM)0xDEAD10CC Wrote:  It was never a thing in C#... Learn how to instantiate classes and call methods properly. Only VB.NET has default instances.

Maybe try this :

Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Hide() /// Close your initial form
    Form2.Show() /// Open the form2
Code
Form2 newForm = new Form2();
newForm.Show();
fuck.
[Image: wyEbCMi.png]
Not trying to be a dick, It just comes naturally.
(Sep 7, 2018 06:35 AM)Le-coyote Wrote:  Maybe try this :

Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Me.Hide() /// Close your initial form
   Form2.Show() /// Open the form2

This is VB -.-, OP clearly wants it on C#

This is what you need to do

Code
Form2 _form2 = new Form2();
_form2.Show();

However this will initialize every single time a new form, if you don't want you can dispose it
Жизнь это не те дни, что прошли, а те, что запомнились
Disposable:
Code
using (Form2 form = new Form2())
    {
        form.Show();
    }

I guess you could also do initialize a new form2 and set as property then call it like:

Code
Form2 form; //property

private void Form1_Load(object sender, System.EventArgs e)
{
   form = new Form2(); //initialize new instance
}

//Consume it like below:
form.Show();
(Sep 7, 2018 01:16 PM)Closed User Wrote:  Disposable:
Code
using (Form2 form = new Form2())
    {
        form.Show();
    }

I guess you could also do initialize a new form2 and set as property then call it like:

Code
Form2 form; //property

private void Form1_Load(object sender, System.EventArgs e)
{
   form = new Form2(); //initialize new instance
}

//Consume it like below:
form.Show();

Other events may happen before form Load event so why wouldn't you just use the constructor ? Unless the idea is to lazy initialize it but then you can just use Lazy<T>.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Sep 7, 2018 01:16 PM)Closed User Wrote:  Disposable:
Code
   using (Form2 form = new Form2())
   {
       form.Show();
   }

.Show is non-blocking. The form will flash up briefly then be disposed.

Either use .ShowDialog which will suspend the use of the first form, or remove the using statement.
Lotta blood to let, peace to make, give a fuk about a check


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by EffexionApr 16, 2018 02:48 AM 4 195 Apr 16, 2018 02:48 AM
Last Post: Effexion
[.NET] by adenfrMar 20, 2017 11:03 AM 3 187 Mar 20, 2017 11:03 AM
Last Post: Ninja
[.NET] by Moon RockJul 22, 2016 07:53 AM 2 217 Jul 22, 2016 07:53 AM
Last Post: Moon Rock