using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("rama.jpg");
Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
g.DrawImage(bmp, this.ClientRectangle);
}
public static void Main() {
Application.Run(new Form1());
}
}
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
DrawImage with destination points
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("rama.jpg");
g.FillRectangle(Brushes.White, this.ClientRectangle);
Point[] destinationPoints = {
new Point(0, 0), // destination for upper-left point of original
new Point(100, 0), // destination for upper-right point of original
new Point(50, 100)};// destination for lower-left point of original
g.DrawImage(bmp, destinationPoints);
}
public static void Main() {
Application.Run(new Form1());
}
}
Fill the area 'bounded' by the path
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
GraphicsPath gp = new GraphicsPath();
gp.AddLine(10, 10, 10, 50);
gp.AddLine(10, 50, 50, 50);
gp.AddLine(50, 50, 50, 10);
gp.StartFigure();
gp.AddLine(60, 10, 60, 50);
gp.AddLine(60, 50, 100, 50);
gp.AddLine(100, 50, 100, 10);
gp.CloseFigure();
Rectangle r = new Rectangle(110, 10, 40, 40);
gp.AddEllipse(r);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Black, gp);
gp.Dispose();
}
public static void Main() {
Application.Run(new Form1());
}
}
Rotate the text through 45 degrees
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Font f = new Font("Times New Roman", 24);
g.DrawString("Rotation", f, Brushes.Black, 0, 0);
g.RotateTransform(45);
g.DrawString("Rotation", f, Brushes.Black, 0, 0);
}
public static void Main() {
Application.Run(new Form1());
}
}
Reset the transformation Translate by 30 pixels in vertical direction
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, ClientRectangle);
g.DrawEllipse(Pens.Black, 20, 20, 30, 50);
g.TranslateTransform(-15, 0);
g.DrawEllipse(Pens.Black, 20, 20, 30, 50);
g.ResetTransform();
g.TranslateTransform(0, 30);
g.DrawEllipse(Pens.Black, 20, 20, 30, 50);
}
public static void Main() {
Application.Run(new Form1());
}
}
Apply the scaling transformation(scale subsequent operations by 2x horizontally and 3x vertically)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
g.DrawRectangle(Pens.Black, 10, 10, 50, 50);
g.DrawEllipse(Pens.Black, 10, 10, 10, 10);
g.ScaleTransform(2.0f, 3.0f);
g.DrawRectangle(Pens.Black, 10, 10, 50, 50);
g.DrawEllipse(Pens.Black, 10, 10, 10, 10);
}
public static void Main() {
Application.Run(new Form1());
}
}
Transform and RotateTransform in a loop
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Font f = new Font(“Times New Roman”, 16);
for (float angle = 0; angle < 360; angle += 45)
{
g.ResetTransform();
g.TranslateTransform(ClientRectangle.Width / 2,
ClientRectangle.Height / 2);
g.RotateTransform(angle);
g.DrawString("Hello, World", f, Brushes.Black, 50, 0);
}
}
public static void Main() {
Application.Run(new Form1());
}
}
[/csharp]