资源简介

by conmajia 这是一个简单的GDI+的例子。讲的是怎么从无到有绘制一个极坐标系,以及在此基础上绘制数据图。按照类似的思路,你可以画出直角坐标系、对数直角系、外太空银河系…… 没有版权,但仍希望使用者能够反馈 conmajia@gmail.com

资源截图

代码片段和文件信息

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

namespace GetPhysical
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        public class PolarValue
        {
            float ang = 0;
            float val = 0;

            // 角度
            public float Angle
            {
                get { return ang; }
                set { ang = value; }
            }

            // 数值
            public float Value
            {
                get { return val; }
                set { val = value; }
            }

            public PolarValue(float angle float value)
            {
                this.ang = angle;
                this.val = value;
            }
        }

        // 数据列表
        public List values = new List();
        float min = 0;
        float max = 100;

        // 合并后的映射方法
        private PointF getMappedPoint(float angle float value)
        {
            // 计算映射在坐标图中的半径
            float r = radius * (value - min) / (max - min);
            // 计算GDI+坐标
            PointF pt = new PointF();
            pt.X = (float)(r * Math.Cos(angle * Math.PI / 180) + center.X);
            pt.Y = (float)(r * Math.Sin(angle * Math.PI / 180) + center.Y);
            return pt;
        }

        private void Form1_Paint(object sender PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            //drawDiagramCircles(e.Graphics this.ClientRectangle);
            // 缩小点画圆的区域
            Rectangle rect = this.ClientRectangle;
            rect.Inflate(0 -20);
            drawDiagramCircles(e.Graphics rect);

            drawDiagramCrosshair(e.Graphics);

            drawPoints(e.Graphics values);
        }

        // 画圆
        float diameter radius;
        PointF center;
        private void drawDiagramCircles(Graphics g Rectangle rect)
        {
            // 圆的直径等于绘图区域最短边
            diameter = Math.Min(rect.Width rect.Height);
            // 半径
            radius = diameter / 2;
            // 圆心
            center = new PointF(
               rect.X + rect.Width / 2
               rect.Y + rect.Height / 2
               );

            // 画几个圆
            int count = 1;
            float diameterStep = diameter / count;
            float radiusStep = radius / count;

            // 生成圆的范围
            RectangleF cirleRect = new RectangleF();
            cirleRect.X = center.X - radius;
            cirleRect.Y = center.Y - radius;
            cirleRect.Width = cirleRect.Height = diameter;

            // 画同心圆
            for (int i = 0; i < count; i++

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-05-21 22:40  PolarDiagram\
     文件        1685  2012-05-21 21:54  PolarDiagram\Form1.Designer.cs
     文件        6094  2012-05-21 22:05  PolarDiagram\Form1.cs
     文件        5814  2012-05-21 21:54  PolarDiagram\Form1.resx
     文件        3304  2012-05-21 22:05  PolarDiagram\GetPhysical.csproj
     文件         910  2012-05-20 20:54  PolarDiagram\GetPhysical.sln
     文件       13824  2012-05-21 22:05  PolarDiagram\GetPhysical.suo
     文件         470  2012-05-20 20:54  PolarDiagram\Program.cs
     目录           0  2012-05-21 22:40  PolarDiagram\Properties\
     文件        1186  2012-05-21 22:41  PolarDiagram\Properties\AssemblyInfo.cs
     文件        2878  2012-05-20 20:54  PolarDiagram\Properties\Resources.Designer.cs
     文件        5612  2012-05-20 20:54  PolarDiagram\Properties\Resources.resx
     文件        1096  2012-05-20 20:54  PolarDiagram\Properties\Settings.Designer.cs
     文件         249  2012-05-20 20:54  PolarDiagram\Properties\Settings.settings
     目录           0  2012-05-21 22:40  PolarDiagram\bin\
     目录           0  2012-05-21 22:40  PolarDiagram\bin\Debug\
     文件       24576  2012-05-21 22:05  PolarDiagram\bin\Debug\GetPhysical.exe
     文件       36352  2012-05-21 22:05  PolarDiagram\bin\Debug\GetPhysical.pdb
     文件        5632  2005-11-11 22:25  PolarDiagram\bin\Debug\GetPhysical.vshost.exe
     目录           0  2012-05-21 22:40  PolarDiagram\obj\
     目录           0  2012-05-21 22:40  PolarDiagram\obj\Debug\
     文件         180  2012-05-21 21:54  PolarDiagram\obj\Debug\GetPhysical.Form1.resources
     文件         180  2012-05-20 21:12  PolarDiagram\obj\Debug\GetPhysical.Properties.Resources.resources
     文件         842  2012-05-21 21:54  PolarDiagram\obj\Debug\GetPhysical.csproj.GenerateResource.Cache
     文件       24576  2012-05-21 22:05  PolarDiagram\obj\Debug\GetPhysical.exe
     文件       36352  2012-05-21 22:05  PolarDiagram\obj\Debug\GetPhysical.pdb
     目录           0  2012-05-21 22:41  PolarDiagram\obj\Debug\Refactor\
     文件        2613  2012-05-21 21:43  PolarDiagram\obj\Debug\ResolveAssemblyReference.cache
     目录           0  2012-05-21 22:41  PolarDiagram\obj\Debug\TempPE\
     文件         664  2012-05-21 22:05  PolarDiagram\obj\GetPhysical.csproj.FileListAbsolute.txt

评论

共有 条评论