Add a shield icon to a button in a program

Source: Internet
Author: User

Earlier in the Windows 7 compatibility webcast I made a shield icon of the demo, this icon is to say click on the button to perform a request to enhance the rights of the operation, to write its main implementation process and the webcast in the demo released.

In fact, the main implementation is to invoke the method in User32.dll to paste the existing button control a small icon, you can use the following methods to implement:

[DllImport ("user32.dll")]
private static extern IntPtr SendMessage (handleref hWnd, uint MSG, IntPtr WParam, IntPtr lParam);

/**////////////////////////////////////////////////////////////////////////
///<summary& Gt        
///enables the elevated shield icon on the given button control
///</summary>
        <param name= "Thisbutton"
///button control to enable the elevated icon on.
</param>
///////////////////////////////////////////////////////////////////////
P rivate void Enableelevateicon_bcm_setshield (Button Thisbutton)
{
//Input validation, validate             That's not NULL
if (Thisbutton = null)
{
return;
ThisControl           

//Define Bcm_setshield locally, declared originally in Commctrl.h
  UINT Bcm_setshield = 0x0000160c;

//Set button style to the system style
Thisbutton.flatstyle = FlatStyle.System;

//Send the Bcm_setshield message to the button control
SendMessage (new HandleRef THISBU Tton, Thisbutton.handle), Bcm_setshield, new IntPtr (0), new IntPtr (1));
}

You can then implement the effect by passing the button directly into the method:

EnableElevateIcon_BCM_SETSHIELD(button2);

The implementation effect is as follows:

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.