visual| Create | Control step 6th: Clean up
For the control to work smoothly, we also need to do some other things. For example, the control needs to be redrawn when the size changes. And, in order not to change the proportions of the controls, we need to detect when the properties that affect the size change, and then force the width equal to One-third of the height. The following is an event handler that completes both tasks:
Private Sub trafficlight_resize (ByVal sender as Object, _
ByVal e as System.EventArgs) Handles mybase.resize
Me.invalidate ()
End Sub
Private Sub trafficlight_layout (ByVal sender as Object, _
ByVal e as System.Windows.Forms.LayoutEventArgs) _
Handles Mybase.layout
Select Case E.affectedproperty
Case "Bounds"
Me.Width = CInt (Me.height * 0.3333)
Case Else
' Do not perform any action
End Select
End Sub
Finally, set the icon that the control uses in the Toolbox. The control already has a default icon that looks like a gear, but we want to use the traffic light icon that is included with Visual Studio. NET.
The Toolbox icon for a control is set by an attribute in the class named ToolboxBitmap. Insert the following line above the line starting with public Class:
Note: All content should be on one line. To facilitate reading, we placed a carriage return after Studio. When you paste the code, make sure that they are on a single line, just a space between Studio and. NET, and delete the carriage return. If you have installed Visual Studio. NET to its default location, the code above will set the attribute with an icon in the Visual Studio directory. If you do not install Visual Studio. NET to its default location, you will need to change the path name of the icon accordingly.
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.