RFID conference sign-in system summary (17th)-menu and toolbar Transformation (II)

Source: Internet
Author: User

 

After the two interfaces defined in the previous article, the menu and toolbar basically matchCommandMode, you can load it in the system. But theoretically, it is one thing to follow the pattern, actually writingCodeIt is another thing.

We are sorry to find that Toolbarbutton This class does not even have a click event UI None of the related events, because they are not Control Inherited, but from Component Inherited. Click the toolbar button from the toolbar Toolbar Of Buttonclick Event, that is, if you want to hang up a code that clicks a single button on the toolbar Toolbar In terms of events, there is no such thing as a strange design. This Toolbar It can only be used in static places (in fact, even static places, this Buttonclick The event is also very bad, and the abnormal event of the static Toolbar will be seen later), for the dynamic Toolbar . NET Framework This Toolbar It is powerless.

No, let's change it. Click events on our own. Below isToolbarbuttonComplete code:


Toolbarbutton
Public   Class Commandtoolbarbutton: toolbarbutton, icommandholder

{

Private   String _ Id;

Private Icommand command;

 

Public   Event Eventhandler onclick;

 

Public   String ID

{

Get   {Return_ Id ;}

Set   {_ Id=Value ;}

}

 

Public Commandtoolbarbutton ( String Name ): Base (Name) {}

 

Icommandholder Member # Region Icommandholder Member

 

Public Icommand getcommand ()

{

ReturnCommand;

}

 

Public   Void Setcommand (icommand cmd)

{

Command=CMD;

}

 

# Endregion

 

Internal   Virtual   Void Doonclick () {

If(Onclick! = Null)

Onclick (This, System. eventargs. Empty );

}

 

}

 

to enable toolbar Get To Know This Ton perform minor changes, toolbarbutton .

Protected Override VoidWndproc (RefMessage m ){

If(M. MSG = 0x2111 ){

IntIndex = ((Int) M. wparam) & 0 xFFFF;

Toolbarbutton button =This. Buttons [Index];

If(Button! =Null){

Commandtoolbarbutton commandbtn = buttonAsCommandtoolbarbutton;

If(Commandbtn! =Null){

Commandbtn. doonclick ();

}Else{

Toolbarbuttonclickeventargs args1 =NewToolbarbuttonclickeventargs (button );

This. Onbuttonclick (args1 );

}

}

 

}Else

Base. Wndproc (RefM );

 

Base. Resetmouseeventargs ();

}

 

the above Code contains a magic number , in Win32 API indicates that the cyclic message ( wm_entermenuloop , note that it is not written in the click message ), because the message constants are rarely used, I am just a little lazy and write it directly.

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.