-1-
-2-
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
label1.Text = "X: " + e.X + ", Y:" + e.Y + "\r\n Location ="+e.Location ;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
// Create four Pen objects with red,
// blue, green, and black colors and
// different widths
Pen redPen = new Pen(Color.Red, 1);
Pen bluePen = new Pen(Color.Blue, 2);
Pen greenPen = new Pen(Color.Green, 3);
Pen blackPen = new Pen(Color.Black, 4);
// Draw line using float coordinates
float x1 = 20.0F, y1 = 20.0F;
float x2 = 200.0F, y2 = 20.0F;
e.Graphics.DrawLine(redPen, x1, y1, x2, y2);
// Draw line using Point structure
Point p1 = new Point(20, 20);
Point p2 = new Point(20, 200);
e.Graphics.DrawLine(greenPen, p1, p2);
//Draw line using PointF structures
PointF ptf1 = new PointF(20.0F, 20.0f);
PointF ptf2 = new PointF(200.0F, 200.0f);
e.Graphics.DrawLine(bluePen, ptf1, ptf2);
// Draw line using integer coordinates
int X1 = 60, Y1 = 40, X2 = 250, Y2 = 100;
e.Graphics.DrawLine(blackPen, X1, Y1, X2, Y2);
//===================
//Create graphic object for the current form
Graphics gs = this.CreateGraphics();
//Create brush object
Brush br1 = new SolidBrush(Color.Red);
Brush br2 = new SolidBrush(Color.CadetBlue);
//Create pen objects
Pen p11 = new Pen(br1,10);
Pen p22 = new Pen(br2,10);
//Draw lines
gs.DrawLine(p11, new Point(20, 300), new Point(900, 300));
gs.DrawLine(p22, new Point(450, 10), new Point(450, 500));
//============
//Dispose of objects
redPen.Dispose();
bluePen.Dispose();
greenPen.Dispose();
blackPen.Dispose();
p11.Dispose();
p22.Dispose();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Pen redPen = new Pen(Color.Red,6);
float x1 = 00F, y1 = 0.0F;
float x2 = 300.0F, y2 = 300.0F;
e.Graphics.DrawLine(redPen, x1, y1, x2, y2);
Pen Pen2 = new Pen(Color.Blue, 12);
float x3 = 300F, y3 = 0.0F;
float x4 = 0.0F, y4 = 300.0F;
e.Graphics.DrawLine(Pen2, x3, y3, x4, y4);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
-3-
-4-