GDI绘图基本,持续更新

来源:互联网 发布:compareto java用法 编辑:程序博客网 时间:2024/06/06 17:28

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace examplehuitu2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Paint(object sender, PaintEventArgs e)    {        Graphics g = this.CreateGraphics();        Pen p = new Pen(Color.Blue, 5);        //画虚线        p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;//定义虚线样式为点        g.DrawLine(p, 10, 10, 300, 10);        //自定义画虚线        p.DashPattern = new float[] { 2, 1 };//自定义短划线和空白的数组        g.DrawLine(p, 10, 20, 300, 20);        //画箭头        p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;//样式恢复为实线        p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;//结尾定义为箭头        g.DrawLine(p, 10, 30, 300, 30);        //填充矩形        Rectangle rect = new Rectangle(50, 50, 50, 50);//定义一个新矩形        SolidBrush b1 = new SolidBrush(Color.Blue);        g.FillRectangle(b1, rect);        //字符串        g.DrawString("主机", new Font("宋体", 10), b1, new PointF(50, 150));        //使用图片填充        TextureBrush b2 = new TextureBrush(Image.FromFile(@"D:\影音\照片\手机也能出好片\IMG_20170713_190754ss.jpg"));        rect.Location = new Point(50, 200);        rect.Width = 300;        rect.Height = 400;        g.FillRectangle(b2, rect);        //渐变色填充        rect.Location = new Point(50, 700);        LinearGradientBrush b3 = new LinearGradientBrush(rect,Color.Yellow,Color.Black,LinearGradientMode.Horizontal);//左黄右黑        g.FillRectangle(b3, rect);        //绘制扇形,使用扇形实际填充详见慕课162页        g.DrawPie(p, 300, 300, 100, 100, 60, 120);        //绘制圆弧        rect.Location = new Point(500, 300);        g.DrawArc(p, rect, 0, 120);        //转换坐标角度        Pen pe = new Pen(Color.Blue, 1);        for (int i = 0; i < 90; i++)        {            g.RotateTransform(i);//每旋转一度就画一条线(通过for循环)            g.DrawLine(pe, 0, 0, 100, 0);            g.ResetTransform();//恢复坐标轴        }        //平移坐标轴        g.TranslateTransform(0, 1000);        g.DrawLine(pe, 0, 0, 300, 0);        g.ResetTransform();        //平移坐标轴后进行旋转        g.TranslateTransform(100, 500);        for (int i = 0; i < 8; i++)        {            g.RotateTransform(45);            g.DrawLine(pe, 0, 0, 100, 0);        }        g.ResetTransform();    }}

}

原创粉丝点击