当前位置: 首页>>代码示例>>C#>>正文


C# Graphics.DrawLine方法代码示例

本文整理汇总了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);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:13,代码来源:Graphics.DrawLine

示例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);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:15,代码来源:Graphics.DrawLine

示例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());
    }
}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:57,代码来源:Graphics.DrawLine

示例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);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:15,代码来源:Graphics.DrawLine

示例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);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:13,代码来源:Graphics.DrawLine

示例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();
    }
  }
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:45,代码来源:Graphics.DrawLine


注:本文中的System.Drawing.Graphics.DrawLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。