如何调用picturebox的paint事件

chrisJiang 2003-08-22 01:28:43
参数(object sender,system.windows.forms.paintEventArgs)应怎样传入?
还有怎样在picturebox的image上放一个图标?
...全文
768 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxc1981 2003-08-23
  • 打赏
  • 举报
回复
参考了楼上的似乎应当是:
pictureBox1_Paint(this.pictureBox1, System.Windows.Forms.PaintEventArgs(Graphics.FromHwnd(this.pictureBox1.Handle),this.pictureBox1.ClientRectangle));
xxc1981 2003-08-23
  • 打赏
  • 举报
回复
调用的时候你可以试试:
pictureBox1_Paint(this.pictureBox1, System.Windows.Forms.PaintEventArgs());
但我没测试过的哦!

qqq123 2003-08-23
  • 打赏
  • 举报
回复
private void pictureBox1_Click(object sender, System.EventArgs e)
{
Graphics g=Graphics.FromHwnd(this.pictureBox1.Handle);
PaintEventArgs e=new PaintEventArgs(g,this.pictureBox1.ClientRectangle);
this.pictureBox1_Paint(this.pictureBox1,e);
g.Dispose();
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

}
chrisJiang 2003-08-23
  • 打赏
  • 举报
回复
呵呵,别这么急嘛,我的意思就是怎样写这两个参数,能些个例子吗?
xxc1981 2003-08-22
  • 打赏
  • 举报
回复 1
this.picturebox.refresh();就可以了
或者 直接调用事件函数: picturebox_paint(sender,e);
注意,如果没有sender和e,就需要自己事先定义,
可以给分吗?
chrisJiang 2003-08-22
  • 打赏
  • 举报
回复
我的意思是说在别的地方调用此事件该怎么做?他的参数怎么写?
windyyang 2003-08-22
  • 打赏
  • 举报
回复
有事件OnPaint,在里面写处理程序就可以了
liduke 2003-08-22
  • 打赏
  • 举报
回复
picture1.paint();
picture1.image = new bitmap(imagepath)
using System; using System.Drawing; using System.Windows.Forms; namespace 象棋 { public partial class Form1 : Form//依然纯代码 不过要调用图片了 棋盘自己画的 棋子是图片 { int[,] ai ={{5,4,3,2,1,2,3,4,5}, {0,0,0,0,0,0,0,0,0}, {0,6,0,0,0,0,0,6,0}, {7,0,7,0,7,0,7,0,7}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {17,0,17,0,17,0,17,0,17}, {0,16,0,0,0,0,0,16,0}, {0,0,0,0,0,0,0,0,0}, {15,14,13,12,11,12,13,14,15}}; Control bi = null,ci=null,di=null; int ao, bo; public Form1() { Size = new Size(650, 750); this.BackColor = Color.White; Text = "象棋--作者:彳亍乐儿"; StartPosition = FormStartPosition.CenterScreen; MouseDown += new MouseEventHandler(md);//布局 Paint += new PaintEventHandler(huitu); for(int i=0;i<10;i++)//上棋子 for (int l = 0; l < 9; l++) if (ai[i, l] != 0) { PictureBox a = new PictureBox(); a.Image = new Bitmap(ai[i, l] + ".png"); a.Size = new Size(60, 60); a.Tag = ai[i, l]; if (ai[i, l] < 10)//决定谁先出棋 a.Enabled = false; a.Click += new EventHandler(cl); a.Location = zb(new Point((l + 1) * 64, (i + 1) * 64)); if (ai[i, l] == 1) di = a; if (ai[i, l] == 11) ci = a; Controls.Add(a); } } void md(object sender, MouseEventArgs e) { int h1 =zb2(e.Location).Y / 64,h2=zb2(e.Location).X / 64; if(zb2(e.Location).X!=0) if (bi is Control) { bool s=panduan(new Point(bi.Location.Y/64,bi.Location.X/64),new Point(h1,h2),Convert.ToInt32(bi.Tag)); if (ai[h1,h2]!= 0&&s) chidiao(zb2(e.Location)); if (s) { ai[h1,h2] = Convert.ToInt32(bi.Tag); ai[bo, ao] = 0; (bi as Control).Location = zb2(e.Location); foreach (Control i in Controls) { if (Convert.ToInt32(i.Tag) / 10 == Convert.ToInt32(bi.Tag) / 10) i.Enabled = false; else i.Enabled = true; } } } panjue(); bi = null; } void chidiao(Point p)//吃掉 { for (int i = 0; i < Controls.Count; i++) if (Controls[i].Location == p) { Controls.RemoveAt(i); break; } } bool panduan(Point a,Point b,int i)//a初始位置 b目标位置 i棋子种类 { if (i == 17)//兵 { if (a.Y == b.Y && a.X - b.X ==1) return true; else if (Math.Abs(a.Y - b.Y) == 1 && a.X == b.X&&a.X<5) return true; } if (i == 7)//兵2 { if (a.Y == b.Y && a.X - b.X == -1) return true; else if (Math.Abs(a.Y - b.Y) == 1 && a.X == b.X && a.X > 4) return true; } else if (i == 16||i==6)//炮 走法相同 { int s = panding(a, b); if ((s == 0 && ai[b.X, b.Y] == 0)||(s == 1 && ai[b.X, b.Y] != 0)) return true; } else if(i==15||i==5)//车 走法相同 { int s = panding(a, b); if (s == 0)//比较简单 判定出来没有子就可以了 return true; } else if (i == 14||i==4)//马 走法相同 { if ((Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)) == 5)//判断长度通过 { if (b.X - a.X == 2 && ai[a.X + 1, a.Y] != 0)//判断四个马脚 return false; if (b.X - a.X == -2 && ai[a.X - 1, a.Y] != 0) return false; if (b.Y - a.Y == 2 && ai[a.X , a.Y+1] != 0) return false; if (b.Y - a.Y == -2 && ai[a.X, a.Y-1] != 0) return false; return true; } } else if (i == 13||i==3)//象 稍微改变 { if ((Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)) == 8)//判断长度通过 if ((ai[(a.X + b.X) / 2, (a.Y + b.Y) / 2] == 0)&&i==13?b.X>4:b.X<5)//判断象脚通过还有不能过河 return true; } else if (i == 12||i==2)//士 稍微改变 { if ((Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)) == 2)//判断长度通过 if (b.Y >= 3 && b.Y <= 5) { if (b.X <= 2 && i == 2) return true; if (b.X > 6 && i == 12)//判断不出界 return true; } } else if(i==11||i==1)//将 稍微改变 { if ((Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)) == 1)//判断长度通过 if (b.Y >= 3 && b.Y <= 5) { if (b.X <= 2 && i == 1) return true; if (b.X > 6 && i == 11)//判断不出界 return true; } } else return true; return false; } int panding(Point a,Point b)//用来判断两点之间有多少个棋子 { int s = 0; if (a.X == b.X) { int max = a.Y > b.Y ? a.Y : b.Y; int mix = a.Y + b.Y - max; for (int h = mix + 1; h < max; h++) if (ai[a.X, h] != 0) s++; } if (a.Y == b.Y) { int max = a.X > b.X ? a.X : b.X; int mix = a.X + b.X - max; for (int h = mix + 1; h < max; h++) if (ai[h, a.Y] != 0) s++; } return s; } int panjue()//判断胜负 { int jiang=0; for (int i = 0; i < 10; i++) for (int p = 0; p < 9; p++) if (ai[i, p] == 1 || ai[i, p] == 11) jiang += ai[i, p]; if (jiang < 12) { MessageBox.Show(jiang == 1 ? "红方赢了" : "黑方赢了"); return 0; } if(ci.Location.X==di.Location.X)//判断直线相遇 if(panding(z(ci.Location),z(di.Location))==0) MessageBox.Show(Convert.ToInt32(bi.Tag) > 10 ? "红方赢了" : "黑方赢了"); return 0; } Point z(Point z) { return new Point(z.Y / 64, z.X / 64); } void cl(object sender, EventArgs e) { bi = sender as Control; ao = bi.Location.X / 64; bo = bi.Location.Y / 64; } Point zb(Point p)//坐标 { return new Point(p.X - 30, p.Y - 30); } Point zb2(Point p) { for (int i = 1; i < 11; i++) for (int l = 1; l < 10; l++) if (Math.Abs(p.X - l * 64) < 25 && Math.Abs(p.Y - i * 64) < 25) return zb(new Point(l * 64, i * 64)); return new Point(0, 0); } private void huitu(object sender, PaintEventArgs e) { for (int l = 0; l < 3; l += 2) { for (int i = 1; i < 10; i++)//画棋盘 e.Graphics.DrawLine(Pens.Black, new Point(i * 64, (352 - 64) * l + 64), new Point(i * 64, (352 - 320 - ((i == 1 || i == 9) ? 64 : 0)) * l + 320 + ((i == 1 || i == 9) ? 64 : 0))); for (int i = 1; i < 6; i++) e.Graphics.DrawLine(Pens.Black, new Point(64, (352 - 64 * i) * l + 64 * i), new Point(576, (352 - 64 * i) * l + 64 * i)); e.Graphics.DrawLine(Pens.Black, new Point(256, (352 - 64) * l + 64), new Point(383, (352 - 192) * l + 192)); e.Graphics.DrawLine(Pens.Black, new Point(383, (352 - 64) * l + 64), new Point(256, (352 - 192) * l + 192)); } } } }

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧