C # How does winform add a small shield icon to the buttons of the program?

Source: Internet
Author: User

Win32 API needs to be called.

Do you want to call an API? You need to reference the namespace first.

Using System. Runtime. InteropServices;

Then call the API

[DllImport ("user32.dll")]
Private static extern IntPtr SendMessage (HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam );

//////////////////////////////////////// ///////////////////////////////
/// <Summary>
/// Enables the elevated shield icon on the given button control
/// </Summary>
/// <Param name = "ThisButton">
/// Button control to enable the elevated shield icon on.
/// </Param>
//////////////////////////////////////// ///////////////////////////////
Private void EnableElevateIcon_BCM_SETSHIELD (Button ThisButton)
{
// Input validation, validate that ThisControl is not null
If (ThisButton = null)
{
Return;
}

// 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 (ThisButton, ThisButton. Handle), BCM_SETSHIELD, new IntPtr (0), new IntPtr (1 ));
}

Drag a Button on the Form to make it bigger. The icon cannot be seen clearly.

 

Then, add the icon to Button1 using the API in Form1_Load.

Private void Form1_Load (object sender, EventArgs e)
{
EnableElevateIcon_BCM_SETSHIELD (button1 );
} Finally, let's see the effect!
Well? Why is shield a little different? The icon above is on server08, And the icon on win7 should be as follows:
If there is any error, please note it.

Related Article

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.