需要調用Win32 API了
要調用API麼,要先引用命名空間
using System.Runtime.InteropServices;
然後調用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));
}
在Form上拖個Button,拖大一點哦,小了圖標看不清
然後在Form1_Load裡,用API把圖標加到Button1上
private void Form1_Load(object sender, EventArgs e)
{
EnableElevateIcon_BCM_SETSHIELD(button1);
}最後執行看下效果吧!
恩?盾牌為啥有點不一樣呢,上面那個圖標是server08上的,win7上應該是下面這樣:
有錯誤的地方歡迎指出。