Upgrade to Microsoft .NET -> Visual Basic 6.0 Control and .NET Control Difference

zhaozj2021-02-08  197

Visual Basic 6.0 Control and .NET Control Difference

Upgrade to Microsoft .NET

PAUL D. SHERIFFPDSA, Inc. November 2001 Abstract: This article briefly introduces standard controls and equivalent Microsoft .NET controls in Microsoft Visual Basic 6.0. the goal

Learn which Visual Basic 6.0 ActiveX controls have an equivalent control in .NET. Learn about which attributes in the .NET control changes. Learn about what new controls in .NET. Prerequisites To completely understand the content of this article, you need to meet the following conditions:

Understand what is ActiveX control. Write a Windows application using the Visual Basic 6.0 control and ActiveX controls. table of Contents

Standard Control Differences. New Control Attributes in NET Controls Changes The Changes of Standards Controls Changes Summary Standard Controls Different from internal construction, and Microsoft .NET controls are very different from Microsoft® ActiveX® controls because .net The control is created from the hierarchies of other classes. These .NET controls have several classes inherited, as you understand the in-depth understanding of the actual control, you will find that every class is optimized and added more features. The top layer of the class hierarchy of the control is the Control class. But if you create your own control, these controls are likely to inherit from the UserControl class, because the userControl class contains the properties and events you need, and you can draw all the constituent controls. When you create a user interface with .NET, you will find a lot of familiar Microsoft Visual Basic® 6.0 controls that have not been disappeared or have been replaced. This article will briefly introduce standard controls in Visual Basic 6.0 and equivalent .NET controls. In the content later of this article, you'll learn how specific differences in all of these controls are on the attribute name. The functions of these controls are basically the same in Visual Basic 6.0 in addition to the attributes and some event names. Table 1 lists standard controls in the Visual Basic 6.0 toolbox and equivalent .NET controls. Although only some .NET controls are listed here, you can learn what the .NET control has changed. Table 1: ActiveX controls renamed in .NET

.NET controls PicturePictureBoxLabelLabelTextBoxTextBoxFrameGroupBoxCommandButtonButtonCheckBoxCheckBoxOptionButtonRadioButtonListBoxListBoxComboBoxComboBoxHScrollBarHScrollBarVscrollBarVScrollBarTimerTimerDriveListBox no equivalent Visual Basic 6.0 standard controls. Alternate by the OpenFileDialog control. Dirlistbox is not. Alternate by the OpenFileDialog control. FileListbox is not. Alternate by the OpenFileDialog control. Shape is not. Currently, you can use the class of the .NET Public Language Runtime (CLR) to draw shapes. Line is not. Currently you can use classes in the .NET CLR to draw straight lines. Image is not. You can display a single image using the PictureBox control. Data is not. The data binding in .NET is completely different from the data binding in Visual Basic 6.0. Ole is not. The new control in ImageListImageList .NET except for the standard control, the .NET also contains a set of new controls. Some of these controls have equivalent controls in Visual Basic 6.0, while others are new controls. Some new controls you can use in .NET are listed below. Table 2: Standard controls available to creating user interfaces

New Control Description LinkLabel allows you to place hyperlinks on a Windows Form. Its function is similar to hyperlink in the browser. MainMenu helps you create a menu on your form. DataGrid Displays the data in the ADO.NET dataset by form. This control is very similar to the FlexGrid control in Visual Basic 6.0, but it has many new features. CheckedListbox Enhanced ListBox allows users to select one or more items in the list by selecting the checkbox next to each project. To implement this feature in Visual Basic 6.0, you need to set the style property to 1-checked. TabControl combines the functions of two controls in TabStrip and SSTAB in Visual Basic 6.0. Splitter allows you to create interfaces similar to the browser, with two panes. DomainUpdown combines text boxes and Updown arrows. Its function is similar to the combo box, you can put any type of data into a list, users can browse data by clicking on the up arrows and down arrows. TrackBar is very similar to the old Slider control in Visual Basic 6.0. Helpprovider If you add this control to the component bar of the form, it adds the Helpstring, Helptopic, and Showhelp properties to each control of the form. Tooltip If you add this control to the component bar of the form, it adds the tooltip property to each of the controls. Notifyicon usually uses only when you create a Windows service, allow you to set the icon displayed in the system tray in the taskbar. When you click, you can display the menu or any form in the program. ContextMenu add another menu to the form and assigns any of the controls on the form. OpenFileDialog Displays the OpenFile dialog. In Visual Basic 6.0, this control is a method for the Commondialog control. SaveFileDialog Displays the Savefile dialog. In Visual Basic 6.0, this control is a method for the Commondialog control. FontDialog Displays the Font dialog. In Visual Basic 6.0, this control is a method for the Commondialog control. ColorDialog Displays the Color dialog. In Visual Basic 6.0, this control is a method for the Commondialog control. PrintDialog Displays the Print dialog. In Visual Basic 6.0, this control is a method for the Commondialog control. PRINTPREVIEWDIALOG is used in conjunction with PrintPreviewControl. PRINTPREVIEWCONTROL allows documents to be sent to the print preview window instead of being sent to the printer. ErrorProvider If you add this control to the component bar of the form, it adds ERROR, IconAlignment, and IconPadding properties to each control of the form. PrintDocument When you use this control with other classes, you can send a document to the printer. PageSetupDialog Displays a dialog box that can change the page margin and page directions on the above. Attribute changes In order to maintain the consistency of property names in all controls and make the attribute name more intuitive, many attributes have changed relative to their name in Visual Basic 6.0. Some properties have been deleted because these attributes (such as DDE properties) are no longer needed, or their feature has been replaced by other controls or methods in .NET. The deleted public property is in Visual Basic 6.0, there are many attributes that are common in all controls. In .NET, many such levels have been deleted because they are no longer applicable or their functions have been processed in a completely different way.

Table 3 lists the public properties of the Visual Basic 6.0 control that is no longer available in .NET. In the content later in this article, you will learn about their equivalent attributes or delete them. Table 3: Visual Basic 6.0 Property in .NET DragicondragmodeIndexLinkItemlinkModelinkTimeOutlinktopicMouseiconMousePointRagmodeoledropMode New Public Property You often need to use all controls. Public property set. Like Visual Basic 6.0, all controls in .NET also have a public property set. Table 4 lists each new attribute and introduces its functions. Table 4: New attributes in .NET

New Attribute Description AccessibleDescription "Tellors" The instructions read by the attachments. "Tellors" is a communication tool for users who have visual obstacles, which can read the text on the computer screen via the computer speaker. Most of the Windows systems have this feature, using the method to click "Start" | "Programs" | Accessories | "Accessibility Tool", and then click "Tellors". When you move your mouse on the screen, the tool will read the text on the screen. When you fill in this description and run the "Test Man" tool, it will read this description for the user. AccessIblename "Telling People" Accessories The name of the control report. AccessibleRole "Tellors" attachments are the role of the user's report. ALLOWDROP determines if the control receives drag and drop notifications. Anchor determines the anchor position of the control in the form. You can choose any anchoring style you need. ContextMenu sets this property to the name of the ContextMenu control, which is automatically displayed when you right-click on this control, and will automatically display the control menu. Dock determines the position of the control in the form. When the control is taken, the control will be scaled with the size of the form, but the position is constant. Locked If set to True, this control will not be moved during design. Modifiers determine the range of controls. By default, all controls in .NET are Friend. All controls are public for the old version of Visual Basic. Now you can choose private, protected, friend, or public. The changed properties are in Visual Basic 6.0, there are four attributes to be required for all controls, namely: Left, Top, Width, and Height. Although these attributes can still be used, it is best to use new structures called Location and SIZE. Table 5 lists these new properties and describes the structure of these new attributes. Table 5: Location and Size attributes in .NET

Property Description Location points to the Point structure of the X and Y coordinates of the location of the control. In the old version of Visual Basic, you need to use the LEFT and TOP properties to complete this setting. Size pointed out the Size structure of the width and height of the control. In the old version of Visual Basic, you need to use the width and height properties to complete this setting. Changes in conventional controls have changed significantly compared with Visual Basic 6.0. Some of the changes in these changes are introduced in the following Nine, which introduces these changes to the development of you in .NET. The creation of .NET control is compared to Visual Basic 6.0, one of the largest changes in .NET is that the code of the instantiation control on the form is now a visible. All of these code is hidden in the ActiveX control and the Visual Basic runtime. . Now, you can view the code in the #region section of the code behind the form. Below is a form example that contains a tag, 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 ()

The 'Windows Form Designer This call must be called.

InitializeComponent ()

'Adding initialization after calling initializecomponent ().

End Sub

'Form coverage configuration to clear the component list. Protected Overloads Overrides 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

Friend Withevents Label1 As System.Windows.Forms.Label

Friend Withevents TextBox1 As System.Windows.Forms.TextBox

Friend Withevents Button1 As System.Windows.Forms.Button

The 'Windows Form Designer is required.

Private components as system.componentmodel.container

'Note: The following steps are required for the Windows Form Designer.

'You can use the Windows Form Designer to modify it. 'Do not use the code editor to modify it. 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"

'

'TextBox1

'

Me.TextBox1.Location = new system.drawing.point (8, 80)

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, 13)

Me.ClientSize = new system.drawing.size (392, 250)

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 region

End Class can be seen that each control is created first, then initialize the property (such as Location and Size). Any other properties set in the "Properties" window of the Visual Studio designer will also be added as the code. If you prefer, you can use the "Notepad" to design the user interface!

Note: Do not change any code in the #Region area. This part of the code will be automatically created and destroyed by the Visual Studio environment when you add or delete the control in the form.

Like a lot of Visual Basic developers, you must have anchored the control in the right side of the form by writing code multiple times. If you want the user to adjust the form size, it is hoped that some of the controls on the form is always constant relative to the bottom and / or on the right, and you can write code! Visual Studio .NET provides a simple solution: using the anchor property. This property allows you to anchor the control on either side or all of the container. If anchored in the bottom and / or right side, the control will be floated when you adjust the form, if anchored on top and / or left, when you adjust the form size, the size of the control will change . You need to act now to understand the impact of this property on the control. Figure 1: Typical data input screen As shown in Figure 1, on the input form of data with the keyboard, you may want to keep the add, update, delete, and clear buttons in the lower right corner of the form. To achieve this, highlight these buttons and set the Anchor property to Bottomright. To do this, find the Anchor property in the Properties window, and click the drop-down arrow. Clear the column to select the left and the top, then select the column on the right and lower, as shown in Figure 2. Figure 2: The Properties dialog that has been activated anchor drop-down list Use the Anchor property, you do not have to write any of the code rows to anchor the control in any side of the form. By selecting the options in the graphical menu, you can select the required operations. In the code, the property value can be set using constants such as Topleft, Bottomright, Left, Right, Top, Bottom, Topleftbottom, and All. The Dock Dock property is similar to the Anchor property, allowing you to connect the control to any side of the container. When the control is taken, the control will be scaled with the form of the form, but the edges are kept unchanged, and if the control is attached to all edges of the form, the control will be full of the entire form. About control arrays In Visual Basic 6.0, set the NAME properties of all controls to the same value to create an array. Subsequently, the index attribute of each control is set to different numbers. The index value is passed to any event of the group control so you can know which control calls the event. This is one of the purposes of the Control array in Visual Basic 6.0, that is, an event process handles the code of multiple controls. In Visual Basic .NET, the way to process the array of controls is different. There are two ways to implement events that process multiple controls: using the AddHandler process in the .NET class, or use the Handles clause in the process. If you only want to write a CLICK event, make all buttons at the bottom of the form with this event, you can double-click one of the buttons to generate a Click event process. The code for this process is as follows: Private sub btnsave_click (_Byval Sender as object, _

ByVal e as system.eventargs)

Handles btnsave.click, btnnew.click, btndelete.click

MessageBox.show ("Click event")

End Sub Although the above code is simple, it illustrates how different controls call the same process. In addition to creating an array of controls, you can also respond to one or more events of multiple controls by creating and specifying event handles. In addition to the Handles clause, you can also use the AddHandler statement to implement a process to handle multiple controls. This statement allows you to add an event handler to any event and specify the process to be called. Since you can add an event handler to the event, you can use a series of event handlers to handle the same event, which is actually the process of telling the control to respond to the event. Because it is a commissioned event handler to handle this new process, this process is called "agent." To take effect, add similar to the following code in the new method in the form: addHandler btndelete.click, addressof buttonclick addhandler btnnew.click, addressof button After the above code is added, if you click The ButtonClick event process is called when the New, DELETE, or SAVE button is called. Of course, you may need to determine buttons that call this special event process. To do this, you can use the sender parameters that passed to all event processes, which is an object that produces the special event. So you can write the following code: Private sub buttonclick (_Byval Sender as object, _

ByVal e as system.eventargs)

IF sender is btnnew then

Messagebox.show ("Press New Button")

Elseif Sender is btnsave the

Messagebox.show ("Has a Save button")

Elseif Sender is btndelete Then

Messagebox.show ("Press the DELETE button")

END IF

End Sub's two ways of creating arrays have no essential difference, you can choose one. The default and cancel button In the old version of the Visual Basic, you need to set the DEFAULT property of the CommandButton control to True to tell Visual Basic's CLICK event should be called when you press Enter; set another CommandButton control Cancel property. To tell Visual Basic, the Click event of this button should be called when pressed the ESC button; then you must write code for each Click event process described above to close the form, and it is likely to set the properties, tell the call to call the routine of this form. Which button is pressed. Now, you can implement this purpose without writing any code for these buttons, users simply set the DialogResult property of each button to a specific value. For example, if the form contains a "OK" and "Cancel" buttons, set the DialogResult attributes of the two buttons to OK and Cancel. Then set the form's AcceptButton property to the "OK" button, set the form's CancelButton property to the "Cancel" button. Once you have completed the settings of these properties, you can use the showDialog method to display the form, and both buttons can automatically turn off the form. Then, the DialogResult property of the form is set to the DialogResult value set in the pressed button. This way, you can determine the button of the closing form can be determined from the calling program. Context Related menus In Windows applications, you may need to specify a special menu for the control to display the menu when you right-click the control. To implement this feature in Visual Basic 6.0, you need to set the Visible property of the created menu to False and write code during the Click event of the control to display hidden menus. In .NET, you can use the ContextMenu property to create a fully separated menu with the MinMenu of the form. You only need to set the ContextMenu property of the control, you can specify this menu to the control without having to write any code. After the lock control is locked on the form, you need to make sure you do not accidentally move the control when you click the control to add a code. There is an option in Visual Basic 6.0 to lock all controls on the form. This option is very easy, but sometimes you need to handle a small part of the content on a large form, there is a problem. To handle this small part, you must cancel the lock of all controls, so you may accidentally move the control. In .NET, you can lock or separately lock the control packet, which is useful when handling multiple sets of controls on a large form. Controls on the MDI form In Visual Basic 6.0, only those controls with Align properties can be placed on the MDI form; and in .NET, you can place any controls on the MDI form. DDE has been removed in .NET language, dynamic data exchange (DDE) technology is no longer available. In .NET, there are many communication methods between programs, and this technology is no longer needed, so all attributes having a LINK prefix in all controls have been deleted. Changes of standard controls This article has been mentioned above, and the properties of many standard controls have changed. Below is a changed property or the properties that have been added to each of the standard controls. The differences listed in the table below are limited to the specific properties of these controls, and the public attributes mentioned earlier have changed, and will not be described here. Tag Control New Properties Description Text This property is called CAPTION in Visual Basic 6.0. Text box control

New attribute description AcceptsReturn If set to True, the multi-line text box will use the CRLF as a valid character. To prohibit entering CRLF in the text box, set this property to false. AcceptStab If set to True, the multi-line text box will use the tab as a valid character. To prohibit entering tabs in the text box, set this property to false. CHARACTERCASING Controls the case of the letter typed in this control. Options include Normal, Uppercase, and LowerCase. Readonly If you want to prohibit users from entering text in this text box, set this property to True. This property is the same as the original Locked properties. TEXTALIGN This property controls the text alignment when the user typed data in the text area. This property can be set to LEFT, RIGHT or CENTER. Button Control New Properties Description BackgroundImage Allows the background image to be set on the button, you can also add text on the image. DialogResult When you call the form as a dialog, set the return result. If the user presses this button, the value in this property will be returned. FlatStyle changes the appearance of the button. Options include FLAT, POPUP, Standard, and System. If you use Windows XP, you should choose SYSTEM because this option allows you to use XP topics. Image displayed in this button. The placement position of the image in the image of the image. ImageIndexImageList control (set in ImageList properties) index number. The name of the ImageListImageList control uses the ImageIndex property in this control. TEXT This property is called CAPTION in Visual Basic 6.0. The text of the text displayed on the TextAlign control button is aligned. Options include Left, Right, Center, Middle, TOP, or Bottom, or a combination of any of the above options. Check box control

New attribute Description AutoCheck If set to TRUE, click anywhere of the control, and its status will be selected from the selection. BackgroundImage allows background images to be set on the checkbox control, you can also add text on your image. Checkalign determines the location of the checkbox control. Visual Basic 6.0 limits the location of the text on the left or right side of the check box. Now you can choose LEFT, RIGHT, UP, DOWN, or CENTER. Checkedtrue = Select, false = uncheck. CheckState This property allows the user to set three states in design to indicate the content you want to display at runtime. You can choose Checked, Unchecked, or Indeterminate. Note: The IndeterMinate option can only be set when the ThreeState property is set to TRUE. FlatStyle changes the appearance of the check box control. Options include FLAT, POPUP, Standard, and System. Image displayed in the check box. The placement position of the image in the ImageAlign check box. ImageIndexImageList control (set in ImageList properties) index number. The name of the ImageListImageList control uses the ImageIndex property in this control. TEXT This property is called CAPTION in Visual Basic 6.0. ThreeState If this property is set to True, you can set the checkState property to Indeterminate, and it also allows the user to switch between check, unchecked, and indeterminate. Single selection button control

New attribute Description AutoCheck If set to TRUE, click anywhere of the control, and its status will change from the selection to cancel. BackgroundImage allows the background image to be set on the radio button, you can also add text on the image. CheckAlign determines the location of the tag in the radio button. In Visual Basic 6.0, it can only be placed on the left or right side of the text. In .NET, you can choose LEFT, RIGHT, UP, DOWN, or CENTER. CHECKED This property is called Value in Visual Basic 6.0. FlatStyle changes the appearance of the radio button control. Options include FLAT, POPUP, Standard, and System. Image displayed in the radio button. ImageAlign selects the placement position of the image in the button. ImageIndexImageList control (set in ImageList properties) index number. The name of the ImageListImageList control uses the ImageIndex property in this control. TEXT This property is called CAPTION in Visual Basic 6.0. The textAlign controls the alignment of the text displayed on the radio button. This property can be set to Left, Right, Center, Middle, TOP, or Bottom, or a combination of any of the above options. Combination Box Control New Properties Description Displaymember Displays the list of controls from each object to ComboBox from each object. The default value of Displaymember is the toString method. DropDownStyle This property is called Style in Visual Basic 6.0. Like in Visual Basic 6.0, you can choose Simple, DropdownList, and Dropdown. The width of the DropDownWidth combination box pulls part (calculated in pixels). Can be different from the actual size of the combination frame on the form. The MaxDropDownItems user allows the number of items to be displayed using the pull-down section of the combo box. MaxLength Set the maximum number of characters that the DropDownStyle property is set to Simple. ValueMember retrieves data from the selected item. The default is the toString method. List box control

New Attribute Description ColumnWidth sets the multicolumn property to the width of each column when TRUE. Displaymember is displayed from each object to the list of ListBox in the list section of the control. The default value of Displaymember is the toString method. HorizontalExtent If you set the HorizontalscrollBar property to True, you can enter a number in this property indicating that the scroll bar can scroll (calculate in pixels). HorizontalscrollBar If you do not want to display a horizontal scroll bar when the width of the data is greater than this box, set this property to false. ItemHeight uses the height of the items in the list box when fixed fonts. Items replaces the list property of the Visual Basic 6.0 ListBox control. Multicolumn instead of the columns attribute in Visual Basic 6.0. If you want to display multiple rows, set this value to true. ScrollalWaysvisible If you want to display the scroll bar when the amount of data is small, set this property to true. This helps users determine the appropriate width of the list box based on the data that may be entered in this list box. If the data is loaded at runtime, you can see the scroll bar, it is best to set the width of the control at the data is too large. SelectionMode replaces the multislect property in Visual Basic 6.0. UseTabStop If you do not want Tab characters to represent different columns in the list box, set this property to false. ValueMember retrieves data from the selected item. The default is the toString method. Picture Box Control New Properties Description BackgroundImage Allows background images to be set on the image box, you can also add text on your image. BorderStyle includes None, Fixed, and Fixed3D options. Image is used instead of the Picture property. SiZemode Controls the display method of the picture. The values ​​that can be selected include Normal, StretchImage, AutoSize, and CenterImage. HScrollBar control

New attribute description Maximum instead of the max attribute in Visual Basic 6.0. Minimum instead of the min attribute in Visual Basic 6.0. Vscrollbar control

转载请注明原文地址:https://www.9cbs.com/read-3392.html

New Post(0)