在重绘子控件时如何让父控件不重绘?

SHQcloud 2002-10-05 08:25:27
在重绘子控件时如何让父控件不重绘?
...全文
268 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
SHQcloud 2002-10-05
  • 打赏
  • 举报
回复
班门兄是青岛的吗?我也是
SHQcloud 2002-10-05
  • 打赏
  • 举报
回复
班门兄帮我想想办法,我发过去了
TheAres 2002-10-05
  • 打赏
  • 举报
回复
cxli@qingdaonews.com

■■■■■ To teach a fish how to swim. ■■■■■
SHQcloud 2002-10-05
  • 打赏
  • 举报
回复
太多了
SHQcloud 2002-10-05
  • 打赏
  • 举报
回复

//显示控件
private System.Windows.Forms.PictureBox showG = new System.Windows.Forms.PictureBox();
public System.Windows.Forms.PictureBox ShowG
{
set
{
showG = value;
}
get
{
return this;
}
}
//临时画图控件
private System.Windows.Forms.PictureBox tempG = new System.Windows.Forms.PictureBox();
public System.Windows.Forms.PictureBox TempG
{
set
{
tempG = value;
}
get
{
return tempG;
}
}
//临时移动控件
private System.Windows.Forms.PictureBox moveG = new System.Windows.Forms.PictureBox();

private SimpleSVG.PictureCavas.PicturePanel picturePanel;
public SimpleSVG.PictureCavas.PicturePanel PicturePanel
{
set
{
picturePanel = value;
this.init();
}
get
{
return picturePanel;
}
}

private Size Margin;
public Size margin
{
set
{
Margin = value;
}
get
{
return Margin;
}
}
public Show()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void init()
{
this.tempG.BackColor = Color.Transparent;
// this.tempG.BackColor = Color.Bisque;

this.tempG.SetBounds(0,0,this.PicturePanel.Width,this.PicturePanel.Height);
this.tempG.Visible = false;
this.tempG.Paint += new System.Windows.Forms.PaintEventHandler(this.tempG_Paint);

this.moveG.BackColor = Color.Transparent;

this.moveG.SetBounds(0,0,this.PicturePanel.Width,this.PicturePanel.Height);
this.moveG.Visible = false;

this.SetBounds(0,0,this.PicturePanel.Width,this.PicturePanel.Height);
this.ShowG.BackColor = Color.Transparent;

this.PicturePanel.Controls.Add(this);
this.Margin = this.picturePanel.Margin;
this.ShowG.Controls.Add(this.tempG);
this.tempG.BringToFront();
this.ShowG.Controls.Add(this.moveG);

bmp = new Bitmap(this.PicturePanel.Width,this.PicturePanel.Height);

Graphics pg = Graphics.FromImage(bmp);
pg.Clear(Color.White);

// this.Image =
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ShowG_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ShowG_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ShowG_MouseMove);
}
private void ShowG_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{

if(pait != null)
{
this.pait.AddPicture();
}
MouseDownBool = false;





System.Drawing.Graphics g = this.CreateGraphics();
// if(bmp == null)
// this.DrawBmp();
// g.DrawImage(bmp,0,0);
////
g.DrawEllipse(Pens.Blue,200,200,200,200);
//
}

private void ShowG_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.MouseDownBool = true;
OldPoint = new Point(e.X,e.Y);

switch(this.PicturePanel.BarContainerAttrib.Operation)
{
case "圆形":
pait = new Paiting.Circle();
pait.ShowAttrib = this;
break;

case "椭圆形":
pait = new Paiting.DrawEllips();
pait.ShowAttrib = this;

break;
case "距形":
pait = new Paiting.DrawRectanle();
this.
pait.ShowAttrib = this;

break;
case "多边形":
pait = new Paiting.PolyLine();
pait.ShowAttrib = this;

break;

case "移动缩放":
pait = new Paiting.MakeOverAttrib();
pait.ShowAttrib = this;
this.showG.Refresh();
pait.Select(e.X, e.Y);

break;
case "直线":
this.TempG.Visible = true;
pait = new Paiting.DrawLine();
pait.ShowAttrib = this;
break;
case "旋转":
pait = new Paiting.rotate();
pait.ShowAttrib = this;
this.showG.Refresh();
pait.Select(e.X, e.Y);
break;
case "空":
break;
// this.showG.PreProcessMessage(new System.Windows.Forms.Message msg)
}
}

private void ShowG_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.PointMouseMove = new Point(e.X,e.Y);

if(MouseDownBool)
{
if(pait != null)
pait.Refurbish();
}
else
{
if(this.EnableGraphics != -1)
pait.ModifyCursor(e.X,e.Y);

}

}

private void tempG_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
this.pait.tempG_Paint(e);

}

public SF.GraphPath SumPoint(int x, int y)
{
Point point = new Point(x,y);
for(int i=0;i<this.picturePanel.MyList.Count;i++)
{
//区域设为距形边界
System.Drawing.Drawing2D.GraphicsPath gPath = ((SVG.GraphPath)this.picturePanel.MyList[i]).GPath;

g = this.ShowG.CreateGraphics();

if(gPath.IsVisible(point))
{
g.DrawPath(Pens.Red,gPath);
EnableGraphics = i;
return (SVG.GraphPath)this.picturePanel.MyList[i];
}
}
return null;
}

public void SmallRactanle(int x,int y)
{
Point point = new Point(x,y);
for(int i=0;i<this.picturePanel.MyList.Count;i++)
{
//区域设为距形边界
System.Drawing.Drawing2D.GraphicsPath gPath = ((SVG.GraphPath)this.picturePanel.MyList[i]).GPath;

g = this.ShowG.CreateGraphics();

if(gPath.IsVisible(point))
{
if(this.enableGraphics != -1)
{
//区域设为距形边界
System.Drawing.RectangleF rect = ((SVG.GraphPath)this.picturePanel.MyList[this.EnableGraphics]).GetBounds();
g = this.showG.CreateGraphics();
//角点
g.DrawRectangle(Pens.Black, rect.Left-6, rect.Top-6,6,6);//1
g.DrawRectangle(Pens.Black, rect.Left-6, rect.Top+rect.Height, 6, 6);//2
g.DrawRectangle(Pens.Black, rect.Left+rect.Width, rect.Top-6, 6, 6);//3
g.DrawRectangle(Pens.Black, rect.Left+rect.Width, rect.Top+rect.Height, 6, 6);//4

//边点
g.DrawRectangle(Pens.Black, rect.Left-6, rect.Top+rect.Height/2-3,6,6);
g.DrawRectangle(Pens.Black, rect.Left+rect.Width/2-3, rect.Top+rect.Height, 6, 6);
g.DrawRectangle(Pens.Black, rect.Left+rect.Width/2-3, rect.Top-6, 6, 6);
g.DrawRectangle(Pens.Black, rect.Left+rect.Width, rect.Top+rect.Height/2-3, 6, 6);
}

}
}
}
public void ShowImage()
{
if(this.bmp == null)
this.DrawBmp();
}

/// <summary>
/// 绘制图形对象
/// </summary>
public void DrawBmp()
{
// int width = (int)((this.margin.Width * 2 + this.PicturePanel.ViewSize.Width)*this.PicturePanel.ScaleUnit );
// int height = (int)((this.margin.Height * 2 + this.PicturePanel.ViewSize.Height)*this.PicturePanel.ScaleUnit);

int width = this.PicturePanel.Width;
int height = this.PicturePanel.Height;

// if(bmp != null)
// bmp.di.Dispose();
// bmp = new Bitmap(width,height);

Graphics pg = Graphics.FromImage(bmp);
pg.Clear(Color.White);
// pg.DrawRectangle(new Pen(Brushes.Black,1),margin.Width ,margin.Height ,this.PicturePanel.ViewSize.Width ,this.PicturePanel.ViewSize.Height );
// pg.FillRectangle(Brushes.White,(margin.Width+1) ,(margin.Height+1) ,(this.PicturePanel.ViewSize.Width-2),(this.PicturePanel.ViewSize.Height-2) );
SVG.Graph mypath;

for(int i=0;i<this.PicturePanel.MyList.Count;i++)
{
mypath = (SVG.Graph)PicturePanel.MyList[i];
// Matrix mymatrix = new Matrix();
// mymatrix.Translate(margin.Width,margin.Height);
// if(this.PicturePanel.ScaleUnit != 1)
// mymatrix.Scale(this.PicturePanel.ScaleUnit,this.PicturePanel.ScaleUnit);
// pg.Transform = mymatrix;
mypath.Draw(pg);
}
}
protected override void OnPaint(PaintEventArgs e)
{
if(bmp == null)
this.DrawBmp();
e.Graphics.DrawImage(bmp,0,0);
}
}
TheAres 2002-10-05
  • 打赏
  • 举报
回复
请贴出code来.一部分也可以.

■■■■■ To teach a fish how to swim. ■■■■■
yarshray 2002-10-05
  • 打赏
  • 举报
回复
是啊,所以我才要你开篇贴问这个问题啊!
SHQcloud 2002-10-05
  • 打赏
  • 举报
回复
不行,父控件的OnPaint如果不绘原来的图形,哪原来的图就全没了,如果绘就会慢,最好的办法就是不让它发生这个事件,有没有办法?
yarshray 2002-10-05
  • 打赏
  • 举报
回复
VC里的作用是复制!我觉得和你说的有点象
就拿来套,不知道可不可以!
TheAres 2002-10-05
  • 打赏
  • 举报
回复
这样行不行:

设置一个类 级别的变量:

private bool childIsOnPainting

在子控件的OnPaint开始的地方设置为True,结束设置为false.
protected override void OnPaint(PaintEventArgs pe)
{
childIsOnPainting = true;
....
childIsOnPainting = false;
}

在父控件的OnPaint检测这个值.



■■■■■ To teach a fish how to swim. ■■■■■
SHQcloud 2002-10-05
  • 打赏
  • 举报
回复
bitblt 是什么?
yarshray 2002-10-05
  • 打赏
  • 举报
回复
bitblt
IamHacker 2002-10-05
  • 打赏
  • 举报
回复
一个PictureBox上面又增加了一个PictureBox
TheAres 2002-10-05
  • 打赏
  • 举报
回复
子控件和父控件:
我还是不明白子控件和父控件,能在具体吗?不好意思.

■■■■■ To teach a fish how to swim. ■■■■■
IamHacker 2002-10-05
  • 打赏
  • 举报
回复
也就是说在画图形时,怎么样显示图形效果,又能保证性能?
IamHacker 2002-10-05
  • 打赏
  • 举报
回复
在子控件上画图或移动图时需要重绘,父控件也会跟着重绘,这样重绘操作会很慢,子控件是透明的。能不能让代父控件不重绘,或有其它更好的方法?
请班门兄多多指导
yarshray 2002-10-05
  • 打赏
  • 举报
回复
具体的你就看看,他的这篇吧
希望你能解决!
http://www.csdn.net/expert/topic/1074/1074042.xml?temp=.2143061
TheAres 2002-10-05
  • 打赏
  • 举报
回复
能具体说说嘛?

■■■■■ To teach a fish how to swim. ■■■■■

110,533

社区成员

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

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

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