compactFramework里面的pictureBox没有creatGarphics(),连Paint事件都没有,有什么办法呢?我想在任意地方画图,不用Form的Paint事件画,那样太麻烦了。
------解决方案--------------------
没办法哦好像只能在form 的paint事件了画哦 我以前查了很久的资料后来也没有找到别的方法哦
------解决方案--------------------
举个例子:
- C# code
private bool isDraw = false;//判断是否画 private void Form1_Load(object sender, EventArgs e) { this.groupBox1.Paint+=new PaintEventHandler(this.DrawInGroupBox); this.groupBox1.MouseLeave+=new EventHandler(groupBox1_MouseLeave); this.groupBox1.MouseEnter+=new EventHandler(groupBox1_MouseEnter); } private void groupBox1_MouseLeave(object sender, EventArgs e) { isDraw = false; //MessageBox.Show("leave"); } private void groupBox1_MouseEnter(object sender, EventArgs e) { this.isDraw = true; //MessageBox.Show("enter"); this.groupBox1.Invalidate(null); } private void DrawInGroupBox(object sender,PaintEventArgs e) { if (!isDraw) return; MessageBox.Show("draw"); //Graphics grfx = Graphics.FromHwnd(this.groupBox1.Handle); Graphics grfx = e.Graphics; grfx.DrawLine(new Pen(Color.Blue, 3), 10, 10, 100, 100); grfx.Dispose(); }
------解决方案--------------------
在mobile里做gdi+只能重新form_paint事件,其他办法至少我还没有找到 ~呵呵~
具体gdi+操作和在C#里面是一样的
推荐blog:
http://www.cnblogs.com/stg609/archive/2008/03/19/1113694.html