如何让图片框自动重画?先谢了 where are you drawing the rectangle? draw it in OnPaint 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 重载OnPaint事件调用Invalidate();触发OnPaint事件 谢了。那我应在何时重载呢?比如我在Form1中画了一个长方形,点击Form1的一个按钮,弹出Form2。当Form2从Form1上经过时,长方形就不见了。这种情况我应在何时重载Form1的Onpaint事件呢? 直接重载OnPaint,或直接在OnPaint中设计你想画的图形,然后在想改变图形的时候,Invalidata()如果你在Form里和PictureBox里都各自画了图形,则要重载两个的OnPaint() OnPaint中才能重画要不你 试试画在pictureBox控件中,Delphi中如果画在里面是可以保存而不必重画的! To heineken(Heineken) 和 wenzm(疯之驴) 非常感谢你们的回答。可现在关键是何时重载呢? namespace 推箱子的实验{ /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.IContainer components; private Bitmap myend=new Bitmap("end.jpg"); private Bitmap mystop=new Bitmap("stop.jpg"); private Bitmap mybox=new Bitmap("box.jpg"); private Bitmap mywin=new Bitmap("115.jpg"); private Bitmap myback=new Bitmap("back.jpg"); Process ss=new Process(); public static int[,] map=new int[100,100]; public static int mapNO; private Load Load1; public static int manX,manY; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox pictureBox3; private Bitmap myman=new Bitmap("man.jpg"); protected override void OnPaint(PaintEventArgs e) { Pen mypen=new Pen(Color.Red,3); Graphics mygr=e.Graphics; if (ss.isFinished==false) { draw(); base.OnPaint(e); } else { mygr.Clea(System.Drawing.Color.Black); mygr.DrawImage(mywin,0,0); } } public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }这是我写的程序的一段 这里面就有OnPaint的重载,看懂了吗?不行的话,我可以给你整个源代码,不过现在应该明白了 重载就是重载了!真么还有什么时候?你重载了onpaint每次你的图片需要刷新的时候,系统会调用onpaint,你就有机会重画了!------------------------------我是一只小小鸟欢迎交流!尽快结帖哦!我是CSDN的菜鸟,等着你的分呢!MSN&Mail: [email protected]0A 非常感谢 wftree(wftree) 以及其他的各位高手,在窗体上画图已经实现了我的想法。在图片框上我也实现了,再次感谢大家。现在开始散分了。呵呵 + e.Message, LogLevel.L5_FAIL 怎么理解 Winform TextBox 如何获取焦点 高分求助 循环dll文件中的每个类 实例并调用其方法 怎么找到c# 程序里连接ORACLE的用户名和密码 TabControl容器的问题! 有关在DataGrid中使用DropDownlist的问题,各位高手帮帮忙--很急用的,多谢了 有没有静态结构 晕,刚傻了。这么简单的枚举问题竟然想不出。 工作流管理系统解决方案. 为什么编译不能通过??!! 帮助解决二个字符串问题 一个关于多线程的问题
调用Invalidate();触发OnPaint事件
比如我在Form1中画了一个长方形,点击Form1的一个按钮,弹
出Form2。当Form2从Form1上经过时,长方形就不见了。这种情况
我应在何时重载Form1的Onpaint事件呢?
如果你在Form里和PictureBox里都各自画了图形,则要重载两个的OnPaint()
要不你 试试画在pictureBox控件中,Delphi中如果画在里面是可以保存而不必重画的!
非常感谢你们的回答。可现在关键是何时重载呢?
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private Bitmap myend=new Bitmap("end.jpg");
private Bitmap mystop=new Bitmap("stop.jpg");
private Bitmap mybox=new Bitmap("box.jpg");
private Bitmap mywin=new Bitmap("115.jpg");
private Bitmap myback=new Bitmap("back.jpg");
Process ss=new Process();
public static int[,] map=new int[100,100];
public static int mapNO;
private Load Load1;
public static int manX,manY;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox3;
private Bitmap myman=new Bitmap("man.jpg");
protected override void OnPaint(PaintEventArgs e)
{
Pen mypen=new Pen(Color.Red,3);
Graphics mygr=e.Graphics;
if (ss.isFinished==false)
{
draw();
base.OnPaint(e);
}
else
{
mygr.Clea(System.Drawing.Color.Black);
mygr.DrawImage(mywin,0,0);
}
} public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}这是我写的程序的一段 这里面就有OnPaint的重载,看懂了吗?
不行的话,我可以给你整个源代码,不过现在应该明白了
------------------------------
我是一只小小鸟
欢迎交流!
尽快结帖哦!我是CSDN的菜鸟,等着你的分呢!
MSN&Mail: [email protected]
0A
在窗体上画图已经实现了我的想法。
在图片框上我也实现了,再次感谢大家。现在开始散分了。呵呵