在重绘子控件时如何让父控件不重绘? 能具体说说嘛?■■■■■ To teach a fish how to swim. ■■■■■ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 具体的你就看看,他的这篇吧希望你能解决!http://www.csdn.net/expert/topic/1074/1074042.xml?temp=.2143061 子控件和父控件:我还是不明白子控件和父控件,能在具体吗?不好意思.■■■■■ To teach a fish how to swim. ■■■■■ 一个PictureBox上面又增加了一个PictureBox 这样行不行:设置一个类 级别的变量:private bool childIsOnPainting 在子控件的OnPaint开始的地方设置为True,结束设置为false.protected override void OnPaint(PaintEventArgs pe){childIsOnPainting = true;....childIsOnPainting = false;}在父控件的OnPaint检测这个值.■■■■■ To teach a fish how to swim. ■■■■■ 不行,父控件的OnPaint如果不绘原来的图形,哪原来的图就全没了,如果绘就会慢,最好的办法就是不让它发生这个事件,有没有办法? 请贴出code来.一部分也可以.■■■■■ To teach a fish how to swim. ■■■■■ //显示控件 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); } } [email protected]■■■■■ To teach a fish how to swim. ■■■■■ 有N个点求一条直线使得所有点到直线的距离和最小的算法 逻辑判断问题 webform 打开局域网共享的文件夹 新手提问,关于VS2008超时问题 给点学习方向 怎么在程序中包含图形统计报表,统计数据需要从数据库中读出。 new Excel.Application()的问题,解决了现结贴 c#的委托和集合哪个相对来说难理解? 请问有谁知道“策略(policy)”功能如果实现? c#里的RichTextBox,如何让它滚动到刚刚写入的文字位置? 菜鸟急!! 请问怎样获取一个menuitem的name?
希望你能解决!
http://www.csdn.net/expert/topic/1074/1074042.xml?temp=.2143061
我还是不明白子控件和父控件,能在具体吗?不好意思.■■■■■ To teach a fish how to swim. ■■■■■
protected override void OnPaint(PaintEventArgs pe)
{
childIsOnPainting = true;
....
childIsOnPainting = false;
}在父控件的OnPaint检测这个值.■■■■■ To teach a fish how to swim. ■■■■■
//显示控件
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);
}
}