Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issue with referencing Winform form

I have bean having a issue referencing a winform form I initialize in main, the code for the referencing is as follows,

Form1 f1 = new Form1();
Application.Run(f1);
f1.changeText("Hello World");

the form itself is defined in another file. f1.changetext is a simple function which takes a string input and sets a text block element to the string, I call the function in the form class as the result of clicking a button and that works fine but when I call it in main I get no result. As a side note I have a console.writeline function in main as well that doesn’t do anything but I don’t know if that’s related. For context I’m using Visual studio and if it wasn’t obvious I don’t have too much experience with coding with classes and frameworks like this. Thanks for any assistance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’m not familiar with Application.Run(f1); also shouldnt you change the text prior to "Running it?"

It Being:

Form1 f1 = new Form1();
f1.changeText("Hello World");
Application.Run(f1);

A way I’m sure will work (the one I use) with showing / initializing another form would be

Form1 f1 = new Form1();
f1.changeText("Hello World");
f1.ShowDialog();

Have you tried Debug to check if the code works / was read when running?

Welcome to StackOverFlow!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading