本文整理汇总了C#中System.Drawing.Graphics.DrawLine方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.DrawLine方法的具体用法?C# Graphics.DrawLine怎么用?C# Graphics.DrawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.DrawLine方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawLinePointF
public void DrawLinePointF(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create points that define line.
PointF point1 = new PointF(100.0F, 100.0F);
PointF point2 = new PointF(500.0F, 100.0F);
// Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2);
}
示例2: DrawLineInt
public void DrawLineInt(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create coordinates of points that define line.
int x1 = 100;
int y1 = 100;
int x2 = 500;
int y2 = 100;
// Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
示例3: Graphics.DrawLine(Pen,Point point1, Point point2)
//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class frmScribble : System.Windows.Forms.Form {
private System.ComponentModel.Container components = null;
private bool mouseDown = false;
private Point lastPoint = Point.Empty;
private string color = "black";
private Graphics g;
private Pen p;
public frmScribble() {
g = CreateGraphics();
p = new Pen(Color.FromName(color));
}
protected override void OnMouseDown(MouseEventArgs e) {
mouseDown = true;
if (e.Button == MouseButtons.Right) {
ContextMenu m = new ContextMenu();
m.MenuItems.Add(0, new MenuItem("black", new EventHandler(RightMouseButton_Click)));
m.MenuItems.Add(1, new MenuItem("white", new EventHandler(RightMouseButton_Click)));
m.MenuItems.Add(2, new MenuItem("red", new EventHandler(RightMouseButton_Click)));
m.MenuItems.Add(3, new MenuItem("green", new EventHandler(RightMouseButton_Click)));
m.MenuItems.Add(4, new MenuItem("blue", new EventHandler(RightMouseButton_Click)));
m.Show(this, new Point(e.X, e.Y));
}
}
protected void RightMouseButton_Click(object sender, EventArgs e) {
color = ((MenuItem)sender).Text;
p = new Pen(Color.FromName(color));
}
protected override void OnMouseUp(MouseEventArgs e) {
mouseDown = false;
}
protected override void OnMouseMove(MouseEventArgs e) {
if (lastPoint.Equals(Point.Empty)) lastPoint = new Point(e.X, e.Y);
if (mouseDown) {
Point pMousePos = new Point(e.X, e.Y);
g.DrawLine(p, pMousePos, lastPoint);
}
lastPoint = new Point(e.X, e.Y);
}
[STAThread]
static void Main() {
Application.Run(new frmScribble());
}
}
示例4: DrawLineFloat
public void DrawLineFloat(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create coordinates of points that define line.
float x1 = 100.0F;
float y1 = 100.0F;
float x2 = 500.0F;
float y2 = 100.0F;
// Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
示例5: DrawLinePoint
public void DrawLinePoint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create points that define line.
Point point1 = new Point(100, 100);
Point point2 = new Point(500, 100);
// Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2);
}
示例6: Graphics.DrawLine(Pen p, int x0,int y0, int x1, int y1)
//引入命名空间
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Text = "";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Pen p = new Pen(Color.Black);
g.DrawLine(p, 0, 0, 100, 100);
p.Dispose();
}
private void Form1_Resize(object sender, System.EventArgs e)
{
Invalidate();
}
}