📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(284, 167);
this.Name = "Form1";
this.Text = "Form1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,5);
g.DrawLine(Mypen,1,1,100,50);
Point p1=new Point(1,50);
Point p2=new Point(100,1);
g.DrawLine(Mypen,p1,p2);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,5);
g.DrawEllipse(Mypen,1,1,80,40);
Rectangle rect=new Rectangle(85,1,165,40);
g.DrawEllipse(Mypen,rect);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,5);
g.DrawArc(Mypen,1,1,80,40,90,270);
Rectangle rect=new Rectangle(85,1,165,40);
g.DrawArc(Mypen,rect,0,90);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,2);
g.DrawPie(Mypen,1,1,80,40,90,270);
Rectangle rect=new Rectangle(85,1,165,40);
g.DrawArc(Mypen,rect,0,90);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,2);
g.DrawRectangle(Mypen,5,5,80,40);
Rectangle rect=new Rectangle(90,15,130,50);
g.DrawRectangle(Mypen,rect);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,2);
Point p1=new Point(50,50);
Point p2=new Point(70,25);
Point p3=new Point(100,30);
Point p4=new Point(120,85);
Point p5=new Point(80,100);
Point []p={p1,p2,p3,p4,p5};
g.DrawPolygon(Mypen,p);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,2);
Point p1=new Point(50,50);
Point p2=new Point(70,25);
Point p3=new Point(100,30);
Point p4=new Point(120,85);
g.DrawBezier(Mypen,p1,p2,p3,p4);
g.DrawBezier(Mypen,20,10,60,40,80,45,90,10);
*/
/*
Graphics g=this.CreateGraphics();
Pen Mypen=new Pen(Color.Blue,2);
Point p1=new Point(50,50);
Point p2=new Point(70,25);
Point p3=new Point(100,30);
Point p4=new Point(120,85);
Point p5=new Point(80,100);
Point []p={p1,p2,p3,p4,p5};
g.DrawClosedCurve(Mypen,p,.9F,System.Drawing.Drawing2D.FillMode.Alternate);
*/
/*
Graphics g=this.CreateGraphics();
GraphicsPath graphPath = new GraphicsPath();
graphPath.AddEllipse(0, 0, 200, 100);
graphPath.AddRectangle(new Rectangle(30, 6, 70, 80));
Pen blackPen = new Pen(Color.Black, 3);
g.DrawPath(blackPen, graphPath);
*/
/*
System.Drawing.Graphics formGraphics = this.CreateGraphics();
string drawString = "Sample Text";
System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
System.Drawing.SolidBrush drawBrush =
new System.Drawing.SolidBrush(System.Drawing.Color.Black);
float x = 20.0f;
float y = 20.0f;
formGraphics.DrawString(drawString, drawFont, drawBrush, x, y);
drawFont.Dispose();
drawBrush.Dispose();
formGraphics.Dispose();
*/
/*
System.Drawing.Graphics formGraphics = this.CreateGraphics();
string drawString = "Sample Text";
System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
float x = 50.0f;
float y = 10.0f;
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
drawFont.Dispose();
drawBrush.Dispose();
formGraphics.Dispose();
*/
try
{
System.Drawing.Graphics myGraphics = this.CreateGraphics();
Bitmap originalBitmap = new Bitmap("c:\\tt.bmp");
Rectangle sourceRectangle = new Rectangle(0,0, originalBitmap.Width,
originalBitmap.Height/2);
Bitmap secondBitmap = originalBitmap.Clone(sourceRectangle,System.Drawing.Imaging.PixelFormat.DontCare);
myGraphics.DrawImage(originalBitmap, 10, 10);
myGraphics.DrawImage(secondBitmap, 150, 10);
}
catch(Exception ee){Console.WriteLine(ee.Message);}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -