社区
C#
帖子详情
如何调用picturebox的paint事件
chrisJiang
2003-08-22 01:28:43
参数(object sender,system.windows.forms.paintEventArgs)应怎样传入?
还有怎样在picturebox的image上放一个图标?
...全文
768
8
打赏
收藏
如何调用picturebox的paint事件
参数(object sender,system.windows.forms.paintEventArgs)应怎样传入? 还有怎样在picturebox的image上放一个图标?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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)
WinCE 电池状态
在WinCE操作系统中,用于读取电池的状态。
调用
方法: //主窗口电池 Battery battery = new Battery(); Battery.State SLast = Battery.State.Normal; //主界面时钟,用户查看电池状态 private void timer2_Tick(object sender, EventArgs e) { ((Timer)sender).Enabled = false; Battery.SystemIdleTimerReset(); SLast = battery.Status; Rectangle Rect = battery.BatteryState; if (battery.Status != SLast) { Invalidate(); } ((Timer)sender).Enabled = true; } //主窗口画画图
事件
private void FrmMain_
Paint
(object sender,
Paint
EventArgs e) { //画出电池形状 Graphics g = e.Graphics; g.DrawImage(
pictureBox
1.Image, 0, 0); Brush brush = new SolidBrush(this.ForeColor); g.DrawString(PubVar.CurrVer, this.Font, brush, 228, 68); // Screen.PrimaryScreen.WorkingArea.Width - g.MeasureString(PubVar.CurrVer, this.Font).Width - 10, 68); Rectangle Rect = battery.BatteryState; //g.DrawString(battery.BatteryPercent.ToString(), this.Font, brush, battery.Left, battery.Top); //正常使用电池状态 if (battery.Status == Battery.State.Normal) { g.DrawPolygon(new Pen(this.ForeColor), battery.BatteryStateRect); g.FillRectangle(brush, battery.BatteryState); } else//充电 电量不足 { g.DrawString(battery.Text, this.Font, brush, battery.Left, battery.Top); } }
C#写的230象棋
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
Paint
EventHandler(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,
Paint
EventArgs 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)); } } } }
c# 用了
picturebox
-
paint
重绘
事件
之后
使用了
picturebox
——
paint
事件
之后,如果我还想在窗体里面使用控件,比如textbox,但无论怎么样也获取不了它的值,为什么呀
不明白,顶起,多试试。比如用focus,重绘窗体,
调用
load
事件
等...先自己乱试下。整不出来把代码发我一起研究.
经常是:没有给它赋值而想从它那里取值当然得不着了我刚学asp.net不久。跟着老师做个小网站。快要结束了。老师说要添加数据维护:备份与恢复,初始化清空功能。我的数据库是access。只用到了插入和查询。请问各位高手:如果
【c#窗体绘图2】
picturebox
的refresh方法和
paint
方法
前文介绍到c#窗体绘图实质上都是在画布上进行工作,本节课原本是要介绍如何创建一个画布以及如何使用,但是转念一想,在这之前,需要先介绍一下
picturebox
的refresh方法以及
paint
方法,uu们才能更加理解后续内容,如果有着急的uu不想看这节也可以直接跳过。
c#
picturebox
刷新_C#
picturebox
画图问题
做一个有类似画图板的界面(部分功能)操作鼠标,在
picturebox
的图片上,画线,且能够保存。当前已经可以画线,但是出了一点问题。按下鼠标左键,拉动鼠标,没有先出现,放开鼠标左键,还是没有线,最后在
picturebox
上随便找个地方点击左键,刚才那个line直线就出来了,为什么会这样啊。。这个是
picturebox
的
paint
事件
,privatevoidpb_Pic_
Paint
(object...
C#
110,534
社区成员
642,575
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章