Advertisement
Guest User

form1

a guest
Nov 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 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. namespace WindowsFormsApplication11
  12. {
  13. public partial class Form1 : Form
  14. {
  15. Bitmap b;
  16. Graphics g;
  17. Pen p;
  18. Line line1, line2;
  19. //Rectangle rec;
  20.  
  21.  
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. Init();
  26. Draw();
  27.  
  28. }
  29.  
  30. private void Init()
  31. {
  32. line1 = new Line(100, 100, 250, 10);
  33. line2 = new Line(250, 10, 400, 100);
  34. //rec = new rectangle(100, 100, 400, 300);
  35. p = new Pen(Color.Chocolate, 2);
  36. b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  37. g = Graphics.FromImage(b);
  38. pictureBox1.Image = b;
  39.  
  40. }
  41.  
  42.  
  43.  
  44. private void pictureBox1_Click(object sender, EventArgs e)
  45. {
  46.  
  47. }
  48.  
  49. private void Form1_Load(object sender, EventArgs e)
  50. {
  51. Draw();
  52. }
  53.  
  54. public void Draw()
  55. {
  56. Pen p = new Pen(Color.Chocolate, 20);
  57. Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  58. Graphics g = Graphics.FromImage(b);
  59. Point p1 = new Point(100, 100);
  60. Size s = new Size(300, 200);
  61. Rectangle r = new Rectangle(100, 100, 300, 200);
  62.  
  63. g.DrawLine(p, 100, 100, 250, 10);
  64. g.DrawLine(p, 250, 10, 400, 100);
  65.  
  66. g.DrawLine(p,450,30,600, 300);
  67. g.DrawLine(p,300,300, 450,30);
  68.  
  69.  
  70. g.DrawRectangle(p, r.x1, r.x2, r.y1, r.y2);
  71.  
  72. pictureBox1.Image = b;
  73. }
  74.  
  75. private void Draw(Line line)
  76. {
  77. g.DrawLine(p, line.x1, line.y1, line.x2, line.y2);
  78.  
  79. }
  80.  
  81. private void Draw(Rectangle r)
  82. {
  83. g.DrawRectangle(p, r.x1, r.x2, r.y1, r.y2);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement