vb.net Click button is invalid toolbar

Source: Internet
Author: User
Tags exit
Button
When you write a program, you will encounter problems with existing controls that do not meet your requirements, and you will need to use a Third-party control or rewrite the existing controls yourself. The former is not much said, online search, the company to find, students find. What if you wrote it yourself? My experience is as follows:
1. See the need. Know what you want to do and what kind of function you need to accomplish. Take the following code example: Requirements-toolbarbutton must be available, when left click ToolBarButton, by the main program to pass some conditions (such as whether the user followed the prescribed steps) to determine whether to ignore the message, ignore the message after the interface should have no changes.
2. Find gaps. Find out what you want and what the existing controls are. Take the following code example: the existing Control toolbar, as long as the left click on the available ToolBarButton, the button will be reflected, and the demand is not let it react.
3. Find out how existing controls can achieve gaps. Take the following code example: toolbar does not use an overridable OnPaint method during the drawing process, so overriding the OnPaint method does not fulfill the requirement. Where can I extract information from the redraw? WndProc.
4. Design the interface of the class well. The reason we want to rewrite the existing controls is because we want to use the functionality that it does not now, so the interface is well designed to be helpful for future modifications. Take the following code example: provided to the main program of the event parameters included in the ToolBarButtons, may be the next program to be based on the mouse around the key to make some judgments, or modify some appearance.
5. Start coding. Try to standardize so that you can modify and view it later.
The code is as follows:
Public Class Clstoolbar
Inherits ToolBar
Public Event Previewbuttonclick as Previewbuttonclickhandler
Private M_blncandown as Boolean = True
Private Function Zgetmousedownbutton (ByVal Point as Point) as ToolBarButton
For each _tbtn as ToolBarButton in Me.buttons
If _tbtn. Rectangle.contains (point) Then
Return _TBTN
End If
Next
Return Nothing
End Function
Protected Overrides Sub WndProc (ByRef m as System.Windows.Forms.Message)
If m.msg = CInt (&h201) OrElse m.msg = CInt (&h203) Then ' left mouse button is &h201, double-click to &h203
Dim _point as Point = Me.pointtoclient (me.mouseposition)
Dim _tbtntemp as ToolBarButton = Zgetmousedownbutton (_point)
If not _tbtntemp are nothing Then
Dim _args as New Mybuttonclickeventargs (MouseButtons.Left, _tbtntemp)
RaiseEvent Previewbuttonclick (Me, _args)
If _args. Cancel Then
M_blncandown = False
Exit Sub
End If
End If
End If
If m.msg = CInt (&HF) then repaint to &HF
If M_blncandown = False Then
Exit Sub
End If
End If
If m.msg = CInt (&h200) then move mouse to &h200
M_blncandown = True
End If
Mybase.wndproc (M)
End Sub
End Class
Public Delegate Sub Previewbuttonclickhandler (ByVal s as Object, ByVal e as Mybuttonclickeventargs)
Public Class Mybuttonclickeventargs
Private M_blncancel as Boolean = False
Private M_btnclick as MouseButtons
Public Property Cancel () as Boolean
Get
Return Me.m_blncancel
End Get
Set (ByVal Value as Boolean)
Me.m_blncancel = Value
End Set
End Property
Public ReadOnly Property Mousebutton () as MouseButtons
Get
Return Me.m_btnclick
End Get
End Property
Public ToolBarButton as ToolBarButton
Public Sub New (ByVal Mousebutton as MouseButtons, ByVal button as ToolBarButton)
Me.m_btnclick = Mousebutton
Me.toolbarbutton = button
End Sub
End Class

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.