• 大小: 45KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-11-18
  • 语言: C#
  • 标签: C#  GDI+绘图  动态  

资源简介

这个程序是用C#编写的,用GDI+绘制一个动态的二维平面坐标,用户能通过输入X轴和Y轴的最小刻度来控制平面坐标的大小,并通过产生一个随机数波形,来动态显示平面坐标。 希望这个小程序能对学习使用C#GDI+绘图的朋友带来帮助。

资源截图

代码片段和文件信息

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

namespace DrawPlane
{
    class Draw
    {
        public Bitmap mybitmap;//用于双缓冲的位图,和画布等大
        Random rm = new Random();

        public void DrawLineS(Color color float Xmark float Ymark PictureBox picboxPoint[] ptlist)
        {
            mybitmap = new Bitmap(picbox.Width picbox.Height);//设定位图大小
            Graphics doublebufferg = Graphics.FromImage(mybitmap);//从位图上获取画布
            doublebufferg.Clear(Color.White);//用背景色刷新

            //pictureBox1填充为白色,便于显示图像 500*300
            Rectangle rect = new Rectangle(0 0 picbox.Width picbox.Height);
            doublebufferg.FillRectangle(new SolidBrush(Color.White) rect);

            //画X轴和Y轴
            DrawXY(ref doublebufferg picbox);
            //X轴上的刻度
            SetXAxis(ref doublebufferg picbox Xmark);
            //Y轴上的刻度
            SetYAxis(ref doublebufferg picbox Ymark);

            //绘制实时随机曲线
            Point temp = new Point();
            for (int j = 0; j < picbox.Width / 5-1; j++)
            {
                temp = ptlist[j + 1];
                ptlist[j] = new Point(temp.X - 5 temp.Y);
            }
            Point lastpt = new Point();
            lastpt.X = picbox.Width;
            lastpt.Y = rm.Next(DateTime.Now.Millisecond) % picbox.Height;
            ptlist[picbox.Width / 5 -1] = lastpt;
            doublebufferg.DrawLines(new Pen(Color.Red2) ptlist);

            //将缓冲中的位图绘制到窗体上
            Graphics g1 = picbox.CreateGraphics();//创建 PictureBox窗体的画布

            g1.Clear(Color.White);
            g1.DrawImage(mybitmap 0 0);
        }

        //画X轴和Y轴的基本部分,包括间隔、方向箭头
        public void DrawXY(ref Graphics g PictureBox picbox)
        {
            Pen pen = new Pen(Color.Green 2);//画笔
            SolidBrush sb = new SolidBrush(Color.Green);//画刷

            //X轴上的方向箭头,实际上是绘制了一个三角形
            Point[] xpts = new Point[3]{
                new Point(picbox.Width-35picbox.Height-32)
                new Point(picbox.Width-35picbox.Height-28)
                new Point(picbox.Width-30picbox.Height-30)
                                       };
            g.DrawLine(pen 30 picbox.Height - 30 picbox.Width - 30 picbox.Height - 30);//绘制X坐标轴
            g.DrawPolygon(penxpts);//绘制X轴的方向箭头
            g.DrawString(“X轴“ new Font(“宋体“ 9) sb picbox.Width - 25 picbox.Height - 35);//标注X轴

            //Y轴的箭头,实际上是绘制了一个三角形
            Point[] ypts = new Point[3]{
                  new Point(2835)
                  new Point(3030)
                  new Point(3235)   };
            g.DrawLine(pen 30 picbox.Height - 30 30 30);
            g.DrawPolygon(pen ypts);
            g.DrawString(“Y轴“ new Font(“宋体“ 9) sb 20 10);
        }
        //绘制平行Y轴的竖线,相当于X轴上的刻度
        public void SetXAxis(ref Graphics g PictureBox picbox

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12800  2011-03-27 11:37  DrawPlane\DrawPlane\bin\Debug\DrawPlane.exe

     文件      30208  2011-03-27 11:37  DrawPlane\DrawPlane\bin\Debug\DrawPlane.pdb

     文件      14328  2011-03-27 11:45  DrawPlane\DrawPlane\bin\Debug\DrawPlane.vshost.exe

     文件        490  2007-07-21 01:33  DrawPlane\DrawPlane\bin\Debug\DrawPlane.vshost.exe.manifest

     文件       5521  2011-03-27 11:37  DrawPlane\DrawPlane\Draw.cs

     文件       3764  2011-03-23 10:22  DrawPlane\DrawPlane\DrawPlane.csproj

     文件       3020  2011-03-27 11:22  DrawPlane\DrawPlane\Form1.cs

     文件       5867  2011-03-27 11:06  DrawPlane\DrawPlane\Form1.Designer.cs

     文件       6008  2011-03-27 11:06  DrawPlane\DrawPlane\Form1.resx

     文件        618  2011-03-27 11:45  DrawPlane\DrawPlane\obj\Debug\DrawPlane.csproj.FileListAbsolute.txt

     文件        847  2011-03-27 11:06  DrawPlane\DrawPlane\obj\Debug\DrawPlane.csproj.GenerateResource.Cache

     文件      12800  2011-03-27 11:37  DrawPlane\DrawPlane\obj\Debug\DrawPlane.exe

     文件        180  2011-03-27 11:06  DrawPlane\DrawPlane\obj\Debug\DrawPlane.Form1.resources

     文件      30208  2011-03-27 11:37  DrawPlane\DrawPlane\obj\Debug\DrawPlane.pdb

     文件        180  2011-03-23 10:22  DrawPlane\DrawPlane\obj\Debug\DrawPlane.Properties.Resources.resources

     文件        490  2011-03-23 09:42  DrawPlane\DrawPlane\Program.cs

     文件       1374  2011-03-23 09:42  DrawPlane\DrawPlane\Properties\AssemblyInfo.cs

     文件       2868  2011-03-23 09:42  DrawPlane\DrawPlane\Properties\Resources.Designer.cs

     文件       5612  2011-03-23 09:42  DrawPlane\DrawPlane\Properties\Resources.resx

     文件       1094  2011-03-23 09:42  DrawPlane\DrawPlane\Properties\Settings.Designer.cs

     文件        249  2011-03-23 09:42  DrawPlane\DrawPlane\Properties\Settings.settings

     文件        917  2011-03-23 09:42  DrawPlane\DrawPlane.sln

    ..A..H.     15872  2011-03-27 12:03  DrawPlane\DrawPlane.suo

     目录          0  2011-03-23 12:33  DrawPlane\DrawPlane\obj\Debug\Refactor

     目录          0  2011-03-23 09:42  DrawPlane\DrawPlane\obj\Debug\TempPE

     目录          0  2011-03-23 10:22  DrawPlane\DrawPlane\bin\Debug

     目录          0  2011-03-27 11:37  DrawPlane\DrawPlane\obj\Debug

     目录          0  2011-03-23 09:42  DrawPlane\DrawPlane\bin

     目录          0  2011-03-23 09:42  DrawPlane\DrawPlane\obj

     目录          0  2011-03-23 09:42  DrawPlane\DrawPlane\Properties

............此处省略5个文件信息

评论

共有 条评论