vb 控件编程
Building complete custom components can be a very advanced project. But you can build a VB.NET class that has many of the advantages of a toolbox component with much less effort. Here's how!
构建完整的自定义组件可能是一个非常高级的项目。 但是您可以轻松地构建具有工具箱组件许多优点的VB.NET类。 这是如何做!
To get a flavor of what you need to do to create a complete custom component, try this experiment:
要了解创建完整的自定义组件所需执行的操作,请尝试以下实验:
-> Open a new Windows Application project in VB.NET.-> Add a CheckBox from the Toolbox to the form.-> Click the "Show All Files" button at the top of Solution Explorer.
->在VB.NET中打开一个新的Windows应用程序项目。 ->在“工具箱”中将复选框添加到表单。 ->单击解决方案资源管理器顶部的“显示所有文件”按钮。
This will display the files that Visual Studio creates for your project (so you don't have to). As a historical footnote, The VB6 compiler did a lot of the same things, but you never could access the code because it was buried in compiled "p-code". You could develop custom controls in VB6 too, but it was a lot more difficult and required a special utility that Microsoft supplied just for that purpose.
这将显示Visual Studio为您的项目创建的文件(因此您不必这样做)。 作为一个历史脚注,VB6编译器做了很多相同的事情,但是您永远无法访问该代码,因为它被埋在已编译的“ p代码”中。 您也可以在VB6中开发自定义控件,但这要困难得多,并且需要Microsoft为此目的提供的特殊实用程序。
In the Form Designer.vb file, you will find that the code below has been added automatically in the right locations to support the CheckBox component. (If you have a different version of Visual Studio, your code might be slightly different.) This is the code that Visual Studio writes for you.
在Form Designer.vb文件中,您会发现以下代码已自动添加到正确的位置以支持CheckBox组件。 (如果您使用其他版本的Visual Studio,则您的代码可能会略有不同。)这是Visual Studio为您编写的代码。
'Required by the Windows Form Designer Private components _ As System.ComponentModel.IContainer'NOTE: The following procedure is required'by the Windows Form Designer'It can be modified using the Windows Form Designer.'Do not modify it using the code editor.<System.Diagnostics.DebuggerStepThrough()> _Private Sub InitializeComponent() Me.CheckBox1 = New System.Windows.Forms.CheckBox() Me.SuspendLayout() ' 'CheckBox1 ' Me.CheckBox1.AutoSize = True Me.CheckBox1.Location = New System.Drawing.Point(29, 28) Me.CheckBox1.Name = "CheckBox1". . . and so forth ...
This is the code that you have to add to your program to create a custom control. Keep in mind that all the methods and properties of the actual CheckBox control are in a class supplied by the .NET Framework: System.Windows.Forms.CheckBox. This isn't part of your project because it's installed in Windows for all .NET programs. But there's a lot of it.
这是您必须添加到程序中以创建自定义控件的代码。 请记住,实际CheckBox控件的所有方法和属性都在.NET Framework提供的类中: System.Windows.Forms.CheckBox 。 这不是您项目的一部分,因为它已为所有.NET程序安装在Windows中。 但是有很多 。
Another point to be aware of i