不是这样的,是在 Paint 事件里画直线。
当类中有关划线的属性发生了变化时,调用 this.Refresh() 方法,通知控件按照属性值重绘就可以了。
当类中有关划线的属性发生了变化时,调用 this.Refresh() 方法,通知控件按照属性值重绘就可以了。
解决方案 »
- 求正则,刚需求没说清楚。。。
- 怎样可以让ToolTip直接显示 而不用将鼠标放上去
- 如何获取Datagridview中记录的值?
- 如何在主程序中等待新建的线程执行完毕后再继续运行?
- publickeytoken可以代替公钥?
- 如何存取Text类型的值啊?
- windows服务 SystemWatcher监视图片文件(Image.FromFile)弹出异常OutOfMemoryException
- C# 读取EXCEL时跳出是否更新窗口怎么屏蔽掉
- 思归大哥:请帮我看看这段代码.谢谢!
- ?如何将二进制的 值写如注册表?
- 请教一个SendMail在Linux下的问题
- 请帮忙看看这段代码?? 是什么原因引起这个错误??
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace GraphicsTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1"; }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </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 GraphicsTest
{
/// <summary>
/// MyLine 的摘要说明。
/// </summary>
public class MyLine : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null; public MyLine()
{
this.Name = "MyLine";
this.Size = new System.Drawing.Size(48, 48);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.MyLine_Paint);
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void MyLine_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine( new Pen(Color.Blue),new Point(0,0),new Point(100,100));
}
}
}
第二那个class MyLine 对象继承System.Windows.Forms.UserControl的话,就无所谓FORM1了,因为USERCONTROL本身就可以随便放啊,
我要的class MyLine就是个CLASS,不继承任何对象,只是通过里面的属性方法事件来达到我说的目的,行否哩?
{
public PaintBorard paintBoard;
public ShapeCollection shapes;
public PaintControler()
{ }
public void Connect()
{
// paintBoard.MouseDown += ...;
paintBoard.Paint += new PaintEventHandler(OnPaint); }
public void DrawFocus(Graphics g)
{ }
public void OnPaint(object obj,PaintEventArgs e)
{
foreach(Shape s in shapes)
{
s.Paint(e.Graphics);
}
}
}
public class Line : Shape
{
}
public class ShapeCollection : IList
{
}