| | |
Graphing in PictureBox
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
I have been trying to get a simple linear equation to draw. I can draw the axis fine but the equation will not draw. I think one would need a save/refresh function(s), but I don't know how to go about doing this:
Thanks for any help. I should mention that I did declare all variables (x, y, m, and b). I'm just starting out with VC#, so that might explain the sloppy or simple code.
C# Syntax (Toggle Plain Text)
pw = pictureBox1.Size.Width; ph = pictureBox1.Size.Height; w = pictureBox1.Size.Width / 2; h = pictureBox1.Size.Height / 2; Graphics objGraphics = this.pictureBox1.CreateGraphics(); Pen pen = new Pen(Color.Black); b = 2; m = 2; for (x = 0; x < 426; x++) { y = m * x + b; x = (y - b) / m; objGraphics.DrawLine(pen, x, y, x, y); System.Drawing.Drawing2D.GraphicsState graph = objGraphics.Save(); objGraphics.Restore(graph); } objGraphics.DrawLine(pen, 0, h, pw, h); objGraphics.DrawLine(pen, w, 0, w, ph);
Last edited by metkillerjoe; Mar 17th, 2007 at 2:14 pm.
That is because you are plotting a point right on top of the original point.
I changed this line...
Here is the code I used...
Hope that helps
I changed this line...
C# Syntax (Toggle Plain Text)
objGraphic.DrawLine(pen, x, y, -x, -y);
C# Syntax (Toggle Plain Text)
int picBoxWidth = pictureBox1.Size.Width; int picBoxHeight = pictureBox1.Size.Height; int halfWidth = pictureBox1.Size.Width / 2; int halfHeight = pictureBox1.Size.Height / 2; Graphics objGraphic = this.pictureBox1.CreateGraphics(); Pen pen = new Pen(Color.Black); int b = 2; int m = 2; for (int x = 0; x < 426; x++) { int y = m * x + b; x = (y - b) / m; objGraphic.DrawLine(pen, x, y, -x, -y); System.Drawing.Drawing2D.GraphicsState graph = objGraphic.Save(); objGraphic.Restore(graph); } objGraphic.DrawLine(pen, 0, halfHeight, picBoxWidth, halfHeight); objGraphic.DrawLine(pen, halfWidth, 0, halfWidth, picBoxHeight);
Last edited by DDoSAttack; Mar 18th, 2007 at 3:37 am.
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
That is because you are plotting a point right on top of the original point.
I changed this line...
Here is the code I used...C# Syntax (Toggle Plain Text)
objGraphic.DrawLine(pen, x, y, -x, -y);
Hope that helpsC# Syntax (Toggle Plain Text)
int picBoxWidth = pictureBox1.Size.Width; int picBoxHeight = pictureBox1.Size.Height; int halfWidth = pictureBox1.Size.Width / 2; int halfHeight = pictureBox1.Size.Height / 2; Graphics objGraphic = this.pictureBox1.CreateGraphics(); Pen pen = new Pen(Color.Black); int b = 2; int m = 2; for (int x = 0; x < 426; x++) { int y = m * x + b; x = (y - b) / m; objGraphic.DrawLine(pen, x, y, -x, -y); System.Drawing.Drawing2D.GraphicsState graph = objGraphic.Save(); objGraphic.Restore(graph); } objGraphic.DrawLine(pen, 0, halfHeight, picBoxWidth, halfHeight); objGraphic.DrawLine(pen, halfWidth, 0, halfWidth, picBoxHeight);
![]() |
Similar Threads
- pictureBox problem.. please help me! (Visual Basic 4 / 5 / 6)
- Best Graphing software for Mac OSX (Mac Software)
Other Threads in the C# Forum
- Previous Thread: How to append string to string builder in C#
- Next Thread: Store Locator with C#
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





