Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How VB.NET uses the Component class

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how VB.NET uses the Component class, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

A component is actually a piece of reusable code that implements a component by following the standard of the IComponent interface, so some components are derived from the Component class, and the VB.NET Component class implements the IComponent interface. The access level of the function should be used correctly in the component to control external access restrictions.

As long as you have sufficient permissions, you can put the component into your own program without worrying about how big an error the component will cause, because the component has already been tested. For example, you can make a login program into a component, or make some frequently used functions into components, which can reduce errors in development and shorten development time. Components can also be applied to each other, such as one component referencing another, is fine, but the first step is to add a reference to the component in Add Reference, which is achieved by putting the component in the assembly, which stores the file information and path on which these components depend, so CLR can use this information to determine the location of other assemblies needed by the component.

Create a component in VS: select a Project, and then select Class Library,OK from the template. Then Add Component from the Project menu, and so far, a framework for the component is presented, and the platform automatically inherits the VB.NET Component class and constructor. You can delete the Class1 that was automatically generated when you created the class library, depending on the needs of the application. Then you can write the function to be implemented in the component class, and select Build Solution (build solution) from the Build menu to generate the component. If the build is successful, you will see a DLL file in the application's BIN directory.

Reference component: just add a Reference to DLL in the Solution Explorer window.

Imports loginValidator

Imports System.Data

Imports System.Data.SqlClient

Public Class loginFormClass loginForm

Inherits System.Windows.Forms.Form

# Region Code generated by the Windows forms designer

Public Sub New () Sub New ()

MyBase.New ()

'This call is required by the Windows forms designer.

InitializeComponent ()

'add any initialization after the InitializeComponent () call

End Sub

'The form rewrites the dispose to clean up the list of components.

Protected Overloads Overrides Sub Dispose () Sub Dispose (ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

Components.Dispose ()

End If

End If

MyBase.Dispose (disposing)

End Sub

'required for the Windows forms designer

Private components As System.ComponentModel.IContainer

'Note: the following procedures are required for the Windows forms designer

'you can modify this process using the Windows forms designer.

'don 't use the code editor to modify it.

Friend WithEvents lblUserPwd As System.Windows.Forms.Label

Friend WithEvents lblUserName As System.Windows.Forms.Label

Friend WithEvents txtUserName As System.Windows.Forms.TextBox

Friend WithEvents txtUserPwd As System.Windows.Forms.TextBox

Friend WithEvents btnSubmit As System.Windows.Forms.Button

Friend WithEvents btnExit As System.Windows.Forms.Button

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents btnCancel As System.Windows.Forms.Button

Friend WithEvents Label3 As System.Windows.Forms.Label

Private Sub

InitializeComponent () Sub InitializeComponent ()

Dim resources As System.Resources.ResourceManager =

New System.Resources.ResourceManager (GetType (loginForm))

Me.lblUserPwd = New System.Windows.Forms.Label

Me.lblUserName = New System.Windows.Forms.Label

Me.txtUserName = New System.Windows.Forms.TextBox

Me.txtUserPwd = New System.Windows.Forms.TextBox

Me.btnSubmit = New System.Windows.Forms.Button

Me.btnExit = New System.Windows.Forms.Button

Me.Label1 = New System.Windows.Forms.Label

Me.Label2 = New System.Windows.Forms.Label

Me.btnCancel = New System.Windows.Forms.Button

Me.Label3 = New System.Windows.Forms.Label

Me.SuspendLayout ()

About VB.NET Component classes: .net is backward compatible and supports earlier versions of applications such as COM and ActiveX objects. It's interesting to use COM and so on in .NET. Net creates a package to wrap them, and the interaction between them is done through this wrapper, which is called runtime callable wrapper (RCW). You can use COM directly, or you can convert it to a .NET assembly and then use it.

1. The direct use of COM components is achieved through Add Reference, and this method is packaged by RCW. Disadvantages: can not be put into GAC, can not be reused.

2. It is used by converting to. Net assemblies by using tlbimp command-line tools.

* the name of the COM, the second is the name of the .NET component to be generated, the third is the namespace to be generated, the fourth is the version number, and the fourth specifies the file name of the reference.

These are all the contents of the article "how VB.NET uses Component classes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report