当前位置:编程学习 > C#/ASP.NET >>

新手求助,知道两点坐标,画一条直线连接两点

各位帮帮忙,刚刚学C# --------------------编程问答-------------------- Graphics g = this.CreateGraphics();
            g.Clear(Color.SeaShell);
            Brush b = new SolidBrush(Color.Blue);

            Pen p = new Pen(b,11);
            p.Width = 12;
            g.DrawLine(p, 100, 300, 100, 400);
--------------------编程问答-------------------- GDI画图  有个方法 百度吧 --------------------编程问答-------------------- 在OnPaint中 e.Graphics.DrawLine --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        int startX;     //获取鼠标起始点的X坐标
        int startY;    //获取鼠标起始点的Y坐标
        Graphics g;  //定义Graphics对象实例


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            this.BackColor = Color.Snow;         //设置窗体背景颜色

        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            g = this.CreateGraphics();               //创建Graphics对象实例
            Pen p = new Pen(Color.Red, 4);      //设置画笔颜色和宽度
            g.DrawLine(p, startX, startY, e.X, e.Y);  //绘制直线
           

        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            startX = e.X;       //为变量赋值
            startY = e.Y;

        }
    }
}

啊哈和
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,