用GDI+划直线
来源:互联网 发布:kitti数据集介绍 编辑:程序博客网 时间:2024/03/29 19:01
下面是代码,很容易看懂的,没有必要进行解释了吧。:)
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
public class Line : System.Windows.Forms.UserControl
...{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Line()
...{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.FixedHeight | ControlStyles.FixedWidth | ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.Selectable, false);
TabStop = false;
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
...{
if (disposing)
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose(disposing);
}
Component Designer generated code#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()
...{
//
// Line
//
this.Name = "Line";
this.Size = new System.Drawing.Size(140, 140);
}
#endregion
protected override void OnPaint(PaintEventArgs e)
...{
base.OnPaint(e);
int x1, x2, x3, x4, y1, y2, y3, y4;
if (LineStyle == LineStyle.Horizontal)
...{
x1 = 0;
y1 = 0;
x2 = ClientRectangle.Width;
y2 = 0;
x3 = 0;
y3 = 1;
x4 = ClientRectangle.Width;
y4 = 1;
}
else //if (LineStyle == LineStyle.Vertical)
...{
x1 = 0;
y1 = 0;
x2 = 0;
y2 = ClientRectangle.Height;
x3 = 1;
y3 = 0;
x4 = 1;
y4 = ClientRectangle.Height;
}
using (Pen p = new Pen(m_FirstColor, 1))
...{
p.DashStyle = mDashStyle;
e.Graphics.DrawLine(p, x1, y1, x2, y2);
}
using (Pen p = new Pen(m_SecondColor, 1))
...{
p.DashStyle = mDashStyle;
e.Graphics.DrawLine(p, x3, y3, x4, y4);
}
}
private System.Drawing.Drawing2D.DashStyle mDashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
public System.Drawing.Drawing2D.DashStyle DashStyle
...{
get ...{ return mDashStyle; }
set ...{ mDashStyle = value; Invalidate(); }
}
private Color m_FirstColor = Color.FromKnownColor(KnownColor.ControlDark);
public Color FirstColor
...{
get ...{ return m_FirstColor; }
set ...{ m_FirstColor = value; Invalidate(); }
}
private Color m_SecondColor = Color.FromKnownColor(KnownColor.ControlLightLight);
public Color SecondColor
...{
get ...{ return m_SecondColor; }
set ...{ m_SecondColor = value; Invalidate(); }
}
private LineStyle m_LineStyle = LineStyle.Horizontal;
public LineStyle LineStyle
...{
get ...{ return m_LineStyle; }
set
...{
m_LineStyle = value;
Size = new Size(Height, Width);
Invalidate();
}
}
protected override void OnSizeChanged(EventArgs e)
...{
base.OnSizeChanged(e);
ChangeControlSize();
}
private void ChangeControlSize()
...{
if (LineStyle == LineStyle.Horizontal)
Height = 2;
else if (LineStyle == LineStyle.Vertical)
Width = 2;
}
}
public enum LineStyle
...{
Horizontal = 1,
Vertical = 2
}
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
public class Line : System.Windows.Forms.UserControl
...{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Line()
...{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.FixedHeight | ControlStyles.FixedWidth | ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.Selectable, false);
TabStop = false;
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
...{
if (disposing)
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose(disposing);
}
Component Designer generated code#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()
...{
//
// Line
//
this.Name = "Line";
this.Size = new System.Drawing.Size(140, 140);
}
#endregion
protected override void OnPaint(PaintEventArgs e)
...{
base.OnPaint(e);
int x1, x2, x3, x4, y1, y2, y3, y4;
if (LineStyle == LineStyle.Horizontal)
...{
x1 = 0;
y1 = 0;
x2 = ClientRectangle.Width;
y2 = 0;
x3 = 0;
y3 = 1;
x4 = ClientRectangle.Width;
y4 = 1;
}
else //if (LineStyle == LineStyle.Vertical)
...{
x1 = 0;
y1 = 0;
x2 = 0;
y2 = ClientRectangle.Height;
x3 = 1;
y3 = 0;
x4 = 1;
y4 = ClientRectangle.Height;
}
using (Pen p = new Pen(m_FirstColor, 1))
...{
p.DashStyle = mDashStyle;
e.Graphics.DrawLine(p, x1, y1, x2, y2);
}
using (Pen p = new Pen(m_SecondColor, 1))
...{
p.DashStyle = mDashStyle;
e.Graphics.DrawLine(p, x3, y3, x4, y4);
}
}
private System.Drawing.Drawing2D.DashStyle mDashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
public System.Drawing.Drawing2D.DashStyle DashStyle
...{
get ...{ return mDashStyle; }
set ...{ mDashStyle = value; Invalidate(); }
}
private Color m_FirstColor = Color.FromKnownColor(KnownColor.ControlDark);
public Color FirstColor
...{
get ...{ return m_FirstColor; }
set ...{ m_FirstColor = value; Invalidate(); }
}
private Color m_SecondColor = Color.FromKnownColor(KnownColor.ControlLightLight);
public Color SecondColor
...{
get ...{ return m_SecondColor; }
set ...{ m_SecondColor = value; Invalidate(); }
}
private LineStyle m_LineStyle = LineStyle.Horizontal;
public LineStyle LineStyle
...{
get ...{ return m_LineStyle; }
set
...{
m_LineStyle = value;
Size = new Size(Height, Width);
Invalidate();
}
}
protected override void OnSizeChanged(EventArgs e)
...{
base.OnSizeChanged(e);
ChangeControlSize();
}
private void ChangeControlSize()
...{
if (LineStyle == LineStyle.Horizontal)
Height = 2;
else if (LineStyle == LineStyle.Vertical)
Width = 2;
}
}
public enum LineStyle
...{
Horizontal = 1,
Vertical = 2
}
- 用GDI+划直线
- lineto划直线
- 使用GDI绘制直线
- 使用GDI绘制直线
- GDI+画平滑直线
- GDI+ 动态绘制直线
- gdi+(1) 画直线
- GDI/GDI+ 在图像上画直线
- VB6.0 【GDI+ 画直线】
- 在vc2010内使用GDI绘制直线
- (C#) GDI+简单绘图画直线
- C++ GDI+简单示例(绘制直线)
- 使用GDI在桌面画直线
- 用小刀划开
- mcf中用gdi 画直线、画文字等
- C# 利用GDI+画终点为箭头的直线
- GDI+学习记录(7)- 直线连接点 LineJoin
- 实验二 直线DDA生成算法的GDI实现
- XML Schema 心得
- 个人理财规划五步曲
- 关于自动播放/还原隐藏文件失效/U盘病毒的说明
- dhcombobox version 3.0
- Linux下FTP服务器vsftp配置
- 用GDI+划直线
- 实现支持逻辑搜索/单词搜索/词组搜索+支持OR/AND关键字的VBS CLASS
- 不经保存,直接读取上传文件的内容
- 将Access数据库移植到Microsoft SQL Server 7.0
- Schema Structure小结
- 每日一句2006-12-25
- 用ASP自动生成SQL数据库的安装源程序
- 一个简单的数据库持久方案
- 避免asp的SQL的执行效率低