幾何繪圖與三角函數計算應用

幾何繪圖與三角函數計算應用

設計思路

  • 左側為繪圖控制面板,右側為繪圖區域
  • 支持繪制點、線、矩形、圓、多邊形等基本幾何圖形
  • 實現三角函數計算器(正弦、余弦、正切等)
  • 包含角度/弧度切換和常用數學常數
  • 歷史記錄功能保存用戶繪圖

完整實現代碼

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;namespace GeometryDrawingApp
{public partial class MainForm : Form{// 繪圖狀態變量private enum DrawingMode { None, Point, Line, Rectangle, Circle, Polygon, Select }private DrawingMode currentMode = DrawingMode.None;// 圖形存儲private List<Shape> shapes = new List<Shape>();private Shape currentShape = null;private Point startPoint;private Point endPoint;// 多邊形繪制狀態private List<Point> polygonPoints = new List<Point>();private bool isPolygonDrawing = false;// 選擇狀態private Shape selectedShape = null;// 顏色設置private Color drawingColor = Color.Blue;private Color selectedColor = Color.Red;public MainForm(){InitializeComponent();InitializeApp();}private void InitializeApp(){// 設置繪圖區域背景drawingPanel.BackColor = Color.White;drawingPanel.Paint += DrawingPanel_Paint;drawingPanel.MouseDown += DrawingPanel_MouseDown;drawingPanel.MouseMove += DrawingPanel_MouseMove;drawingPanel.MouseUp += DrawingPanel_MouseUp;// 設置初始繪圖模式SetDrawingMode(DrawingMode.Select);// 初始化三角函數計算器InitializeTrigCalculator();// 設置顏色選擇器colorComboBox.Items.AddRange(new object[] { "Blue", "Red", "Green", "Purple", "Orange", "Black" });colorComboBox.SelectedIndex = 0;colorComboBox.SelectedIndexChanged += (s, e) =>{string colorName = colorComboBox.SelectedItem.ToString();drawingColor = Color.FromName(colorName);};// 設置線寬選擇器for (int i = 1; i <= 5; i++)lineWidthComboBox.Items.Add(i);lineWidthComboBox.SelectedIndex = 0;// 設置填充樣式fillStyleComboBox.Items.AddRange(new object[] { "None", "Solid", "Hatch" });fillStyleComboBox.SelectedIndex = 0;// 設置歷史記錄列表historyListBox.DisplayMember = "Description";}private void InitializeTrigCalculator(){// 初始化三角函數計算器UIangleTypeComboBox.Items.AddRange(new object[] { "Degrees", "Radians" });angleTypeComboBox.SelectedIndex = 0;// 添加常用常數constantComboBox.Items.AddRange(new object[] { "π", "e", "√2", "√3", "φ" });constantComboBox.SelectedIndex = 0;// 設置默認值angleTextBox.Text = "30";CalculateTrigFunctions();}private void SetDrawingMode(DrawingMode mode){currentMode = mode;statusLabel.Text = $"Mode: {mode}";// 如果從多邊形繪制切換到其他模式,清除多邊形點if (mode != DrawingMode.Polygon && isPolygonDrawing){polygonPoints.Clear();isPolygonDrawing = false;polygonButton.Text = "Polygon";}}// 圖形基類public abstract class Shape{public Color Color { get; set; }public int LineWidth { get; set; }public bool Filled { get; set; }public bool Selected { get; set; }public abstract void Draw(Graphics g);public abstract bool Contains(Point point);public abstract string Description { get; }}// 點類public class PointShape : Shape{public Point Location { get; set; }public override void Draw(Graphics g){using (Brush brush = new SolidBrush(Selected ? Color.Red : Color)){g.FillEllipse(brush, Location.X - 3, Location.Y - 3, 6, 6);}}public override bool Contains(Point point){return Math.Sqrt(Math.Pow(point.X - Location.X, 2) + Math.Pow(point.Y - Location.Y, 2)) < 5;}public override string Description => $"Point at ({Location.X}, {Location.Y})";}// 線類public class LineShape : Shape{public Point Start { get; set; }public Point End { get; set; }public override void Draw(Graphics g){using (Pen pen = new Pen(Selected ? Color.Red : Color, LineWidth)){g.DrawLine(pen, Start, End);}}public override bool Contains(Point point){// 簡化的點線距離計算double distance = Math.Abs((End.Y - Start.Y) * point.X - (End.X - Start.X) * point.Y +End.X * Start.Y - End.Y * Start.X) /Math.Sqrt(Math.Pow(End.Y - Start.Y, 2) + Math.Pow(End.X - Start.X, 2));return distance < 5;}public override string Description => $"Line from ({Start.X}, {Start.Y}) to ({End.X}, {End.Y})";}// 矩形類public class RectangleShape : Shape{public Rectangle Rect { get; set; }public override void Draw(Graphics g){using (Pen pen = new Pen(Selected ? Color.Red : Color, LineWidth)){if (Filled){using (Brush brush = new SolidBrush(Color.FromArgb(100, Color))){g.FillRectangle(brush, Rect);}}g.DrawRectangle(pen, Rect);}}public override bool Contains(Point point){return Rect.Contains(point);}public override string Description => $"Rectangle at ({Rect.X}, {Rect.Y}), Size: {Rect.Width}x{Rect.Height}";}// 圓類public class CircleShape : Shape{public Point Center { get; set; }public int Radius { get; set; }public override void Draw(Graphics g){Rectangle rect = new Rectangle(Center.X - Radius, Center.Y - Radius,Radius * 2, Radius * 2);using (Pen pen = new Pen(Selected ? Color.Red : Color, LineWidth)){if (Filled){using (Brush brush = new SolidBrush(Color.FromArgb(100, Color))){g.FillEllipse(brush, rect);}}g.DrawEllipse(pen, rect);}}public override bool Contains(Point point){double distance = Math.Sqrt(Math.Pow(point.X - Center.X, 2) + Math.Pow(point.Y - Center.Y, 2));return distance <= Radius + 3 && distance >= Radius - 3;}public override string Description => $"Circle at ({Center.X}, {Center.Y}), Radius: {Radius}";}// 多邊形類public class PolygonShape : Shape{public List<Point> Points { get; set; } = new List<Point>();public override void Draw(Graphics g){if (Points.Count < 2) return;using (Pen pen = new Pen(Selected ? Color.Red : Color, LineWidth)){if (Filled && Points.Count > 2){using (Brush brush = new SolidBrush(Color.FromArgb(100, Color))){g.FillPolygon(brush, Points.ToArray());}}// 修復:當只有兩個點時繪制線段而不是多邊形if (Points.Count == 2){g.DrawLine(pen, Points[0], Points[1]);}else{g.DrawPolygon(pen, Points.ToArray());}}}public override bool Contains(Point point){if (Points.Count == 0) return false;// 對于只有兩個點的情況,使用線段包含檢測if (Points.Count == 2){double distance = Math.Abs((Points[1].Y - Points[0].Y) * point.X -(Points[1].X - Points[0].X) * point.Y +Points[1].X * Points[0].Y - Points[1].Y * Points[0].X) /Math.Sqrt(Math.Pow(Points[1].Y - Points[0].Y, 2) +Math.Pow(Points[1].X - Points[0].X, 2));return distance < 5;}// 對于三個點以上的多邊形GraphicsPath path = new GraphicsPath();path.AddPolygon(Points.ToArray());return path.IsVisible(point);}public override string Description => $"Polygon with {Points.Count} points";}private void DrawingPanel_Paint(object sender, PaintEventArgs e){Graphics g = e.Graphics;g.SmoothingMode = SmoothingMode.AntiAlias;// 繪制所有圖形foreach (Shape shape in shapes){shape.Draw(g);}// 繪制當前正在繪制的圖形if (currentShape != null){currentShape.Draw(g);}// 繪制多邊形點(如果正在繪制多邊形)if (isPolygonDrawing && polygonPoints.Count > 0){// 繪制點之間的連線if (polygonPoints.Count > 1){using (Pen pen = new Pen(Color.Gray, 1)){pen.DashStyle = DashStyle.Dash;g.DrawLines(pen, polygonPoints.ToArray());}}// 繪制所有點foreach (Point p in polygonPoints){g.FillEllipse(Brushes.Blue, p.X - 3, p.Y - 3, 6, 6);}// 繪制從最后一個點到當前鼠標位置的線Point currentPos = drawingPanel.PointToClient(Cursor.Position);if (polygonPoints.Count > 0){using (Pen pen = new Pen(Color.DarkGray, 1)){pen.DashStyle = DashStyle.Dot;g.DrawLine(pen, polygonPoints[polygonPoints.Count - 1], currentPos);}}}}private void DrawingPanel_MouseDown(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Right && isPolygonDrawing){// 右鍵取消多邊形繪制polygonPoints.Clear();isPolygonDrawing = false;polygonButton.Text = "Polygon";drawingPanel.Invalidate();return;}if (e.Button != MouseButtons.Left) return;if (currentMode == DrawingMode.Select){// 選擇圖形selectedShape = null;foreach (Shape shape in shapes){shape.Selected = false;if (shape.Contains(e.Location)){selectedShape = shape;shape.Selected = true;statusLabel.Text = $"Selected: {shape.Description}";}}drawingPanel.Invalidate();return;}startPoint = e.Location;switch (currentMode){case DrawingMode.Point:currentShape = new PointShape{Location = e.Location,Color = drawingColor,LineWidth = (int)lineWidthComboBox.SelectedItem};shapes.Add(currentShape);historyListBox.Items.Add(currentShape.Description);currentShape = null;break;case DrawingMode.Line:case DrawingMode.Rectangle:case DrawingMode.Circle:// 這些圖形需要開始點和結束點break;case DrawingMode.Polygon:if (!isPolygonDrawing){isPolygonDrawing = true;polygonPoints.Clear();polygonPoints.Add(e.Location);polygonButton.Text = "Complete Polygon";}else{polygonPoints.Add(e.Location);}break;}drawingPanel.Invalidate();}private void DrawingPanel_MouseMove(object sender, MouseEventArgs e){// 更新坐標顯示coordinatesLabel.Text = $"X: {e.X}, Y: {e.Y}";if (e.Button != MouseButtons.Left) return;endPoint = e.Location;switch (currentMode){case DrawingMode.Line:currentShape = new LineShape{Start = startPoint,End = endPoint,Color = drawingColor,LineWidth = (int)lineWidthComboBox.SelectedItem};break;case DrawingMode.Rectangle:int width = endPoint.X - startPoint.X;int height = endPoint.Y - startPoint.Y;currentShape = new RectangleShape{Rect = new Rectangle(startPoint.X, startPoint.Y, width, height),Color = drawingColor,LineWidth = (int)lineWidthComboBox.SelectedItem,Filled = fillStyleComboBox.SelectedIndex > 0};break;case DrawingMode.Circle:int radius = (int)Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) +Math.Pow(endPoint.Y - startPoint.Y, 2));currentShape = new CircleShape{Center = startPoint,Radius = radius,Color = drawingColor,LineWidth = (int)lineWidthComboBox.SelectedItem,Filled = fillStyleComboBox.SelectedIndex > 0};break;}drawingPanel.Invalidate();}private void DrawingPanel_MouseUp(object sender, MouseEventArgs e){if (e.Button != MouseButtons.Left || currentShape == null) return;switch (currentMode){case DrawingMode.Line:case DrawingMode.Rectangle:case DrawingMode.Circle:shapes.Add(currentShape);historyListBox.Items.Add(currentShape.Description);currentShape = null;break;}}private void pointButton_Click(object sender, EventArgs e) => SetDrawingMode(DrawingMode.Point);private void lineButton_Click(object sender, EventArgs e) => SetDrawingMode(DrawingMode.Line);private void rectangleButton_Click(object sender, EventArgs e) => SetDrawingMode(DrawingMode.Rectangle);private void circleButton_Click(object sender, EventArgs e) => SetDrawingMode(DrawingMode.Circle);private void selectButton_Click(object sender, EventArgs e) => SetDrawingMode(DrawingMode.Select);private void polygonButton_Click(object sender, EventArgs e){if (isPolygonDrawing){// 完成多邊形繪制if (polygonPoints.Count > 1) // 至少需要兩個點{currentShape = new PolygonShape{Points = new List<Point>(polygonPoints),Color = drawingColor,LineWidth = (int)lineWidthComboBox.SelectedItem,Filled = fillStyleComboBox.SelectedIndex > 0};shapes.Add(currentShape);historyListBox.Items.Add(currentShape.Description);}else if (polygonPoints.Count == 1){// 如果只有一個點,創建點對象currentShape = new PointShape{Location = polygonPoints[0],Color = drawingColor,LineWidth = (int)lineWidthComboBox.SelectedItem};shapes.Add(currentShape);historyListBox.Items.Add(currentShape.Description);}polygonPoints.Clear();isPolygonDrawing = false;polygonButton.Text = "Polygon";SetDrawingMode(DrawingMode.Select);}else{SetDrawingMode(DrawingMode.Polygon);}drawingPanel.Invalidate();}private void clearButton_Click(object sender, EventArgs e){// 修復:正確清空所有圖形和多邊形狀態shapes.Clear();historyListBox.Items.Clear();selectedShape = null;// 清空多邊形繪制狀態polygonPoints.Clear();isPolygonDrawing = false;polygonButton.Text = "Polygon";// 重置為選擇模式SetDrawingMode(DrawingMode.Select);drawingPanel.Invalidate();}private void CalculateTrigFunctions(){if (double.TryParse(angleTextBox.Text, out double angleValue)){bool isDegrees = angleTypeComboBox.SelectedIndex == 0;double radians = isDegrees ? angleValue * Math.PI / 180.0 : angleValue;sinLabel.Text = $"sin: {Math.Sin(radians):F4}";cosLabel.Text = $"cos: {Math.Cos(radians):F4}";tanLabel.Text = $"tan: {Math.Tan(radians):F4}";// 避免除以零錯誤if (Math.Cos(radians) != 0)secLabel.Text = $"sec: {1.0 / Math.Cos(radians):F4}";elsesecLabel.Text = "sec: undefined";if (Math.Sin(radians) != 0)cscLabel.Text = $"csc: {1.0 / Math.Sin(radians):F4}";elsecscLabel.Text = "csc: undefined";if (Math.Tan(radians) != 0)cotLabel.Text = $"cot: {1.0 / Math.Tan(radians):F4}";elsecotLabel.Text = "cot: undefined";}else{sinLabel.Text = "sin: invalid input";cosLabel.Text = "cos: invalid input";tanLabel.Text = "tan: invalid input";secLabel.Text = "sec: invalid input";cscLabel.Text = "csc: invalid input";cotLabel.Text = "cot: invalid input";}}private void calculateButton_Click(object sender, EventArgs e){CalculateTrigFunctions();}private void constantComboBox_SelectedIndexChanged(object sender, EventArgs e){switch (constantComboBox.SelectedIndex){case 0: // πangleTextBox.Text = Math.PI.ToString("F6");break;case 1: // eangleTextBox.Text = Math.E.ToString("F6");break;case 2: // √2angleTextBox.Text = Math.Sqrt(2).ToString("F6");break;case 3: // √3angleTextBox.Text = Math.Sqrt(3).ToString("F6");break;case 4: // φ (黃金比例)angleTextBox.Text = ((1 + Math.Sqrt(5)) / 2).ToString("F6");break;}CalculateTrigFunctions();}private void deleteButton_Click(object sender, EventArgs e){if (selectedShape != null){shapes.Remove(selectedShape);selectedShape = null;drawingPanel.Invalidate();// 更新歷史記錄historyListBox.Items.Clear();foreach (Shape shape in shapes){historyListBox.Items.Add(shape.Description);}}}private void MainForm_Load(object sender, EventArgs e){// 添加示例圖形shapes.Add(new PointShape { Location = new Point(100, 100), Color = Color.Blue });shapes.Add(new LineShape{Start = new Point(150, 150),End = new Point(250, 200),Color = Color.Green,LineWidth = 2});shapes.Add(new RectangleShape{Rect = new Rectangle(300, 100, 80, 60),Color = Color.Purple,LineWidth = 2});shapes.Add(new CircleShape{Center = new Point(200, 300),Radius = 50,Color = Color.Orange,LineWidth = 2});// 添加歷史記錄foreach (Shape shape in shapes){historyListBox.Items.Add(shape.Description);}}private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){HelpForm f = new HelpForm();f.ShowDialog();}}
}

窗體設計代碼 (MainForm.Designer.cs)

namespace GeometryDrawingApp
{partial class MainForm{private System.ComponentModel.IContainer components = null;protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows Form Designer generated codeprivate void InitializeComponent(){System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));this.drawingPanel = new System.Windows.Forms.Panel();this.controlPanel = new System.Windows.Forms.Panel();this.deleteButton = new System.Windows.Forms.Button();this.clearButton = new System.Windows.Forms.Button();this.fillStyleComboBox = new System.Windows.Forms.ComboBox();this.label5 = new System.Windows.Forms.Label();this.lineWidthComboBox = new System.Windows.Forms.ComboBox();this.label4 = new System.Windows.Forms.Label();this.colorComboBox = new System.Windows.Forms.ComboBox();this.label3 = new System.Windows.Forms.Label();this.polygonButton = new System.Windows.Forms.Button();this.selectButton = new System.Windows.Forms.Button();this.circleButton = new System.Windows.Forms.Button();this.rectangleButton = new System.Windows.Forms.Button();this.lineButton = new System.Windows.Forms.Button();this.pointButton = new System.Windows.Forms.Button();this.calculatorGroup = new System.Windows.Forms.GroupBox();this.cotLabel = new System.Windows.Forms.Label();this.cscLabel = new System.Windows.Forms.Label();this.secLabel = new System.Windows.Forms.Label();this.tanLabel = new System.Windows.Forms.Label();this.cosLabel = new System.Windows.Forms.Label();this.sinLabel = new System.Windows.Forms.Label();this.calculateButton = new System.Windows.Forms.Button();this.constantComboBox = new System.Windows.Forms.ComboBox();this.label2 = new System.Windows.Forms.Label();this.angleTypeComboBox = new System.Windows.Forms.ComboBox();this.angleTextBox = new System.Windows.Forms.TextBox();this.label1 = new System.Windows.Forms.Label();this.statusStrip = new System.Windows.Forms.StatusStrip();this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel();this.coordinatesLabel = new System.Windows.Forms.ToolStripStatusLabel();this.historyGroup = new System.Windows.Forms.GroupBox();this.historyListBox = new System.Windows.Forms.ListBox();this.controlPanel.SuspendLayout();this.calculatorGroup.SuspendLayout();this.statusStrip.SuspendLayout();this.historyGroup.SuspendLayout();this.SuspendLayout();// // drawingPanel// this.drawingPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));this.drawingPanel.BackColor = System.Drawing.Color.White;this.drawingPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;this.drawingPanel.Location = new System.Drawing.Point(12, 12);this.drawingPanel.Name = "drawingPanel";this.drawingPanel.Size = new System.Drawing.Size(600, 500);this.drawingPanel.TabIndex = 0;// // controlPanel// this.controlPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right));this.controlPanel.BackColor = System.Drawing.SystemColors.ControlLight;this.controlPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;this.controlPanel.Controls.Add(this.deleteButton);this.controlPanel.Controls.Add(this.clearButton);this.controlPanel.Controls.Add(this.fillStyleComboBox);this.controlPanel.Controls.Add(this.label5);this.controlPanel.Controls.Add(this.lineWidthComboBox);this.controlPanel.Controls.Add(this.label4);this.controlPanel.Controls.Add(this.colorComboBox);this.controlPanel.Controls.Add(this.label3);this.controlPanel.Controls.Add(this.polygonButton);this.controlPanel.Controls.Add(this.selectButton);this.controlPanel.Controls.Add(this.circleButton);this.controlPanel.Controls.Add(this.rectangleButton);this.controlPanel.Controls.Add(this.lineButton);this.controlPanel.Controls.Add(this.pointButton);this.controlPanel.Controls.Add(this.calculatorGroup);this.controlPanel.Controls.Add(this.historyGroup);this.controlPanel.Location = new System.Drawing.Point(618, 12);this.controlPanel.Name = "controlPanel";this.controlPanel.Size = new System.Drawing.Size(280, 640);this.controlPanel.TabIndex = 1;// // deleteButton// this.deleteButton.BackColor = System.Drawing.Color.LightCoral;this.deleteButton.Location = new System.Drawing.Point(142, 295);this.deleteButton.Name = "deleteButton";this.deleteButton.Size = new System.Drawing.Size(120, 30);this.deleteButton.TabIndex = 16;this.deleteButton.Text = "Delete Selected";this.deleteButton.UseVisualStyleBackColor = false;this.deleteButton.Click += new System.EventHandler(this.deleteButton_Click);// // clearButton// this.clearButton.BackColor = System.Drawing.Color.LightCoral;this.clearButton.Location = new System.Drawing.Point(16, 295);this.clearButton.Name = "clearButton";this.clearButton.Size = new System.Drawing.Size(120, 30);this.clearButton.TabIndex = 15;this.clearButton.Text = "Clear All";this.clearButton.UseVisualStyleBackColor = false;this.clearButton.Click += new System.EventHandler(this.clearButton_Click);// // fillStyleComboBox// this.fillStyleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;this.fillStyleComboBox.FormattingEnabled = true;this.fillStyleComboBox.Location = new System.Drawing.Point(90, 258);this.fillStyleComboBox.Name = "fillStyleComboBox";this.fillStyleComboBox.Size = new System.Drawing.Size(172, 21);this.fillStyleComboBox.TabIndex = 14;// // label5// this.label5.AutoSize = true;this.label5.Location = new System.Drawing.Point(16, 261);this.label5.Name = "label5";this.label5.Size = new System.Drawing.Size(48, 13);this.label5.TabIndex = 13;this.label5.Text = "Fill Style:";// // lineWidthComboBox// this.lineWidthComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;this.lineWidthComboBox.FormattingEnabled = true;this.lineWidthComboBox.Location = new System.Drawing.Point(90, 231);this.lineWidthComboBox.Name = "lineWidthComboBox";this.lineWidthComboBox.Size = new System.Drawing.Size(172, 21);this.lineWidthComboBox.TabIndex = 12;// // label4// this.label4.AutoSize = true;this.label4.Location = new System.Drawing.Point(16, 234);this.label4.Name = "label4";this.label4.Size = new System.Drawing.Size(60, 13);this.label4.TabIndex = 11;this.label4.Text = "Line Width:";// // colorComboBox// this.colorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;this.colorComboBox.FormattingEnabled = true;this.colorComboBox.Location = new System.Drawing.Point(90, 204);this.colorComboBox.Name = "colorComboBox";this.colorComboBox.Size = new System.Drawing.Size(172, 21);this.colorComboBox.TabIndex = 10;// // label3// this.label3.AutoSize = true;this.label3.Location = new System.Drawing.Point(16, 207);this.label3.Name = "label3";this.label3.Size = new System.Drawing.Size(34, 13);this.label3.TabIndex = 9;this.label3.Text = "Color:";// // polygonButton// this.polygonButton.Location = new System.Drawing.Point(142, 168);this.polygonButton.Name = "polygonButton";this.polygonButton.Size = new System.Drawing.Size(120, 30);this.polygonButton.TabIndex = 8;this.polygonButton.Text = "Polygon";this.polygonButton.UseVisualStyleBackColor = true;this.polygonButton.Click += new System.EventHandler(this.polygonButton_Click);// // selectButton// this.selectButton.Location = new System.Drawing.Point(16, 168);this.selectButton.Name = "selectButton";this.selectButton.Size = new System.Drawing.Size(120, 30);this.selectButton.TabIndex = 7;this.selectButton.Text = "Select";this.selectButton.UseVisualStyleBackColor = true;this.selectButton.Click += new System.EventHandler(this.selectButton_Click);// // circleButton// this.circleButton.Location = new System.Drawing.Point(142, 132);this.circleButton.Name = "circleButton";this.circleButton.Size = new System.Drawing.Size(120, 30);this.circleButton.TabIndex = 6;this.circleButton.Text = "Circle";this.circleButton.UseVisualStyleBackColor = true;this.circleButton.Click += new System.EventHandler(this.circleButton_Click);// // rectangleButton// this.rectangleButton.Location = new System.Drawing.Point(16, 132);this.rectangleButton.Name = "rectangleButton";this.rectangleButton.Size = new System.Drawing.Size(120, 30);this.rectangleButton.TabIndex = 5;this.rectangleButton.Text = "Rectangle";this.rectangleButton.UseVisualStyleBackColor = true;this.rectangleButton.Click += new System.EventHandler(this.rectangleButton_Click);// // lineButton// this.lineButton.Location = new System.Drawing.Point(142, 96);this.lineButton.Name = "lineButton";this.lineButton.Size = new System.Drawing.Size(120, 30);this.lineButton.TabIndex = 4;this.lineButton.Text = "Line";this.lineButton.UseVisualStyleBackColor = true;this.lineButton.Click += new System.EventHandler(this.lineButton_Click);// // pointButton// this.pointButton.Location = new System.Drawing.Point(16, 96);this.pointButton.Name = "pointButton";this.pointButton.Size = new System.Drawing.Size(120, 30);this.pointButton.TabIndex = 3;this.pointButton.Text = "Point";this.pointButton.UseVisualStyleBackColor = true;this.pointButton.Click += new System.EventHandler(this.pointButton_Click);// // calculatorGroup// this.calculatorGroup.Controls.Add(this.cotLabel);this.calculatorGroup.Controls.Add(this.cscLabel);this.calculatorGroup.Controls.Add(this.secLabel);this.calculatorGroup.Controls.Add(this.tanLabel);this.calculatorGroup.Controls.Add(this.cosLabel);this.calculatorGroup.Controls.Add(this.sinLabel);this.calculatorGroup.Controls.Add(this.calculateButton);this.calculatorGroup.Controls.Add(this.constantComboBox);this.calculatorGroup.Controls.Add(this.label2);this.calculatorGroup.Controls.Add(this.angleTypeComboBox);this.calculatorGroup.Controls.Add(this.angleTextBox);this.calculatorGroup.Controls.Add(this.label1);this.calculatorGroup.Location = new System.Drawing.Point(16, 331);this.calculatorGroup.Name = "calculatorGroup";this.calculatorGroup.Size = new System.Drawing.Size(246, 180);this.calculatorGroup.TabIndex = 2;this.calculatorGroup.TabStop = false;this.calculatorGroup.Text = "Trigonometry Calculator";// // cotLabel// this.cotLabel.AutoSize = true;this.cotLabel.Location = new System.Drawing.Point(130, 150);this.cotLabel.Name = "cotLabel";this.cotLabel.Size = new System.Drawing.Size(30, 13);this.cotLabel.TabIndex = 11;this.cotLabel.Text = "cot: ";// // cscLabel// this.cscLabel.AutoSize = true;this.cscLabel.Location = new System.Drawing.Point(130, 130);this.cscLabel.Name = "cscLabel";this.cscLabel.Size = new System.Drawing.Size(30, 13);this.cscLabel.TabIndex = 10;this.cscLabel.Text = "csc: ";// // secLabel// this.secLabel.AutoSize = true;this.secLabel.Location = new System.Drawing.Point(130, 110);this.secLabel.Name = "secLabel";this.secLabel.Size = new System.Drawing.Size(30, 13);this.secLabel.TabIndex = 9;this.secLabel.Text = "sec: ";// // tanLabel// this.tanLabel.AutoSize = true;this.tanLabel.Location = new System.Drawing.Point(20, 150);this.tanLabel.Name = "tanLabel";this.tanLabel.Size = new System.Drawing.Size(28, 13);this.tanLabel.TabIndex = 8;this.tanLabel.Text = "tan: ";// // cosLabel// this.cosLabel.AutoSize = true;this.cosLabel.Location = new System.Drawing.Point(20, 130);this.cosLabel.Name = "cosLabel";this.cosLabel.Size = new System.Drawing.Size(30, 13);this.cosLabel.TabIndex = 7;this.cosLabel.Text = "cos: ";// // sinLabel// this.sinLabel.AutoSize = true;this.sinLabel.Location = new System.Drawing.Point(20, 110);this.sinLabel.Name = "sinLabel";this.sinLabel.Size = new System.Drawing.Size(27, 13);this.sinLabel.TabIndex = 6;this.sinLabel.Text = "sin: ";// // calculateButton// this.calculateButton.Location = new System.Drawing.Point(150, 70);this.calculateButton.Name = "calculateButton";this.calculateButton.Size = new System.Drawing.Size(80, 25);this.calculateButton.TabIndex = 5;this.calculateButton.Text = "Calculate";this.calculateButton.UseVisualStyleBackColor = true;this.calculateButton.Click += new System.EventHandler(this.calculateButton_Click);// // constantComboBox// this.constantComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;this.constantComboBox.FormattingEnabled = true;this.constantComboBox.Location = new System.Drawing.Point(90, 73);this.constantComboBox.Name = "constantComboBox";this.constantComboBox.Size = new System.Drawing.Size(54, 21);this.constantComboBox.TabIndex = 4;this.constantComboBox.SelectedIndexChanged += new System.EventHandler(this.constantComboBox_SelectedIndexChanged);// // label2// this.label2.AutoSize = true;this.label2.Location = new System.Drawing.Point(20, 76);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(56, 13);this.label2.TabIndex = 3;this.label2.Text = "Constants:";// // angleTypeComboBox// this.angleTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;this.angleTypeComboBox.FormattingEnabled = true;this.angleTypeComboBox.Location = new System.Drawing.Point(170, 43);this.angleTypeComboBox.Name = "angleTypeComboBox";this.angleTypeComboBox.Size = new System.Drawing.Size(60, 21);this.angleTypeComboBox.TabIndex = 2;// // angleTextBox// this.angleTextBox.Location = new System.Drawing.Point(90, 43);this.angleTextBox.Name = "angleTextBox";this.angleTextBox.Size = new System.Drawing.Size(74, 20);this.angleTextBox.TabIndex = 1;this.angleTextBox.Text = "30";// // label1// this.label1.AutoSize = true;this.label1.Location = new System.Drawing.Point(20, 46);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(37, 13);this.label1.TabIndex = 0;this.label1.Text = "Angle:";// // statusStrip// this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.statusLabel,this.coordinatesLabel});this.statusStrip.Location = new System.Drawing.Point(0, 665);this.statusStrip.Name = "statusStrip";this.statusStrip.Size = new System.Drawing.Size(910, 22);this.statusStrip.TabIndex = 2;this.statusStrip.Text = "statusStrip1";// // statusLabel// this.statusLabel.Name = "statusLabel";this.statusLabel.Size = new System.Drawing.Size(42, 17);this.statusLabel.Text = "Ready";// // coordinatesLabel// this.coordinatesLabel.Name = "coordinatesLabel";this.coordinatesLabel.Size = new System.Drawing.Size(34, 17);this.coordinatesLabel.Text = "X: Y:";// // historyGroup// this.historyGroup.Controls.Add(this.historyListBox);this.historyGroup.Location = new System.Drawing.Point(16, 3);this.historyGroup.Name = "historyGroup";this.historyGroup.Size = new System.Drawing.Size(246, 87);this.historyGroup.TabIndex = 0;this.historyGroup.TabStop = false;this.historyGroup.Text = "Drawing History";// // historyListBox// this.historyListBox.Dock = System.Windows.Forms.DockStyle.Fill;this.historyListBox.FormattingEnabled = true;this.historyListBox.Location = new System.Drawing.Point(3, 16);this.historyListBox.Name = "historyListBox";this.historyListBox.Size = new System.Drawing.Size(240, 68);this.historyListBox.TabIndex = 0;// // MainForm// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(910, 687);this.Controls.Add(this.statusStrip);this.Controls.Add(this.controlPanel);this.Controls.Add(this.drawingPanel);this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));this.Name = "MainForm";this.Text = "Geometry Drawing App";this.Load += new System.EventHandler(this.MainForm_Load);this.controlPanel.ResumeLayout(false);this.controlPanel.PerformLayout();this.calculatorGroup.ResumeLayout(false);this.calculatorGroup.PerformLayout();this.statusStrip.ResumeLayout(false);this.statusStrip.PerformLayout();this.historyGroup.ResumeLayout(false);this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.Panel drawingPanel;private System.Windows.Forms.Panel controlPanel;private System.Windows.Forms.StatusStrip statusStrip;private System.Windows.Forms.ToolStripStatusLabel statusLabel;private System.Windows.Forms.GroupBox historyGroup;private System.Windows.Forms.ListBox historyListBox;private System.Windows.Forms.Button pointButton;private System.Windows.Forms.Button lineButton;private System.Windows.Forms.Button rectangleButton;private System.Windows.Forms.Button circleButton;private System.Windows.Forms.Button polygonButton;private System.Windows.Forms.Button selectButton;private System.Windows.Forms.ComboBox colorComboBox;private System.Windows.Forms.Label label3;private System.Windows.Forms.ComboBox lineWidthComboBox;private System.Windows.Forms.Label label4;private System.Windows.Forms.ComboBox fillStyleComboBox;private System.Windows.Forms.Label label5;private System.Windows.Forms.Button clearButton;private System.Windows.Forms.GroupBox calculatorGroup;private System.Windows.Forms.Label label1;private System.Windows.Forms.TextBox angleTextBox;private System.Windows.Forms.ComboBox angleTypeComboBox;private System.Windows.Forms.Button calculateButton;private System.Windows.Forms.ComboBox constantComboBox;private System.Windows.Forms.Label label2;private System.Windows.Forms.Label sinLabel;private System.Windows.Forms.Label cotLabel;private System.Windows.Forms.Label cscLabel;private System.Windows.Forms.Label secLabel;private System.Windows.Forms.Label tanLabel;private System.Windows.Forms.Label cosLabel;private System.Windows.Forms.Button deleteButton;private System.Windows.Forms.ToolStripStatusLabel coordinatesLabel;}
}

功能說明

這個幾何繪圖應用包含以下核心功能:

  1. 繪圖功能

    • 支持繪制點、線、矩形、圓和多邊形
    • 可選擇顏色、線寬和填充樣式
    • 選擇工具可選取已繪制的圖形
    • 可刪除選中的圖形或清空整個畫布
  2. 三角函數計算器

    • 支持角度和弧度模式
    • 計算正弦、余弦、正切及其倒數函數
    • 內置常用數學常數(π、e、√2等)
  3. 歷史記錄

    • 記錄所有繪制的圖形
    • 顯示圖形類型和位置信息
  4. 用戶界面

    • 左側為繪圖區域,右側為控制面板
    • 狀態欄顯示當前模式和鼠標坐標
    • 直觀的工具欄和設置選項

使用說明

  1. 繪圖

    • 選擇要繪制的圖形類型(點、線、矩形等)
    • 在繪圖區域點擊并拖動鼠標創建圖形
    • 對于多邊形:點擊多個點,最后點擊"Complete Polygon"按鈕完成
  2. 編輯

    • 使用選擇工具點擊圖形可選中它
    • 點擊"Delete Selected"刪除選中圖形
    • 點擊"Clear All"清空整個畫布
  3. 三角函數計算

    • 輸入角度值(或使用預設常數)
    • 選擇角度單位(度或弧度)
    • 點擊"Calculate"按鈕計算結果

這個應用程序結合了幾何繪圖和數學計算功能,適合用于教學、工程繪圖和數學學習場景。界面設計直觀,功能完整,代碼結構清晰易于擴展。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/84191.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/84191.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/84191.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

CSS 定位:原理 + 場景 + 示例全解析

一. 什么是CSS定位? CSS中的position屬性用于設置元素的定位方式,它決定了元素在頁面中的"定位行為" 為什么需要定位? 常規布局(如 display: block)適用于主結構 定位適用于浮動按鈕,彈出層,粘性標題等場景幫助我們精確控制元素在頁面中的位置 二. 定位類型全…

GESP 二級復習參考 A

本教程完整包含&#xff1a; 5000字詳細知識點解析 36個Python/C雙語言示例 15個GESP真題及模擬題 8張專業圖表和流程圖 # C編程二級標準終極教程## 一、計算機存儲系統深度解析### 1.1 存儲體系架構 mermaid graph TDA[CPU寄存器] --> B[L1緩存 1-2ns]B --> C[L2緩…

嵌入式面試常問問題

以下內容面向嵌入式/系統方向的初學者與面試備考者,全面梳理了以下幾大板塊,并在每個板塊末尾列出常見的面試問答思路,幫助你既能夯實基礎,又能應對面試挑戰。 一、TCP/IP 協議 1.1 TCP/IP 五層模型概述 鏈路層(Link Layer) 包括網卡驅動、以太網、Wi?Fi、PPP 等。負責…

【人工智能 | 項目開發】Python Flask實現本地AI大模型可視化界面

文末獲取項目源碼。 文章目錄 項目背景項目結構app.py(后端服務)index.html(前端界面)項目運行項目圖示項目源碼項目背景 隨著人工智能技術的快速發展,大語言模型在智能交互領域展現出巨大潛力。本項目基于 Qwen3-1.7B 模型,搭建一個輕量化的智能聊天助手,旨在為用戶提…

【設計模式】1.簡單工廠、工廠、抽象工廠模式

every blog every motto: You can do more than you think. https://blog.csdn.net/weixin_39190382?typeblog 0. 前言 以下是 簡單工廠模式、工廠方法模式 和 抽象工廠模式 的 Python 實現與對比&#xff0c;結合代碼示例和實際應用場景說明&#xff1a; 1. 簡單工廠模式&a…

瀏覽器訪問 AWS ECS 上部署的 Docker 容器(監聽 80 端口)

? 一、ECS 服務配置 Dockerfile 確保監聽 80 端口 EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]或 EXPOSE 80 CMD ["python3", "-m", "http.server", "80"]任務定義&#xff08;Task Definition&…

01.SQL語言概述

SQL 語言概述 SQL &#xff08;Structured Query Language&#xff09;結構化査詢語言 1. 關系型數據庫的常見組件 數據庫: database 表的集合&#xff0c;物理上表現為一個目錄表: table&#xff0c;行: row 列: column索引: index視圖: view&#xff0c;虛擬的表存儲過程:…

C++學習-入門到精通【14】標準庫算法

C學習-入門到精通【14】標準庫算法 目錄 C學習-入門到精通【14】標準庫算法一、對迭代器的最低要求迭代器無效 二、算法1.fill、fill_n、generate和generate_n2.equal、mismatch和lexicographical_compare3.remove、remove_if、remove_copy和remove_copy_if4.replace、replace_…

Vue 項目實戰:三種方式實現列表→詳情頁表單數據保留與恢復

背景&#xff1a;在Vue項目中&#xff0c;實現列表頁跳轉詳情頁并保留表單數據&#xff0c;返回時恢復表單狀態。 核心功能&#xff1a; 保存緩存&#xff1a;點擊查詢按鈕時&#xff0c;表單數據保存恢復緩存&#xff1a;從詳情頁返回時&#xff0c;恢復表單數據清除緩存&…

iptables實驗

實驗一&#xff1a;搭建web服務&#xff0c;設置任何人能夠通過80端口訪問。 1.下載并啟用httpd服務器 dnf -y install httpd 開啟httpd服務器 systemctl start httpd 查看是否啟用 下載并啟用iptables&#xff0c;并關閉firewalld yum install iptable…

Razor編程RenderXXX相關方法大全

文章目錄 第一章&#xff1a;RenderXXX方法概述1.1 RenderXXX方法的作用與意義1.2 基本工作原理1.3 主要方法分類 第二章&#xff1a;部分視圖渲染方法2.1 Html.RenderPartial()2.2 Html.RenderAction()2.3 性能對比分析 第三章&#xff1a;視圖組件渲染方法3.1 Html.RenderCom…

Go 語言 range 關鍵字全面解析

Go 語言 range 關鍵字全面解析 range 是 Go 語言中用于迭代數據結構的關鍵字&#xff0c;支持多種數據類型的遍歷操作。它提供了一種簡潔、安全且高效的方式來處理集合類型的數據。 基本語法 for index, value : range collection {// 循環體 } 1. 數組/切片迭代 fruits :…

美化顯示LLDB調試的數據結構

前面的博文美化顯示GDB調試的數據結構介紹了如何美化顯示GDB中調試的數據結構&#xff0c;本文將還是以mupdf庫為例介紹如何美化顯示LLDB中調試的數據結構。 先看一下美化后的效果&#xff1a; 一、加載自定義腳本 與GDB類似&#xff0c;需要添加一個~/.lldbinit文件&#xf…

【Java學習筆記】日期類

日期類 第一代日期類&#xff1a;Date 引入包 import java.text.ParseException&#xff1a;日期轉換可能會拋出轉換異常 import java.text.SimpleDateFormat import java.util.Date 1. 基本介紹 Date&#xff1a;精確到毫秒&#xff0c;代表特定的瞬間 SimpleDateForma…

C++基礎進階:函數、內聯函數與Lambda函數詳解

引言 在C編程的旅程中&#xff0c;函數是構建復雜程序的基本單元。它們像樂高積木一樣&#xff0c;允許我們將代碼分解成更小、更易于管理的部分。今天&#xff0c;我們將深入探討C中的三種重要函數類型&#xff1a;普通函數、內聯函數以及Lambda函數。掌握它們&#xff0c;將…

從Node.js到React/Vue3:流式輸出技術的全棧實現指南

本文將從底層原理到工程實踐&#xff0c;完整解析如何使用Node.js后端結合React和Vue3前端實現流式輸出功能&#xff0c;涵蓋協議選擇、性能優化、錯誤處理等關鍵細節&#xff0c;并通過真實場景案例演示完整開發流程。 一、流式輸出的核心原理與協議選擇 1.1 流式傳輸的底層機…

AT2401C中科微2.4g芯片PA

作為無線通信系統的核心模塊&#xff0c;射頻前端芯片通過整合功率放大器&#xff08;PA&#xff09;、濾波器、開關和低噪聲放大器&#xff08;LNA&#xff09;等關鍵組件&#xff0c;成為保障通信質量、降低功耗及維持信號穩定的決定性因素。 AT2401C是一款面向2.4GHz無線通信…

Linux安裝jdk、tomcat

1、安裝jdk sudo yum install -y java-1.8.0-openjdk-devel碰到的問題&#xff1a;/var/run/yum.pid 已被鎖定 Another app is currently holding the yum lock&#xff1b; waiting for it to exit… https://blog.csdn.net/u013669912/article/details/131259156 參考&#…

在本地電腦中部署阿里 Qwen3 大模型及連接到 Elasticsearch

在今天的文章中&#xff0c;我將參考文章 “使用 Elastic 和 LM Studio 的 Herding Llama 3.1” 來部署 Qwen3 大模型。據測評&#xff0c;這是一個非常不錯的大模型。我們今天嘗試使用 LM Studio 來對它進行部署&#xff0c;并詳細描述如何結合 Elasticsearch 來對它進行使用。…

【設計模式】2.策略模式

every blog every motto: You can do more than you think. https://blog.csdn.net/weixin_39190382?typeblog 0. 前言 商場收銀軟件為例 1. 基礎版 total 0def click_ok(price,num):tot price * numtotal totprint(合計&#xff1a;, total)增加打折 total 0def cli…