且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建自定义控件并将其添加到Windows窗体C#

更新时间:2023-12-05 23:51:10

1.创建Control.您可以继承ComboBoxUserControlControlFormNativeWindow.
2.也将其添加到您的Form.您可以从工具箱中选择它,也可以在Form的构造函数中添加逻辑.
1. Create the Control. You may inherit ComboBox, UserControl, Control, Form or NativeWindow.
2. Add it too your Form. You may either select it from the toolbox, or add the logic in your Form''s constructor.


如果您不熟悉C#,则应该学习使用控件在考虑编写自己的控件之前就已经存在.
If you''re new to C#, you should learn to use the controls that exist before you consider writing your own control.


假设这是一个扩展的dll,最简单的方法是:

右键单击工具箱",然后单击选择项目".
浏览",找到dll,然后单击确定".
现在,您可以像其他控件一样将其从工具箱中拖放,您的项目引用将自动更新.
Assuming this an extenal dll the easiest way is:

Right click on the ToolBox and ''Choose Items''.
''Browse'', find the dll and click OK.
Now you can drag and drop it from the ToolBox like any other control and your project references will be updated automatically.