C#里面的paint事件如何自己调用
C#里面的paint事件是在窗口改变后自动触发的吧?我想另开一个线程,过多少毫秒就触发paint事件,怎么弄?...
C#里面的paint事件是在窗口改变后自动触发的吧?我想另开一个线程,过多少毫秒就触发paint事件,怎么弄?
展开
2013-08-25
展开全部
不能直接调用paint
如果需要的话. 最简单的似乎可以用Control.Refresh()方法.强制重绘控件
如果需要的话. 最简单的似乎可以用Control.Refresh()方法.强制重绘控件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2016-05-03
展开全部
代码:
=================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ch13_paint
{
/// <summary>
/// Summary description for ScribbleComponent.
/// </summary>
public class ScribbleComponent : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Drawing.Point fStartPoint;
private System.Drawing.Point fEndPoint;
public ScribbleComponent()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
fStartPoint = new System.Drawing.Point();
fEndPoint = new System.Drawing.Point();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// ScribbleComponent
//
this.Name = "ScribbleComponent";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
}
#endregion
private void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
fEndPoint.X = e.X;
fEndPoint.Y = e.Y;
Refresh();
}
private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
fStartPoint.X = e.X;
fStartPoint.Y = e.Y;
}
private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Pen p = new Pen( System.Drawing.Brushes.Blue, 1 );
e.Graphics.DrawLine( p,
fStartPoint, fEndPoint );
}
}
}
===============================================================
******** this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
也就是问,该代码的this.Paint事件是如何被调用的?谁调用的呢?好象dotNET掩盖了一切.
================
附Form1.cs代码,可在vs.net中运行鼠标划线.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ch13_paint
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private ch13_paint.ScribbleComponent comp;
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 );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comp = new ch13_paint.ScribbleComponent();
this.comp.Location = new System.Drawing.Point(0,0);
this.comp.Name = "component1";
this.comp.Size = new System.Drawing.Size(300,300);
this.comp.TabIndex = 1;
this.components = new System.ComponentModel.Container();
this.Controls.AddRange(new System.Windows.Forms.Control[]
{
this.comp
});
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
=================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ch13_paint
{
/// <summary>
/// Summary description for ScribbleComponent.
/// </summary>
public class ScribbleComponent : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Drawing.Point fStartPoint;
private System.Drawing.Point fEndPoint;
public ScribbleComponent()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
fStartPoint = new System.Drawing.Point();
fEndPoint = new System.Drawing.Point();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// ScribbleComponent
//
this.Name = "ScribbleComponent";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
}
#endregion
private void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
fEndPoint.X = e.X;
fEndPoint.Y = e.Y;
Refresh();
}
private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
fStartPoint.X = e.X;
fStartPoint.Y = e.Y;
}
private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Pen p = new Pen( System.Drawing.Brushes.Blue, 1 );
e.Graphics.DrawLine( p,
fStartPoint, fEndPoint );
}
}
}
===============================================================
******** this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
也就是问,该代码的this.Paint事件是如何被调用的?谁调用的呢?好象dotNET掩盖了一切.
================
附Form1.cs代码,可在vs.net中运行鼠标划线.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ch13_paint
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private ch13_paint.ScribbleComponent comp;
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 );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comp = new ch13_paint.ScribbleComponent();
this.comp.Location = new System.Drawing.Point(0,0);
this.comp.Name = "component1";
this.comp.Size = new System.Drawing.Size(300,300);
this.comp.TabIndex = 1;
this.components = new System.ComponentModel.Container();
this.Controls.AddRange(new System.Windows.Forms.Control[]
{
this.comp
});
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询