如何在窗体上使用从 .NET 类派生的类,例如 TableLayoutPanel

发布于 2024-08-20 03:26:42 字数 562 浏览 5 评论 0原文

这是一个非常基本的问题,我相信你们中的许多人都能够回答它,并且不仅适用于 TableLayoutPanel,而且也适用于所有其他 .NET 控件。

我创建了一个派生自 TableLayoutPanel 的新类,并且我想在表单上使用此派生类而不是 .NET 版本。我希望能够像使用工具箱中的所有其他控件一样使用拖放功能。

但是,我不知道该怎么做;我还猜测,对于派生类,这种拖放到表单上的操作无法在设计器中完成;并且必须仅在代码中完成。我对此不确定,因为这是我的第一个 .NET 表单应用程序,所以我没有经验可以依靠。

public class CustomTableLayoutPanel : TableLayoutPanel
{
}

承载此控件的窗体(不是直接)是在名为 MainForm 的窗体中实现的。我想我可以进入 deigner.cs (MainForm.Designer.cs) 文件并将成员变量更改为我的自定义类型而不是 .NET 类型,但我不确定这是否是执行此操作的既定方法某种功能或者这是否是一个黑客。据我所知,您不应该手动更改 XXXdesigner.cs 文件中的代码,因为这是自动生成的。

This is quite a basic question, that I'm sure many of you will be able to answer and applies not only to TableLayoutPanel, but to all other .NET controls too.

I have created a new class which derives from TableLayoutPanel and I want to use this derivation on the form instead of the .NET version. I am expecting to be able to use drag and drop as one does will all the other controls in the tool box.

However, I am not sure how to do this; I am also guessing that for dervived classes, this drag and drop onto a form can not be done in the designer; and must be done in code only. I am not sure about this and since this is my first .NET forms application, I have no experience to fall back on.

public class CustomTableLayoutPanel : TableLayoutPanel
{
}

The form that hosts this control (not directly) is implemented in a form called MainForm. I suppose I could go into the deigner.cs (MainForm.Designer.cs) file and change the member variable to be of my custom type instead of the .NET type, but I am not sure if this is the established method of performing this kind of function or whether that is a hack. As far as I know, you should not manually change code in and XXXdesigner.cs file since this is automatically generated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一念一轮回 2024-08-27 03:26:42

您必须至少成功编译您的类一次,然后它将出现在工具箱中。然后您可以像拖放任何其他控件一样拖放它。

You must successfully compile your class atleast one time, and then it will appear in the toolbox. Then you can just drag and drop it as you would any other control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文