简体   繁体   中英

How do I get the design view back?

I have seen a few questions about this but not one which is quite the same:

In Dev Studio 2017 I am writing a WinForms project.

At some point when I was coding I lost the ability to see the design view of the form.

See below, Form1 (the top one) only has the option to view the code, whereas Form2 has the ability to view the code or the design view.

Shift F7 has no effect and the Design View option does not appear in the right click menu.

在此处输入图片说明

How do I get the design view back?

By the looks of it you might have renamed the Form1 class at some point or you have tried to copy and rename it to or from AlertDetails ..

Your Form UI code is in a separate file from the main Form class, so you have to make sure that the class names match and is marked partial class Your_Form_Name in both/all files.

So lets assume your structure use to look like this:

在此处输入图片说明

Form1.cs (1) is a .cs file on its own, but it is only one part of the complete Form1 class.

In that file your class is defined like this: public partial class Form1 : Form

Form1.Designer.cs (2) is also a .cs file on its own, but it also forms part of the Form1 class.

The designer file defines the class like this: partial class Form1 .

If you intended to rename Form1 to AlertDetails , you have to make sure that the class name is the same in both .cs files, Form1.Designer.cs and Form1.cs

So it should be

  • public partial class AlertDetails : Form in the Form1.cs file
  • and partial class AlertDetails in the Form1.Designer.cs file

Design View option requires the code for the component to be designed to be either the only type, or first type inside the source code file.

In your case the code file contains a type AlertDetails which is before the Form1 (which can be seen by the class view). Just move it to another code file or after Form1 in the same file and the problem will be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM