画的图最小化后怎么就没有了?

chenzhengxi 2005-07-29 09:03:28
拜托了
我是小鸟,分都问完了
...全文
130 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
YYKXQ 2005-07-30
  • 打赏
  • 举报
回复
是的,最小化后还原,需要重新绘制
Macosx 2005-07-30
  • 打赏
  • 举报
回复
重写OnPaint 把绘制操作写在当中
zhxudong 2005-07-29
  • 打赏
  • 举报
回复
你应该在paint事件中绘制,这样最小化后再还原时,会重新绘制
leonchenjian 2005-07-29
  • 打赏
  • 举报
回复
是不是刷新一下就没了? 我对GUI也不太懂, 下面的是以前的一个作业, 画直线, 希望能对楼主有说帮助

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 画直线_Demo_02101434_陈剑
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox picDrawLine;
private Pen myPen;
private bool drawState;
private Graphics gTemp;
private Graphics g;
private int x, y;
private int xD, yD;

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.picDrawLine = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// picDrawLine
//
this.picDrawLine.BackColor = System.Drawing.Color.White;
this.picDrawLine.Image = ((System.Drawing.Image)(resources.GetObject("picDrawLine.Image")));
this.picDrawLine.Location = new System.Drawing.Point(5, 5);
this.picDrawLine.Name = "picDrawLine";
this.picDrawLine.Size = new System.Drawing.Size(370, 305);
this.picDrawLine.TabIndex = 0;
this.picDrawLine.TabStop = false;
this.picDrawLine.MouseUp += new System.Windows.Forms.MouseEventHandler(this.picDrawLine_MouseUp);
this.picDrawLine.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picDrawLine_MouseMove);
this.picDrawLine.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picDrawLine_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(377, 315);
this.Controls.Add(this.picDrawLine);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "画直线_Demo_02101434_陈剑";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
gTemp = this.picDrawLine.CreateGraphics();
myPen = new Pen(Brushes.Blue, 2);
g = System.Drawing.Graphics.FromImage(this.picDrawLine.Image);
}

private void picDrawLine_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
drawState = true;
xD = x = e.X;
yD = y = e.Y;
}

private void picDrawLine_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (drawState == true)
{
gTemp.DrawLine(new Pen(Brushes.White, 2), x, y, xD, yD);

gTemp.DrawLine(myPen, x, y, e.X, e.Y);
this.Refresh();
xD = e.X;
yD = e.Y;

//this.picDrawLine.Image.Save("paint.bmp");
// this.picDrawLine.BackgroundImage.Save("paint.bmp");
}
}

private void picDrawLine_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (drawState == true)
{
drawState = false;
g.DrawLine(myPen, x, y, e.X, e.Y);
//gTemp.Clear(Color.White);
this.Refresh();
}
}


}
}

110,535

社区成员

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

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

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