简体   繁体   English

如何在C#中进行自定义表单控件

[英]How to make custom form control in c#

有一天,我意识到自己想在Visual Studio中做某事,如果我可以让表单控件替我做,那分配起来会更容易,除非我不知道该怎么做,我想要表单控件拥有网格,每个正方形都有其自己的color属性,如果有人知道如何制作表单控件,或者甚至更好地知道如何制作类似我刚才描述的内容,我会很高兴的:D

1) Inside your project: Solution Explorer --> Right Click the .csproj --> Add UserControl 1)在项目内部: Solution Explorer --> Right Click the .csproj --> Add UserControl

2) Drag and drop gridBox or any control you want into your custom control. 2)将gridBox或所需的任何控件拖放到自定义控件中。

3) Check the ToolBox , your custom control should be located at the very first selection 3)选中ToolBox ,您的自定义控件应位于第一个选择处

This MSDN article is a basic step by step outline of how you can write a customer control. MSDN文章是如何编写客户控件的基本分步概述。 Unfortunatly MS has not figured out how to do avoid link rot -- so you may need to search creating custom winform controls to find this if you come in the future. 不幸的是,MS还没有弄清楚如何避免链接腐烂-因此,如果将来出现这种情况,您可能需要搜索创建自定义Winform控件来找到它。

You are usually best servered by subclassing an existing control and customizing it. 通常,最好通过子类化现有控件并对其进行自定义来为服务器提供最佳服务。

You might also find some of the freely available winform control projects a gold-mine of useful info if you get serious about this. 如果您对此有所了解,您可能还会发现一些免费的winform控件项目是有用信息的金矿。

However, it sounds likely what you should consider doing is creating a "User Control", this is usually simpler for a composite of few existing controls. 但是,您似乎应该考虑创建一个“用户控件”,这对于少数几个现有控件的组合通常更简单。 This article on the types of controls for winforms may be a useful overview for you. 有关Winforms控件类型的文章可能对您有用。

Beyond that you really should use S/O if you are trying to resolve a specific problem you are having when you are coding. 除此之外,如果您要解决编码时遇到的特定问题,则确实应该使用S / O。 Google is a more appropriate tool for finding tutorials, etc. Google是查找教程等的更合适的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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