diff options
Diffstat (limited to 'src/CS340.Plotter')
-rw-r--r-- | src/CS340.Plotter/CS340.Plotter.csproj | 4 | ||||
-rw-r--r-- | src/CS340.Plotter/Plot.Designer.cs | 21 | ||||
-rw-r--r-- | src/CS340.Plotter/Plot.cs | 36 |
3 files changed, 49 insertions, 12 deletions
diff --git a/src/CS340.Plotter/CS340.Plotter.csproj b/src/CS340.Plotter/CS340.Plotter.csproj index de15111..7a10161 100644 --- a/src/CS340.Plotter/CS340.Plotter.csproj +++ b/src/CS340.Plotter/CS340.Plotter.csproj @@ -7,8 +7,4 @@ <RootNamespace>Plotter</RootNamespace> </PropertyGroup> - <ItemGroup> - <PackageReference Include="System.Windows.Forms.DataVisualization" Version="1.0.0-prerelease.20110.1" /> - </ItemGroup> - </Project>
\ No newline at end of file diff --git a/src/CS340.Plotter/Plot.Designer.cs b/src/CS340.Plotter/Plot.Designer.cs index c1a6b5f..36d9a56 100644 --- a/src/CS340.Plotter/Plot.Designer.cs +++ b/src/CS340.Plotter/Plot.Designer.cs @@ -29,20 +29,37 @@ namespace Plotter /// </summary> private void InitializeComponent() { + this.Canvas = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.Canvas)).BeginInit(); this.SuspendLayout(); // + // Canvas + // + this.Canvas.Dock = System.Windows.Forms.DockStyle.Fill; + this.Canvas.Location = new System.Drawing.Point(0, 0); + this.Canvas.Name = "Canvas"; + this.Canvas.Size = new System.Drawing.Size(604, 368); + this.Canvas.TabIndex = 0; + this.Canvas.TabStop = false; + this.Canvas.SizeChanged += new System.EventHandler(this.Canvas_SizeChanged); + this.Canvas.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Canvas_MouseDown); + // // Plot // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(604, 368); + this.Controls.Add(this.Canvas); this.Name = "Plot"; - this.Text = "Form1"; + this.Text = "Plot"; + ((System.ComponentModel.ISupportInitialize)(this.Canvas)).EndInit(); this.ResumeLayout(false); } #endregion + + private System.Windows.Forms.PictureBox Canvas; } } diff --git a/src/CS340.Plotter/Plot.cs b/src/CS340.Plotter/Plot.cs index 7b274d8..f26978f 100644 --- a/src/CS340.Plotter/Plot.cs +++ b/src/CS340.Plotter/Plot.cs @@ -1,21 +1,45 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace Plotter { public partial class Plot : Form { + Random rand = new Random(); public Plot() { InitializeComponent(); + Render(); + } + void Render() + { + using var bmp = new Bitmap(Canvas.Width, Canvas.Height); + using var gfx = Graphics.FromImage(bmp); + using var pen = new Pen(Color.White); + // draw one thousand random white lines on a dark blue background + gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + gfx.Clear(Color.Navy); + for (int i = 0; i < 1000; i++) + { + var pt1 = new Point(rand.Next(bmp.Width), rand.Next(bmp.Height)); + var pt2 = new Point(rand.Next(bmp.Width), rand.Next(bmp.Height)); + gfx.DrawLine(pen, pt1, pt2); + } + + // copy the bitmap to the picturebox (double buffered) + Canvas.Image?.Dispose(); + Canvas.Image = (Bitmap)bmp.Clone(); + } + + private void Canvas_SizeChanged(object sender, EventArgs e) + { + Render(); } + private void Canvas_MouseDown(object sender, MouseEventArgs e) + { + Render(); + } } } |