如何在WinForm中产生斜线并能接收鼠标等事件
需要在WinForm中产生斜线,试过在Form的OnPaint事件中通过Graphic产生,但是这种方法产生的斜线不能接收鼠标等相关事件,于是放弃了这种方法。
现在想通过旋转Label或GroupBox来实现,却找不到旋转.NET控件的方法,请大家指点迷津。
[解决办法]
public Line()
{
}
private System.ComponentModel.Container components = null;
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private LineDirection direction = LineDirection.Left;
public LineDirection Direction
{
get
{
return this.direction;
}
set
{
this.direction=value;
this.Refresh();
}
}
[System.ComponentModel.Browsable(true)]
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if(this.direction==LineDirection.Left)
{
e.Graphics.DrawLine(new Pen(this.ForeColor),0,0,this.Width ,this.Height);
}
else
{
e.Graphics.DrawLine(new Pen(this.ForeColor),0,this.Height,this.Width,0);
}
}
public enum LineDirection
{
Left,
Right
}