当前位置: 代码迷 >> .NET组件控件 >> 关于c#画线解决方案
  详细解决方案

关于c#画线解决方案

热度:1662   发布时间:2013-02-25 00:00:00.0
关于c#画线

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;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        private PointF current;
        private PointF movepf;

        public Form1()
        {
            InitializeComponent();
        }


        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {

            current = e.Location;       
          
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            movepf = e.Location;
            Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {

            Bitmap mp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            Pen pen = new Pen(Color.Blue);

            SolidBrush drawBrush = new SolidBrush(Color.Black);
            using (Graphics g = Graphics.FromImage(mp))
            {

              g.DrawImage(mp, pictureBox1.ClientRectangle.X, pictureBox1.ClientRectangle.Y);
                g.DrawLine(pen, current, movepf);

                PointF pt1 = new PointF();

                pt1.X = (current.X + movepf.X) / 2;
                pt1.Y = (current.Y + movepf.Y) / 2;


                g.DrawString("12345", this.Font, drawBrush, pt1);

                using (Graphics gg = this.CreateGraphics())
                {
  相关解决方案