Showing multiple forms

2019-07-07 02:48发布

In my code I have a main form (named frmMain) and an About Box(named AboutBox1). What I want to happen is when the user clicks on the Help menu in my menu strip and then clicks on About I want the AboutBox1 form to show. I've researched on how to do it but the intellisense is not recognizing the second form when I try and type and I have no idea why. Any ideas?

The code that I'd assume that I put in my menu button click even is:

AboutBox1 aboutbox = new aboutbox();
aboutbox.ShowDialog();

however AboutBox1 gives an error that the type or namespace could not be found.

Here is the code I currently have. Along with this is also a newly created form that has nothing but the initial code in it:

https://gist.github.com/anonymous/5366535

3条回答
唯我独甜
2楼-- · 2019-07-07 03:01

This line:

AboutBox1 aboutbox = new aboutbox();

Is not a proper initialization of object in C# language. You should try to initialize the object in the following way:

AboutBox1 aboutbox = new AboutBox1();

Read more at MSDN:

查看更多
\"骚年 ilove
3楼-- · 2019-07-07 03:15

Try this :

AboutBox1 aboutbox = new AboutBox1();
aboutbox.ShowDialog();

ShowDialog() creates a modal window, if you need to create a modeless window you can use Show() method.


in C#

the typical way to initialize a object is

Classname variable_name = new Classname(); // assuming that constructor does not take any parameter

Go though this article once : Objects (C# Programming Guide) it will help you to understand a few basic things.

查看更多
三岁会撩人
4楼-- · 2019-07-07 03:15

If your class is named AboutBox1 you need to use

AboutBox1 aboutbox = new AboutBox1(); 

to instantiate the aboutbox object of the type AboutBox1

查看更多
登录 后发表回答