怎样用GDI画BUtton的背景,样子等? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LZ 直接给Button 的背景添加图片不行吗?LZ想要什么样的效果? button1_Paint 事件中画Graphics g = e.Graphics; 形状使用Region属性可以控制,绘制放在其Paint事件处理方法中。 自己做一个Button1.新建一个UserControl2. Protected override void OnPaint(...) { Graphics g = e.Graphics;//建立画图对象 GraphicsPath buttonPath = new GraphicsPath(); //自定义Button的形状; buttonPath.AddRectange(this.ClientRectange); //矩形Button; g.DrawImage((image),ClientRectange); //Image背景;//也可以用渐变色填充 g.DrawPath(Pens.Black,buttonPath); g.DrawString(.....); ...... } //鼠标事件 private void MouseClick(...) {...} private void MouseEnter(...) {...} ......3.生成就可以用了. 上图中,1-5图分别为素材图和窗体设计时截图,6为运行时效果图下面的代码是通过通过VB2008在线转换成的C#代码Graphics G; Bitmap B_LEFT; Bitmap B_TOP; Bitmap B_BOTTOM; Bitmap B_RIGHT; Bitmap BP; Bitmap B1; Bitmap B_TR; //---------------------------- public void 普通(Button 物件) { // ERROR: Not supported in C#: OnErrorStatement 物件.FlatStyle = FlatStyle.Flat; 物件.BackColor = Color.Transparent; 矩形 = new Rectangle(0, 0, 物件.Width, 物件.Height); B1 = new Bitmap(矩形.Width, 矩形.Height); G = Graphics.FromImage(B1); G.DrawImage(My.Resources.button, new Rectangle(0, 0, 10, 13), new Rectangle(1, 0, 10, 13), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(0, 矩形.Height - 14, 10, 14), new Rectangle(1, 14, 10, 14), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(矩形.Width - 10, 0, 10, 13), new Rectangle(77, 0, 10, 13), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(矩形.Width - 10, 矩形.Height - 14, 10, 14), new Rectangle(77, 14, 10, 14), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(10, 0, 矩形.Width - 20, 13), new Rectangle(11, 0, 26, 13), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(10, 矩形.Height - 14, 矩形.Width - 20, 14), new Rectangle(11, 14, 26, 14), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(0, 13, 10, 矩形.Height - 27), new Rectangle(1, 13, 10, 1), GraphicsUnit.Pixel); G.DrawImage(My.Resources.button, new Rectangle(矩形.Width - 10, 13, 10, 矩形.Height - 27), new Rectangle(77, 13, 10, 1), GraphicsUnit.Pixel); G.Dispose(); 物件.BackgroundImage = B1; 物件.ForeColor = Color.White; 物件.FlatAppearance.BorderColor = Color.Transparent; 物件.FlatAppearance.BorderSize = 0; 物件.FlatAppearance.CheckedBackColor = Color.Transparent; 物件.FlatAppearance.MouseDownBackColor = Color.Transparent; 物件.FlatAppearance.MouseOverBackColor = Color.Transparent; } http://www.chenjiliang.com/Article/View.aspx?ArticleID=4439 怎么移动 动态加载的 Lable .Net serialport类读取串口数据 一个关于Enum.Parse的列子不明白 新手问题,怎么多个控件触发同一事件? ShowDialog()方法,小问 一个asp.net的问题,请教高手 WPF 中Label怎么没有autosize属性了 在.net remoting中,服务器如何才能调用客户端的对象? c#如何能申请一段连续空间地址的数组 知道图片在网上的url,怎么把图片原样取到图片文件?? httpwebrequest身份验证问题 C# 邮件群 退信
Graphics g = e.Graphics;
2. Protected override void OnPaint(...)
{
Graphics g = e.Graphics;//建立画图对象
GraphicsPath buttonPath = new GraphicsPath(); //自定义Button的形状;
buttonPath.AddRectange(this.ClientRectange); //矩形Button;
g.DrawImage((image),ClientRectange); //Image背景;//也可以用渐变色填充
g.DrawPath(Pens.Black,buttonPath);
g.DrawString(.....);
......
}
//鼠标事件
private void MouseClick(...) {...}
private void MouseEnter(...) {...}
......
3.生成就可以用了.
Bitmap B_LEFT;
Bitmap B_TOP;
Bitmap B_BOTTOM;
Bitmap B_RIGHT;
Bitmap BP;
Bitmap B1;
Bitmap B_TR;
//----------------------------
public void 普通(Button 物件)
{
// ERROR: Not supported in C#: OnErrorStatement
物件.FlatStyle = FlatStyle.Flat;
物件.BackColor = Color.Transparent;
矩形 = new Rectangle(0, 0, 物件.Width, 物件.Height);
B1 = new Bitmap(矩形.Width, 矩形.Height);
G = Graphics.FromImage(B1);
G.DrawImage(My.Resources.button, new Rectangle(0, 0, 10, 13), new Rectangle(1, 0, 10, 13), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(0, 矩形.Height - 14, 10, 14), new Rectangle(1, 14, 10, 14), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(矩形.Width - 10, 0, 10, 13), new Rectangle(77, 0, 10, 13), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(矩形.Width - 10, 矩形.Height - 14, 10, 14), new Rectangle(77, 14, 10, 14), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(10, 0, 矩形.Width - 20, 13), new Rectangle(11, 0, 26, 13), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(10, 矩形.Height - 14, 矩形.Width - 20, 14), new Rectangle(11, 14, 26, 14), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(0, 13, 10, 矩形.Height - 27), new Rectangle(1, 13, 10, 1), GraphicsUnit.Pixel);
G.DrawImage(My.Resources.button, new Rectangle(矩形.Width - 10, 13, 10, 矩形.Height - 27), new Rectangle(77, 13, 10, 1), GraphicsUnit.Pixel);
G.Dispose();
物件.BackgroundImage = B1;
物件.ForeColor = Color.White;
物件.FlatAppearance.BorderColor = Color.Transparent;
物件.FlatAppearance.BorderSize = 0;
物件.FlatAppearance.CheckedBackColor = Color.Transparent;
物件.FlatAppearance.MouseDownBackColor = Color.Transparent;
物件.FlatAppearance.MouseOverBackColor = Color.Transparent;
}