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.