手动更改类名后无法继承System.Window.Forms.Form类
我在 Visual Studio C# 中编写了一个简单的 Form1(继承自 Form)类。一切都很好。
然后我想将类和命名空间的名称更改为有意义的名称,而不是默认的 'WindowApplicationForm1' 。我还更改了 Form1.cs 类的文件名以匹配新的类名(IRISReaderGUI 和 Com.Harmonysoft)。首先我手动重命名代码,然后编译,编译器给了我很多我无法弄清楚的错误。所以我尝试使用“重构”菜单重命名我的类和命名空间。我的代码仍然没有编译。
我做了一些研究并更改了“IRISReaderGUI.Designer.cs”类名称和命名空间以匹配新名称。 C# 仍然没有给我带来任何快乐。
- 编译器错误消息是: “Com.Harmonysoft.IRISReaderGUI.Dispose(bool)”:没有合适的方法 发现覆盖'
- 在设计器视图上它说:基类'System.object'无法设计。
所以我猜我的IRISReaderGUI没有正确继承System.Windows.Forms.Form类,通过将鼠标放在代码中的Form字上可以确认这一点,Visual Net不会弹出描述该类的文本,按F12也不会弹出让我了解表单定义。
这是代码:
“IRISReaderGUI.Designer.cs”
namespace Com.Harmonysoft
{
partial class IRISReaderGUI
{
.......
}
“IRISReaderGUI.cs”
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.OracleClient;
using Com.StellmanGreene.CSVReader;
using System.Windows.Forms;
using System.IO;
namespace Com.Harmonysoft
{
public partial class IRISReaderGUI : Form
{
......
}
我是 C# 和 Visual Studio 的新手,以前主要使用 Java 编译器和 Vim 编辑器。有人可以帮我编译我的代码吗?
I have written a simple Form1 (inherit from Form) class in Visual Studio C#. All was good.
Then I wanted to change the name of the class and the namespace to something meaningful instead of the default 'WindowApplicationForm1' . I also changed the file name of the Form1.cs class to match the new class name (IRISReaderGUI and Com.Harmonysoft). First I manually rename the code, then compiled, the compiler gave me lot of error that I could not figure out. So I tried to rename my class and namespace using 'refactoring' menu. My code still didn't compile.
I did some research and change the 'IRISReaderGUI.Designer.cs' class name and namespace to match the new names. C# still didn't give me no joy.
- The compiler erros message was :
'Com.Harmonysoft.IRISReaderGUI.Dispose(bool)': no suitable method
found to override' - On the designer view it said : The base class'System.object' can not be designed.
So I guess my IRISReaderGUI did not correctly inherit the System.Windows.Forms.Form class, this was confirmed by putting the mouse over the Form word in the code, Visual Net does not popup the text describing the class, and pressing F12 does not get me to the Form definition.
Here is the code :
"IRISReaderGUI.Designer.cs"
namespace Com.Harmonysoft
{
partial class IRISReaderGUI
{
.......
}
"IRISReaderGUI.cs"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.OracleClient;
using Com.StellmanGreene.CSVReader;
using System.Windows.Forms;
using System.IO;
namespace Com.Harmonysoft
{
public partial class IRISReaderGUI : Form
{
......
}
I am new to C# and Visual Studio, I have previously worked with Java compiler and Vim editor mostly. Could anyone please help me to compile my code ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VS2005 及更高版本中的表单是部分类。您编辑了其中一部分,但没有编辑另一部分。在“解决方案资源管理器”窗口中,展开窗体旁边的节点,然后双击 Designer.cs 文件将其打开。
使用“重构 + 重命名”上下文菜单命令是更好的方法,它也不会忘记编辑其他源文件。当您尝试时它不起作用,因为损坏已经造成,零件不再具有相同的名称。
Forms in VS2005 and up are partial classes. You edited the one part but not the other. In the Solution Explorer window, expand the node next to the form and double-click the Designer.cs file to open it.
Using the Refactor + Rename context menu command is the better approach, it doesn't forget to edit the other source files as well. It didn't work when you tried it because the damage was already done, the parts no longer had the same name.