C # errors in opening the Form Designer and Solutions

Source: Internet
Author: User

The error message is as follows:
 Form1 can be designed, but it is not the first class in the file. Visual Studio requires the designer to use the first class in the file. Move the class code to make it the first class in the file, and then try to reload the designer.

That is, when you click "view designer", only error messages are reported for the Form and control.

Piu can see that the error shown in 1 has not been repeated twice. The previous error prompted that the problem could not be solved, so he had to give up.
But this time it was intolerable. How could it be that VS's form editor is so fragile ?! Or is there a disk error in the file I saved?

I recall that the last "good" was that the class public class AppDatas was not added, so I removed it and solved the problem. "Check that the designer is working properly !"

The error message is not clear!

But I don't know why vs does not automatically help us move the class above the Form1 class.

The Code is as follows:

Using System. Windows. Forms;
Using System. Collections;

Namespace WindowsFormsApplication4
{

Public class AppDatas
{
// Static data member
* ****** Static ArrayList listData;
// Static Constructor
Static AppDatas ()
{
ListData = new ArrayList ();
ListData. Add ("DotNet ");
ListData. Add ("C #");
ListData. Add ("Asp.net ");
ListData. Add ("WebService ");
ListData. Add ("XML ");
}
// Static attributes
Public static ArrayList ListData
{
Get {return listData ;}
}
// Static method
Public static ArrayList GetListData ()
{
Return listData;
}
}

Public partial class Form1: Form
{

Public Form1 ()
{
InitializeComponent ();
This. listbox1.datasource = appdatas. listdata;
}

P rivate void button#click (Object sender, eventargs E)
{
Form2 formchild = new form2 ();
Formchild. showdialog ();
This. listbox1.datasource = NULL;
This. listbox1.datasource = appdatas. listdata;

}

}
}

Note that the class public class AppDatas is located on the top of the Form1 class and moves it below. The error is solved.
Well, maybe someone else is confused. I hope I can see this article to solve the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.