When you write a program, you will encounter problems where the existing control cannot meet the requirements. In this case, you need to use a third-party control or rewrite the existing control by yourself. I won't say much about the former. I want to find it online, in the company, and in the students. What if it is written by yourself? My experience is as follows:
1. view the requirements. Know what you want to do and what features you need to complete. Take the following code as an example: requirement-the toolbarbutton must be available. When the left-click toolbarbutton, the main program will pass certain conditions (such as whether the user follows the prescribed steps) determine whether to ignore the message. The interface should remain unchanged after the message is ignored.
2. Search for gaps. Find out the difference between the desired function and the existing control. Take the following code as an example: in the toolbar of an existing control, the button will be reflected by clicking the available toolbarbutton with the left button. The requirement is that it will not be reflected.
3. Find out how to implement the gaps of existing controls. Take the following code as an example: the toolbar does not use the onpaint method that can be rewritten during the painting process. Therefore, the onpaint method cannot be rewritten. Where can I extract the re-painting information? WndProc.
4. design the class interface. The reason why we need to rewrite the existing control is that we need to use the functions that it does not currently have, so designing the interface is very helpful for future changes. Take the following code as an example: the event parameters provided to the main program include toolbarbuttons. In the future, the main program may need to make some judgments or modify some appearances Based on the left and right keys of the mouse.
5. Start encoding. Standardize as much as possible for future modification and viewing.
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