Differences between Visual Basic 6.0 controls and. NET Controls (cont.)

Source: Internet
Author: User
Tags include min valid
visual| Control | Distinguish Figure 1: A typical data entry screen

As shown in Figure 1, you may want the ADD, Update, Delete, and clear buttons to remain in the lower-right corner of the form on the input form where you type the data by using the keyboard. To do this, highlight the buttons, and then set the Anchor property to BottomRight. To do this, locate the Anchor property in the Properties window and click its Drop-down arrow. Clear the columns to the left and top of the selection, and then select the columns to the right and bottom, as shown in Figure 2.



Figure 2: Properties dialog box with the Anchor drop-down list activated

With the Anchor property, you can anchor the control to any side of the form without writing any lines of code. By selecting the options in the graphical menu, you can select the action you want. In code, you can set property values by using constants such as TopLeft, BottomRight, left, right, top, Bottom, Topleftbottom, and all.

Connect
The Dock property is similar to the Anchor property, allowing you to dock the control to any side of the container. When you rely on a control, the control will scale with the form's scaling, but its attached side remains unchanged, and if you rest the control on all sides of the form, the control fills the entire form.

About control arrays
In Visual Basic 6.0, you can create a control array by setting the Name property of all controls to the same value. The Index property of each control is then set to a different number. The Index value is passed to any event in the group control, so that you can know which control has invoked the event. This is one of the purposes of the array of controls in Visual Basic 6.0, an event procedure that handles code for multiple controls.

In Visual Basic. NET, the way a control array is handled is very different. There are two ways to implement a procedure that handles events for multiple controls: Use the AddHandler procedure embedded in the. NET class, or use the Handles clause in the procedure.

If you only want to write a click event that enables all buttons at the bottom of the form to have the event, you can double-click one of the buttons to cause the code window to generate a click event procedure. The code for this procedure 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 shows how different controls invoke the same procedure. In addition to creating a control array, you can also respond to one or more events of multiple controls by creating and specifying an event handler.

In addition to the Handles clause, you can use the AddHandler statement to implement a procedure that handles events for multiple controls. This statement allows you to add an event handler to any event and specify the procedure to invoke. Because you can add an event handler to an event, you can use a series of event handlers to handle the same event, actually telling the control which procedure should be invoked to respond to the event. Because it is a delegate event handler to handle this new process, this process is called a "proxy."

To make the agent effective, add code similar to the following in the TODO comment for the existing code in the New method of the form:

AddHandler Btndelete.click, AddressOf ButtonClick

AddHandler Btnnew.click, AddressOf ButtonClick

When you finish adding the above code, if you click the New, Delete, or Save button, the ButtonClick event procedure is invoked. Of course, you might want to determine the button that calls this particular event procedure. To do this, you can use the sender parameter passed to all event procedures, which is the object that generated the particular 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 ("The New button has been pressed")
ElseIf Sender is Btnsave Then
MessageBox.Show ("The Save button has been pressed")
ElseIf Sender is Btndelete Then
MessageBox.Show ("The Delete button has been pressed")
End If
End Sub
There is no essential difference between the two methods of creating an array, and you can choose one at random.

Default and Cancel buttons
In an older version of Visual Basic, you need to set the Default property of the CommandButton control to True to tell Visual basic the Click event that this button should be called when the ENTER key is pressed; set another Command The Cancel property of the button control to tell Visual Basic that this button's Click event should be called when the ESC key is pressed, and then you must also write code to close the form for each of these Click event procedures, and you will most likely need to set the property to tell the routine that called this form to press the Which button it is.

Now, you do not need to write any code for these buttons to do this, and the user simply sets the DialogResult property of each button to a specific value. For example, if the form contains OK and Cancel buttons, set the DialogResult property of the two buttons to OK and cancel respectively. Then set the form's AcceptButton property to the OK button, and set the form's CancelButton property to the Cancel button.

When you have finished setting these properties, you can use the ShowDialog method to display the form, and two buttons can automatically close the form. The DialogResult property of the form is then set to the DialogResult value set in the pressed button. This allows you to determine the button that closes the form from within the calling program.

Context-related menus
In a Windows application, you might want to specify a special menu for the control to display when you right-click the control with the right mouse button. To implement this functionality in Visual Basic 6.0, you need to set the Visible property of the menu you have created to False, and then write code in the Click event procedure for the control to display the hidden menu.

In. NET, you can use the ContextMenu property to create a menu that is completely separate from the MainMenu of a form. You simply set the control's ContextMenu property so that you can assign the menu to the control without having to write any additional code.

Lock controls on a form
After you create the user interface, you need to make sure that you do not accidentally move controls when you click the control to add code. Visual Basic 6.0 has an option to lock all controls on a form. This option works fine, but sometimes you still need to work on a large form for a small amount of content, which can cause problems. To handle this small portion of the content, you must unlock all the controls so that you may inadvertently move the controls.

In. NET, you can block or lock controls individually, which is useful when working with multiple groups of controls on a large form.

Controls on an MDI form
In Visual Basic 6.0, only controls with Align properties can be placed on an MDI form, and in. NET, you could place any control on an MDI form.

DDE has been deleted
In. NET languages, Dynamic Data exchange (DDE) technology is no longer available. In. NET, there are many methods of communication between programs that no longer require this technology, so all properties that have Link prefixes in all controls have been deleted.

Changes to standard controls
As mentioned earlier in this article, the properties of many of the standard controls have changed. The following are properties that have been changed or properties that have been added to each of the different standard controls. The differences listed in the following table are limited to the specific properties of these controls, and the public properties mentioned above are also changed, and are not discussed here.

Label controls

New Attribute Description
Text This property is called Caption in Visual Basic 6.0.

Text Box control

New Attribute Description
Acceptsreturn if set to True, the multiline text box treats CRLF as a valid character. To prevent entering CRLF in the text box, set this property to False.
AcceptsTab if set to True, a multiline text box treats tabs as valid characters. To prevent entering tabs in the text box, set this property to False.
CharacterCasing controls the case of the letters that users type in this control. Options include Normal, uppercase, and lowercase.
ReadOnly set this property to True if you want to prevent users from entering text in this text box. This property has the same functionality as the original Locked property.
TextAlign This property controls how text is aligned when the user types data in a text area. You can set this property to left, right, or Center.



Button control

New Attribute Description
BackgroundImage allows you to set the background image on the button and add text to the image.
DialogResult sets the return result when a form is called as a dialog box. If the user presses this button, the value in this property is returned.
FlatStyle change the appearance of the button. Options include Flat, PopUp, Standard, and System. If you are using Windows XP, you should select System because this option allows you to use an XP theme.
Image that is displayed in this button.
The placement position of the image in the ImageAlign button.
ImageIndex the index number of the image in the ImageList control (set in the ImageList property).
ImageList the name of the ImageList control in which the ImageIndex property is used to retrieve the image.
Text This property is called Caption in Visual Basic 6.0.
TextAlign the alignment of the text displayed on the control button. Options include a combination of left, right, center, middle, top, or bottom, or any of the above options.


check box control

New Attribute Description
AutoCheck if set to True, click anywhere in the control and its status will change from checked to unchecked.
BackgroundImage allows you to set a background image on a check box control, and you can add text to the image.
CheckAlign determines the position of the check box control. Visual Basic 6.0 limits the position of the text to the left or right of the check box. Now you can select left, right, up, down, or center.
Checked true= selected, false= unchecked.
CheckState This property allows the user to set three states at design time to indicate what you want the control to display at run time. You can choose Checked, Unchecked, or indeterminate. Note: You can set the indeterminate option only if you set the ThreeState property to True.
FlatStyle changes the appearance of the check box control. Options include Flat, PopUp, Standard, and System.
Image that is displayed in the check box.
ImageAlign the location where the image is placed in the check box.
ImageIndex the index number of the image in the ImageList control (set in the ImageList property).
ImageList the name of the ImageList control in which the ImageIndex property is used to retrieve the image.
Text This property is called Caption in Visual Basic 6.0.
ThreeState If this property is set to True, the CheckState property can be set to indeterminate, and it also allows the user to switch between Checked, Unchecked, and indeterminate three states.


Radio Button control

New Attribute Description
AutoCheck if set to True, click anywhere in the control and its status will change from checked to unchecked.
BackgroundImage allows you to set the background image on the radio button and add text to the image.
CheckAlign determines the position of the selected marker in the radio button. In Visual Basic 6.0, you can only place it on the left or right side of the text. In. NET, you can select 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 that is displayed in the radio button.
ImageAlign where the image is placed in the radio button.
ImageIndex the index number of the image in the ImageList control (set in the ImageList property).
ImageList the name of the ImageList control in which the ImageIndex property is used to retrieve the image.
Text This property is called Caption in Visual Basic 6.0.
TextAlign controls the alignment of the text displayed on the radio button. You can set this property to left, right, center, middle, top, or bottom, or a combination of any of these options.


Combo box control

New Attribute Description
DisplayMember Displays items loaded into ComboBox from each object in the list section of the control. The default value for DisplayMember is the ToString method.
DropDownStyle This property is called Style in Visual Basic 6.0. As in Visual Basic 6.0, you can choose Simple, DropDownList, and DropDown.
DropDownWidth the width of the drop-down portion of the combo box (in pixels). Can be different from the actual size of a combo box on a form.
MaxDropDownItems the number of items allowed to be displayed when the user uses the Drop-down portion of the combo box.
MaxLength the maximum number of characters that can be entered when the DropDownStyle property is set to simple.
ValueMember retrieves data from the selected item. The default value is the ToString method.


List box control

New Attribute Description
ColumnWidth the width of each column when the Multicolumn property is set to True.
DisplayMember displays items loaded from each object into the ListBox in the list section of the control. The default value for DisplayMember is the ToString method.
HorizontalExtent If you set the Horizontalscrollbar property to True, you can enter a number in this property to indicate the maximum width (in pixels) that the scroll bar can scroll.
Horizontalscrollbar set this property to False if you do not want the horizontal scroll bar to appear when the data is wider than this box.
ItemHeight the height of the items in the list box when you use a fixed font.
Items Replace the List property of the Visual Basic 6.0 ListBox control.
Multicolumn replaces the Columns attribute in Visual Basic 6.0. If you want to display multiple rows, set this value to True.
Scrollalwaysvisible set this property to True if you want the scroll bar to still appear when the amount of data is small. This helps the user determine the appropriate width of the list box based on the data that may be entered in this list box. If you load the data at run time, you can see the scroll bar, preferably when the data is too large to set the width of the control correctly.
SelectionMode replaces the MultiSelect attribute in Visual Basic 6.0.
Usetabstop set this property to False if you do not want the Tab character to represent a different column in the list box.
ValueMember retrieves data from the selected item. The default value is the ToString method.


Picture Box control

New Attribute Description
BackgroundImage allows you to set the background image on the picture frame and add text to the image.
BorderStyle includes the None, Fixed, and FIXED3D options.
Image is used instead of the Picture property.
SizeMode controls how pictures are displayed. The values you can select Include Normal, StretchImage, AutoSize, and CenterImage.


HScrollBar Control

New Attribute Description
Maximum replaces the Max attribute in Visual Basic 6.0.
Minimum replaces the Min attribute in Visual Basic 6.0.


VScrollBar control

Attribute description
Maximum replaces the Max attribute in Visual Basic 6.0.
Minimum replaces the Min attribute in Visual Basic 6.0.


Other controls
In addition to the standard controls in Visual Basic 6.0, many other controls are upgraded in Visual Basic. NET. In fact, there are so many upgraded controls that each control can write a single article. Knowing the changes listed in this article gives you a clear idea of the types of changes you will encounter when you use these new controls in. NET.

Summarize
The way in which the user interface is created in. NET has changed a lot. Some of the controls you've used before have ceased to exist or become very different from the original. To perform specific actions, you need to use these new properties, and sometimes you must use a system class instead of a control. You will find that the. NET control has considerably improved relative to the original ActiveX control. With these new properties and new methods, you can help you develop better Windows applications.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.