Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11.  
  12. namespace WindowsFormsApplication3
  13. {
  14. public partial class Form1 : Form
  15. {
  16.  
  17. float slope;
  18. int yintercept;
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22.  
  23. slope = float.Parse(textBox1.Text);
  24. yintercept = int.Parse(textBox2.Text);
  25.  
  26. drawLine();
  27.  
  28. }
  29.  
  30.  
  31. PictureBox pb;
  32. Pen pen = new Pen(Color.Black, 5);
  33. Pen gridPen = new Pen(Color.DarkGray, 2);
  34. Pen pointPen = new Pen(Color.Black, 15);
  35. Pen linePen = new Pen(Color.Black, 1);
  36.  
  37.  
  38.  
  39. Bitmap surface;
  40. Graphics device;
  41.  
  42.  
  43.  
  44. public Form1()
  45. {
  46. InitializeComponent();
  47. }
  48.  
  49. private void Form1_Load(object sender, EventArgs e)
  50. {
  51. pb = new PictureBox();
  52. pb.Parent = this;
  53. pb.Dock = DockStyle.Fill;
  54. pb.BackColor = Color.White;
  55.  
  56. this.Text = "Graph Drawing";
  57. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  58. this.MaximizeBox = false;
  59. this.Size = new Size(1500, 800);
  60.  
  61. surface = new Bitmap(1500, 800);
  62. pb.Image = surface;
  63. device = Graphics.FromImage(surface);
  64.  
  65. drawGrid();
  66. drawPlane();
  67.  
  68.  
  69. }
  70.  
  71. public void drawPlane()
  72. {
  73.  
  74. device.DrawLine(pen, 100, 0, 100, 800);
  75. device.DrawLine(pen, 0, 700, 1500, 700);
  76.  
  77. pb.Image = surface;
  78.  
  79. }
  80.  
  81. public void drawGrid()
  82. {
  83. for (int i = 0; i < 1500; i += 50)
  84. {
  85. device.DrawLine(gridPen, i, 0, i, 800);
  86. }
  87.  
  88. for (int j = 0; j < 800; j += 50)
  89. {
  90. device.DrawLine(gridPen, 0, j, 1500, j);
  91. }
  92.  
  93. pb.Image = surface;
  94.  
  95. }
  96.  
  97. public void drawLine()
  98. {
  99. yintercept *= 50;
  100.  
  101. float x = 0;
  102. float y = 0;
  103.  
  104. for (int k = 0; k < 1500; k++)
  105. {
  106. x++;
  107. y = x * -slope - yintercept;
  108.  
  109.  
  110. device.DrawLine(linePen, x + 100, y + 700, x + 99, y + 701);
  111.  
  112. }
  113.  
  114. pb.Image = surface;
  115.  
  116. }
  117.  
  118. private void textBox1_TextChanged(object sender, EventArgs e)
  119. {
  120.  
  121. }
  122.  
  123. private void textBox2_TextChanged(object sender, EventArgs e)
  124. {
  125.  
  126. }
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement