在按钮上绘制图片
2012-11-19 17:13
127 查看
using System; using System.Drawing; using System.Windows.Forms; namespace 在button上绘制图片 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.button1.Click+=new EventHandler(button1_Click); this.button1.Paint+=new PaintEventHandler(button1_Paint); } Bitmap bm; private void button1_Click(object sender, EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.InitialDirectory = @"E:\"; of.Filter = "图片文件|*.jpg;*.png;*.gif"; if (of.ShowDialog() == DialogResult.OK && of.FileName != "") { bm = new Bitmap(of.FileName); this.Invalidate();//使当前操作区域无效,并导致重绘事件 } } private void button1_Paint(object sender, PaintEventArgs e) { if (bm != null) { Graphics g=e.Graphics; TextureBrush b=new TextureBrush(bm); Button bt = (Button)sender; bt.Width = bm.Width; bt.Height = bm.Height; if (this.Width < bm.Width) { this.Width = (int)(bm.Width * 1.3); } if (this.Height < bm.Height) { this.Height = (int)(bm.Height*1.3); } g.FillRectangle(b, this.ClientRectangle); } } } }
相关文章推荐
- dskinlite(uieasy mfc界面库)使用记录2:绘制动态元素(按钮控件绘制元素动态控制,改变图片和文字)
- dskinlite(uieasy mfc界面库)使用记录3:绘制动态元素(按钮控件通过隐藏方式修改图片显示)
- dskinlite(uieasy mfc界面库)使用记录2:绘制动态元素(按钮控件绘制元素动态控制,改变图片和文字)
- dskinlite(uieasy mfc界面库)使用记录3:绘制动态元素(按钮控件通过隐藏方式修改图片显示)
- 重新绘制TabControl的Tabpage标签,添加图片及关闭按钮
- 重新绘制TabControl的Tabpage标签,添加图片及关闭按钮
- Android[高级教程] Android程序调用本地图片并进行绘制
- canvas绘制圆、渐变、字体和图片及其他
- IE7下按钮<input>不显示自定义背景图片
- MFC给按钮添加图片
- 用按钮打开对话框选取图片按大小显示在控件中
- 【签名】点击按钮弹出签名框,保存成图片,并显示出来
- iOS开发——UI进阶篇(十八)核心动画小例子,转盘(裁剪图片、自定义按钮、旋转)图片折叠、音量震动条、倒影、粒子效果
- 如何给wpf的按钮添加背景图片
- 用纯CSS3的animation制作雪花飘落、星星闪烁、按钮缩放、图片倾斜
- C#(WPF)按钮图片不显示,壁纸切换功能
- 使用GDI+创建支持更多图片格式的按钮
- Skia深入分析3——skia图片绘制的实现(2)
- Qt中为工程添加资源文件、给按钮添加图片
- Java自定义图片按钮