資源簡介
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?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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
評論
共有 條評論