【转载】c# winform 怎么给程序的按钮上也加上小盾牌图标
2013-12-11 15:58
309 查看
【转载于博客】2cto.com/kf/201304/205317.html
c# winform 怎么给程序的按钮上也加上小盾牌图标
作者:simadi
需要调用Win32 API了
【1】要调用API么,要先引用命名空间
using System.Runtime.InteropServices;
【2】然后调用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,拖大一点哦,小了图标看不清
【3】然后在Form1_Load里,用API把图标加到Button1上
private void Form1_Load(object sender, EventArgs e)
{
EnableElevateIcon_BCM_SETSHIELD(button1);
}
最后执行看下效果吧!
恩?盾牌为啥有点不一样呢,上面那个图标是server08上的,win7上应该是下面这样:
有错误的地方欢迎指出。
c# winform 怎么给程序的按钮上也加上小盾牌图标
作者:simadi
需要调用Win32 API了
【1】要调用API么,要先引用命名空间
using System.Runtime.InteropServices;
【2】然后调用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,拖大一点哦,小了图标看不清
【3】然后在Form1_Load里,用API把图标加到Button1上
private void Form1_Load(object sender, EventArgs e)
{
EnableElevateIcon_BCM_SETSHIELD(button1);
}
最后执行看下效果吧!
恩?盾牌为啥有点不一样呢,上面那个图标是server08上的,win7上应该是下面这样:
有错误的地方欢迎指出。
相关文章推荐
- c# winform 怎么给程序的按钮上也加上小盾牌图标
- C# winform程序怎么打包成安装项目(图解)
- C# 强制退出WinForm程序之Application.Exit和Environment.Eixt(转载)
- [转载]c# winform 获取当前程序运行根目录
- 用 c 调用 win-api 实现自动点击c# winform 程序 的按钮
- 怎么给自己的程序加上图标
- 【转载】C#Winform程序如何发布并自动升级(图解)
- C# winform程序怎么打包成安装项目(图解)
- C#winform中怎么将程序最小化到系统托盘
- C#winform中怎么将程序最小化到系统托盘
- C# winform程序怎么打包成安装项目(VS2010图解)
- C#winform中怎么将程序最小化到系统托盘
- C#实现WinForm程序的动态系统托盘图标
- C#winform中怎么将程序最小化到系统托盘
- C#窗体程序怎么点击按钮打开一个选择文件的对话框
- C# winform程序中datagridview里按钮的单击事件
- C#winform中怎么将程序最小化到系统托盘
- C# Winform 怎么让按钮在Panel里居中显示
- 【转载】C# WinForm程序中使用Unity3D控件
- 在C#中怎么让应用程序在任务栏上显示该程序的图标?