visual| Controls | Distinguish between Visual Basic 6.0 controls and. NET controls
Summary:This article briefly describes the standard controls and equivalent Microsoft. NET controls in Microsoft Visual Basic 6.0.
Goal
- Learn which Visual Basic 6.0 ActiveX controls have an equivalent control in. NET.
- Learn which properties in. NET controls have changed.
- Learn which new controls are in. NET.
Prerequisite conditions
To fully understand the content of this article, the following conditions need to be met:
- Learn what an ActiveX control is.
- You have written Windows applications using Visual Basic 6.0 controls and ActiveX controls.
Directory
- Differences in standard controls
- New controls in. NET
- Changes to Attributes
- Changes to general controls
- Changes to standard controls
- Summarize
differences in standard controls
From an internal construct, there is a significant difference between a Microsoft. NET control and a microsoft®activex® control because the. NET control is created from a hierarchy of other classes. There are several classes inherited by these. NET controls, and as you delve deeper into the actual controls, you'll find that each class is optimized and adds more functionality. The top level of the control's class hierarchy is
ControlClass. But if you create your own controls, these controls are most likely to be from the
UserControlclass inherits from the
UserControlclass contains the properties and events you need, and you can draw all the constituent controls for you.
When you use. NET to create a user interface, you will find that many familiar Microsoft Visual basic®6.0 controls are missing or have been replaced with names. This article provides a brief introduction to the standard controls in Visual Basic 6.0 and the equivalent. NET controls. Later in this article, you'll see how all of these controls differ in their property names. The functionality of these controls is essentially the same as in Visual Basic 6.0, except for the changes in properties and some event names.
Table 1 lists the standard controls in the Visual Basic 6.0 toolbox and the equivalent. NET controls. Although only some of the. NET controls are listed here, you can see from this table what changes have taken place in the. NET control.
Table 1: ActiveX controls renamed in. NETThe. NET control equivalent of the Visual Basic 6.0 standard control
Picture
PictureBox
Label
Label
TextBox
TextBox
Frame
GroupBox
CommandButton
Button
CheckBox
CheckBox
OptionButton
RadioButton
ListBox
ListBox
ComboBox
ComboBox
HScrollBar
HScrollBar
VScrollBar
VScrollBar
Timer
Timer
DriveListBoxNo. By
OpenFileDialogControl instead.
DirListBoxNo. By
OpenFileDialogControl instead.
FileListBoxNo. By
OpenFileDialogControl instead.
ShapeNo. Currently, you can use classes in the. NET Common Language Runtime (CLR) to draw shapes.
LineNo. You can now use the classes in the. NET CLR to draw a line.
ImageNo. You can use
PictureBoxcontrol displays a single image.
DataNo. NET data binding is completely different from the data binding in Visual Basic 6.0.
OLENo.
ImageList
ImageList
new controls in. NET
In addition to the standard controls,. NET also contains a new set of controls. Some of these controls have equivalent controls in Visual Basic 6.0, while others are new controls. Some of the new controls that you can use in. NET are listed below.
Table 2: Standard controls that can be used to create a user interfaceNew control Description
LinkLabelAllows you to place hyperlinks on Windows forms. It functions like a hyperlink in a browser.
MainMenuHelps you create a menu on a form.
DataGridDisplays data in a Ado.net dataset in tabular form. This control is in Visual Basic 6.0
FlexGridControl is very similar, but it has many new features.
CheckedListBoxEnhancement of
ListBox, allowing the user to select one or more items in the list by selecting the check box next to each item. To implement this feature in Visual Basic 6.0, you need to
Styleproperty is set to
1-checked。
TabControlCombined with the Visual Basic 6.0
TabStripAnd
SSTabThe functionality of two controls.
SplitterAllows you to create a browser-like interface with two panes.
DomainUpDownThe text box and
UpDownThe arrows are grouped together. Similar to a combo box, you can put any type of data into a list, and users can browse the data by clicking the up and down arrows.
TrackBarWith the old in Visual Basic 6.0
SliderControls are very similar.
HelpProviderIf you add this control to the component bar of a form, it will add to each control of the form
helpstring、
HelptopicAnd
ShowHelpProperty.
ToolTipIf you add this control to the component bar of a form, it will add to each control of the form
ToolTipProperty.
NotifyIconis typically used only when creating Windows services, so that you can set the system tray that appears in the taskbar
Icon。 When you click, you can display a menu or any form in that program.
ContextMenuAdd another menu to the form, and then assign it to any control on the form.
OpenFileDialogShow
OpenFiledialog box. In Visual Basic 6.0, this control is
CommonDialogThe method of the control.
SaveFileDialogShow
SaveFiledialog box. In Visual Basic 6.0, this control is
CommonDialogThe method of the control.
FontDialogShow
Fontdialog box. In Visual Basic 6.0, this control is
CommonDialogThe method of the control.
ColorDialogShow
Colordialog box. In Visual Basic 6.0, this control is
CommonDialogThe method of the control.
PrintDialogShow
Printdialog box. In Visual Basic 6.0, this control is
CommonDialogThe method of the control.
PrintPreviewDialogAnd
PrintPreviewControlUsed in combination.
PrintPreviewControlAllows the document to be sent to the Print preview window instead of to the printer.
ErrorProviderIf you add this control to the component bar of a form, it will add to each control of the form
Error、
iconalignmentAnd
iconpaddingProperty.
PrintDocumentWhen you use the control with other classes, you can send the document to the printer.
PageSetupDialogDisplays a dialog box that allows users to change settings such as page margins and page orientation.
changes to Attributes
To preserve the consistency of property names in all controls and make the property names more intuitive, the names of many properties have changed in relation to their names in Visual Basic 6.0. Some properties have been deleted because these properties, such as the DDE property, are no longer needed, or their functionality is replaced by other controls or methods in. NET.
Public properties that have been deleted
In Visual Basic 6.0, there are many properties that are common to all controls. In. NET, many of these properties have been removed because they no longer apply or their functionality has been handled in a completely different way. Table 3 lists the public properties of the Visual Basic 6.0 controls that are no longer available in. NET. Later in this article, you will learn about their equivalent attributes or why they are deleted.
The Visual Basic 6.0 properties that are not in table 3:.netProperties that have been deleted
DragIcon
DragMode
Index
Linkitem
LinkMode
Linktimeout
LinkTopic
MouseIcon
MousePointer
OLEDragMode
OLEDropMode
New Public properties
You will often need to use a common set of properties for all controls. As with Visual Basic 6.0, all controls in. NET also have a common set of properties. Table 4 lists the new properties and describes their functionality.
new properties in table 4:.netNew Attribute Description
accessibledescriptionThe description that is read aloud in the narrator's attachment. Narrator is a communication tool for visually impaired users that can read text on a computer screen for a user through a computer speaker. Most Windows systems have this feature, using the option to click Start | Program "|" Attachment "|" Accessibility tool, and then click Narrator. When you move the mouse over the screen, the tool reads the text on the screen. When you fill out this description and run the narrator tool, it reads this description for the user.
AccessibleNameThe name of the control that is reported in the narrator attachment.
AccessibleRoleNarrator attachments are the roles reported by the user.
AllowDropDetermines whether the control receives drag-and-drop notifications.
AnchorDetermines the anchor position of the control in the form. You can select any anchor style that you want.
ContextMenuSet this property to
ContextMenuThe control's name so that the menu of controls is automatically displayed when the right mouse button is clicked on the control.
DockDetermines the position of the control in the form. When you connect to a control, the control scales with the size of the form, but the connection position does not change.
LockedIf set to
True, the control cannot be moved at design time.
modifiersDetermines the scope of the control. By default, all the controls in. NET are
Friend。 In an older version of Visual Basic, all controls are
Public。 Now, you can choose
Private、
Protected、
FriendOr
Public。
Changed properties
In Visual Basic 6.0, there are four properties that are required for all controls, namely:
Left、
Top、
WidthAnd
Height。 Although these properties can still be used, it is best to use a name called
LocationAnd
SizeThe new structure. Table 5 lists these new properties and describes the structure of these new properties.
Location and Size properties in table 5:.netAttribute description
LocationPoint structure that indicates the X and Y coordinates where the control is located. In the old version of Visual Basic, you need to use the
LeftAnd
Topproperty to complete this setting.
SizeThat indicates the width and height of the control.
SizeStructure. In the old version of Visual Basic, you need to use the
WidthAnd
Heightproperty to complete this setting.
changes to general controls
Compared to Visual Basic 6.0, the way controls in. NET work has changed a lot. The following nine sections describe some of these changes and describe the impact of these changes on your development efforts in. NET.
The creation of the. NET control
One of the biggest changes in. NET compared to Visual Basic 6.0 is that the code for the instantiated control on the form is now visible and all of the previous code is hidden inside the ActiveX control and in the Visual basic runtime. Now expand the #Region portion of the code that follows the form to see the code. The following is an example of a form that contains a label, a text box, and a button control.
public Class frmtest inherits system.windows.forms.form#region "Windows Form Designer Generated code " public Sub New () mybase.new () ' Windows Forms Designer requires this call. initializecomponent () ' Add initialization after calling InitializeComponent (). end sub ' form overrides the configuration to clear the list of components. Protected Overloads Overrides Sub Dispose
(ByVal disposing as Boolean) if disposing then if not (components are nothing) then components. Dispose () end If end If mybase.dispose (disposing) end sub friend WithEvents Label1 as system.windows.forms.label friend WithEvents TextBox1 as System.windows.forms.textbox friend WithEvents Required for Button1 as system.windows.forms.button ' Windows forms Designer. private components as system.componentmodel.container ' NOTE: The following steps are Required by the Windows Forms Designer. ' can be modified using the Windows Forms Designer. ' Do not use the Code Editor for modification.
<system.diagnostics.debuggerstepthrough () > Private sub initializecomponent () me.label1 = New System.Windows.Forms.Label () me.textbox1 = New System.Windows.Forms.TextBox () me.button1 = New System.Windows.Forms.Button () me.suspendlayout () ' ' label1 ' me.label1.name = ' Label1 ' me.label1.tabindex = 0 Me.Label1.Text = "Label1" ' &nbSP; ' textbox1 ' Me.TextBox1.Location = New System.Drawing.Point (8) Me.TextBox1.Name = "TextBox1" me.textbox1.tabindex = 1 me.textbox1.text = "TextBox1" ' ' button1 ' me.button1.location = New System.Drawing.Point (112, 32) me.button1.name = "Button1" me.button1.tabindex = 2 me.button1.text = "Button1" ' ' frmtest ' me.autoscalebasesize = New System.Drawing.Size (5) me.clientsize = New System.Drawing.Size ( 392, me.controls.addrange (New System.Windows.Forms.Control ()) {me.button1, Me.textBox1, Me.Label1}) me.helpbutton = true Me.maximizebox = False me.minimizebox = False me.name = "Frmtest" me.text = " Frmtest " me.resumelayout (False) end Sub# End Regionend Class
As you can see, each control is created first and then the property, such as
LocationAnd
Size) for initialization. Any other properties you set in the Properties window of the Visual Studio Designer will also be added as code here. If you prefer, you can use Notepad only to design the user interface!
Note: do not change any code in the #Region area. This section of code is automatically created and destroyed by the Visual Studio environment when you add or remove controls on a form.
Anchoring
Like many Visual Basic developers, you must have written code several times to anchor the control to the bottom right of the form. If you want users to be able to resize the form, but you want some controls on the form to always remain positioned relative to the bottom and/or right of the form, you don't have to write code! Visual Studio. NET provides a simple solution: to take advantage of the Anchor property. This property allows you to anchor the control to either side or all sides of the container. If the anchor is at the bottom and/or right, the control will float when you resize the form, and if the anchor is on top and/or left, the size of the control will change as you resize the form. You need to actually do this to understand the effect of this property on the control.