Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsFormsApplication3
- {
- public partial class Form1 : Form
- {
- float slope;
- int yintercept;
- private void button1_Click(object sender, EventArgs e)
- {
- slope = float.Parse(textBox1.Text);
- yintercept = int.Parse(textBox2.Text);
- drawLine();
- }
- PictureBox pb;
- Pen pen = new Pen(Color.Black, 5);
- Pen gridPen = new Pen(Color.DarkGray, 2);
- Pen pointPen = new Pen(Color.Black, 15);
- Pen linePen = new Pen(Color.Black, 1);
- Bitmap surface;
- Graphics device;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- pb = new PictureBox();
- pb.Parent = this;
- pb.Dock = DockStyle.Fill;
- pb.BackColor = Color.White;
- this.Text = "Graph Drawing";
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.Size = new Size(1500, 800);
- surface = new Bitmap(1500, 800);
- pb.Image = surface;
- device = Graphics.FromImage(surface);
- drawGrid();
- drawPlane();
- }
- public void drawPlane()
- {
- device.DrawLine(pen, 100, 0, 100, 800);
- device.DrawLine(pen, 0, 700, 1500, 700);
- pb.Image = surface;
- }
- public void drawGrid()
- {
- for (int i = 0; i < 1500; i += 50)
- {
- device.DrawLine(gridPen, i, 0, i, 800);
- }
- for (int j = 0; j < 800; j += 50)
- {
- device.DrawLine(gridPen, 0, j, 1500, j);
- }
- pb.Image = surface;
- }
- public void drawLine()
- {
- yintercept *= 50;
- float x = 0;
- float y = 0;
- for (int k = 0; k < 1500; k++)
- {
- x++;
- y = x * -slope - yintercept;
- device.DrawLine(linePen, x + 100, y + 700, x + 99, y + 701);
- }
- pb.Image = surface;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement