ТЕМА 29: Графични примитиви Линия

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
 
namespace line_ok
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); Draw();
        }
 
 
        public void Draw()
        {
 
 
 
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
 
            Graphics graph = Graphics.FromImage(bmp);
            Pen pen = new Pen(Color.Black);
            graph.DrawLine(pen, 10, 10, 100, 100);
            pictureBox1.Image = bmp;
 
        }
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
    }
}
  

1 задача: Изчертаване на линия с координати на крайните точки :(10, 10), (100, 100).

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
 
namespace line_ok
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); Draw();
        }
 
 
        public void Draw()
        {
 
 
 
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
 
            Graphics graph = Graphics.FromImage(bmp);
            Pen pen = new Pen(Color.Black);
            graph.DrawLine(pen, 10, 10, 100, 100);
            pictureBox1.Image = bmp;
 
        }
       
    }
}
 

2 задача: Изчертаване на триъгълник с координати на долния ляв ъгъл  x1 = 200, y1 =300 и страна a = 200.

     int a = 200, x1 = 200, y1 =300 , x2, y2, x3, y3; 
          x2 = x1 + a; 
            y2 = y1; 
            x3 = (x1 + x2) / 2; 
            int h = (int)(a * Math.Sqrt(3) / 2); 
            y3 = y1 - h; 
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height); 

            Graphics graph = Graphics.FromImage(bmp); 
            Pen pen = new Pen(Color.Red,2); 
             
            graph.DrawLine(pen, x1, y1, x2, y2); 
            graph.DrawLine(pen, x2, y2, x3, y3); 
            graph.DrawLine(pen, x3, y3, x1, y1); 
            pictureBox1.Image = bmp;
 

Търсене