c#绘制图形

news2024/9/25 19:16:19

窗体工具控件 

如果选纹理 ,需要在ImageList选择图像(点击添加选择图片路径)

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 画
{
    public partial class Form1 : Form
    {//重写窗体 Form1 的 OnPaint()方法 
        protected override void OnPaint(PaintEventArgs e) {
            //调用基类的 Onpain()方法绘制窗体
            base.OnPaint(e);
            //添加自己的代码绘制图形
            Graphics g = e.Graphics;
            Pen pen = new Pen(Color.Red, 5);
            PointF[] Tpoit = new PointF[] { new PointF(26, 50),new PointF(90, 80),
              new PointF(190, 180), new PointF(26, 50)        };//多边形之三角形
                                                       
            g.DrawEllipse(pen, 20, 30, 230, 80);//椭圆
            g.DrawPolygon(pen, Tpoit);
            g.Dispose();
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void btnDrowLine_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();//创建 Graphics 对象
            Pen pen = new Pen(Color.Red,3);
            Point startpoit = new Point(50, 80);
            Point endpoint = new Point(250, 80);
            g.DrawLine(pen ,startpoit,endpoint);//画直线 
            pen .Dispose();//释放资源
            g.Dispose();

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            Graphics d = this.CreateGraphics();
            d.Clear(BackColor);
            d.Dispose ();
                               }

        private void tuoyuan_Click(object sender, EventArgs e)
        {
            Graphics g = CreateGraphics();
            SolidBrush brush = new SolidBrush(Color.Green); //画刷 
            g.FillEllipse(brush, 120, 30, 200, 100); //画实心椭圆 
            g.Dispose();
            brush.Dispose();

        }
        
//声明画刷
private Brush brush = new SolidBrush(Color.Red);
        

        private void radioButton1_CheckedChanged(object sender, EventArgs e)//实心
        {
            brush = new SolidBrush(Color.Green); //参数为填充的颜色
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)//纹理
        {
            brush = new TextureBrush(imageList1.Images[0]); //参数为填充的图/拖入imageList控件
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)//渐变
        {

            Point startPoint = new Point(80, 70);
            Point endPoint = new Point(310, 70);
            brush = new LinearGradientBrush(startPoint, endPoint, Color.Red, Color.Yellow);
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)//阴影
        {
            brush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Red, Color.LightGreen);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = CreateGraphics();
            g.FillEllipse(brush, 80, 30, 230, 80);
            g.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //定义路径中的顶点
            Point[] pt = new Point[10];
            pt[0] = new Point(120, 46);
            pt[1] = new Point(156, 46);
            pt[2] = new Point(168, 10);
            pt[3] = new Point(180, 46);
            pt[4] = new Point(214, 46);
            pt[5] = new Point(188, 70);
            pt[6] = new Point(198, 106);
            pt[7] = new Point(168, 82);
            pt[8] = new Point(138, 104);
            pt[9] = new Point(150, 70);
            GraphicsPath path = new GraphicsPath(); //创建路径 
            for (int i = 0; i <= 8; i++)
            {
                path.AddLine(pt[i], pt[i + 1]); //添加线段
            }
            path.CloseFigure(); //闭合起点和终点
            Pen pen = new Pen(Color.Black, 5);
            Graphics g = CreateGraphics();
            SolidBrush brush = new SolidBrush(Color.Blue); //画刷 
            g.FillPath(brush, path);//填充颜色
           g.DrawPath(pen, path);//单绘制路径
            g.Dispose();
            path.Dispose();
        }
    }
}

运行效果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1542191.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【JavaEE初阶系列】——阻塞队列

目录 &#x1f6a9;阻塞队列的定义 &#x1f6a9;生产者消费者模型 &#x1f388;解耦性 &#x1f388;削峰填谷 &#x1f6a9;阻塞队列的实现 &#x1f4dd;基础的环形队列 &#x1f4dd;阻塞队列的形成 &#x1f4dd; 内存可见性 &#x1f4dd;阻塞队列代码 &#…

MQ高级篇---消息可靠性

MQ的一些常见问题 后面内容基于springboot 2.3.9.RELEASE 消息可靠性 生产者确认机制 在publisher微服务中application.yml中添加 spring:rabbitmq:publisher-confirm-type: correlatedpublisher-returns: truetemplate:mandatory: true每个RabbitTemplate只能配置一个Return…

vscode配置c/c++调试环境

本文记录win平台使用vscode远程连接ubuntu server服务器下&#xff0c;如何配置c/c调试环境。 过程 1. 服务器配置编译环境 这里的前置条件是vscode已经能够连接到服务器&#xff0c;第一步安装编译构建套件&#xff08;gcc、g、make、链接器等&#xff09;和调试器&#xf…

Vue2(十):全局事件总线、消息订阅与发布、TodoList的编辑功能、$nextTick、动画

一、全局事件总线&#xff01;&#xff01; 任意组件间通信 比如a想收到别的组件的数据&#xff0c;那么就在a里面给x绑定一个demo自定义事件&#xff0c;所以a里面就得有一个回调函数吧&#xff0c;然后我要是想让d组件给a穿数据&#xff0c;那就让d去触发x的自定义事件&…

使用html做一个2048小游戏

下载地址: https://pan.xunlei.com/s/VNtiF13HxmmE4gglflvS1BUhA1?pwdvjrt# 提取码&#xff1a;vjrt”

C#执行命令行

效果图 主要代码方法 private Process p;public List<string> ExecuteCmd(string args){System.Diagnostics.Process p new System.Diagnostics.Process();p.StartInfo.FileName "cmd.exe";p.StartInfo.RedirectStandardInput true;p.StartInfo.RedirectSta…

STM32--RC522学习记录

一&#xff0c;datasheet阅读记录 1.关于通信格式 2.读寄存器 u8 RC522_ReadReg(u8 address) {u8 addr address;u8 data0x00;addr((addr<<1)&0x7e)|0x80;//将最高位置一表示read&#xff0c;最后一位按照手册建议变为0Spi_Start();//选中从机SPI2_ReadWriteByte(ad…

C++实现FFmpeg音视频实时拉流并播放

1.准备工作: 下载rtsp流媒体服务器rtsp-simple-server,安装go开发环境并编译 编译好后启动流媒体服务器 准备一个要推流的mp4视频文件,如db.mp4 使用ffmpeg开始推流 推流命令: ffmpeg -re -stream_loop -1 -i db.mp4 -c copy -rtsp_transport tcp -f rtsp rtsp://192.168.16…

JVM快速入门(2)HotSpot和堆、新生区、永久区、堆内存调优、JProfiler工具分析OOM原因、GC(垃圾回收)、JVM经典面试笔试题整理

5.6 HotSpot和堆 5.6.1 Hotspot 三种JVM&#xff1a; Sun公司&#xff0c;HotspotBEA&#xff0c;JRockitIBM&#xff0c;J9 VM&#xff0c;号称是世界上最快的Java虚拟机 我们一般学习的是&#xff1a;HotSpot 5.6.2 堆 Heap&#xff0c;一个JVM只有一个堆内存&#xff0c…

基于51单片机数控直流电压源proteus仿真LCD显示+程序+设计报告+讲解视频

基于51单片机数控直流电压源proteus仿真LCD显示( proteus仿真程序设计报告讲解视频&#xff09; 仿真图proteus7.8及以上 程序编译器&#xff1a;keil 4/keil 5 编程语言&#xff1a;C语言 设计编号&#xff1a;S0072 讲解视频 基于51单片机数控直流电压源proteus仿真程序…

t-rex2开放集目标检测

论文链接&#xff1a;http://arxiv.org/abs/2403.14610v1 项目链接&#xff1a;https://github.com/IDEA-Research/T-Rex 这篇文章的工作是基于t-rex1的工作继续做的&#xff0c;核心亮点&#xff1a; 是支持图片/文本两种模态的prompt进行输入&#xff0c;甚至进一步利用两…

八股文(1)

管道 匿名管道和命名管道 命名管道的使用是什么&#xff1f;在linux系统如何实现 命名管道&#xff08;Named Pipe&#xff09;&#xff0c;也称为FIFO&#xff08;First In First Out&#xff09;&#xff0c;是一种在UNIX和Linux系统中用于进程间通信&#xff08;IPC&…

【PyQt】17.1-日历控件 不同风格的日期和时间、以及高级操作

日历控件puls版本 前言一、日历控件中不同风格的日期和时间1.1 代码1.2 注意事项格式设置m的大小写问题QTime和QDateTime的区别 1.3 运行结果 二、高级操作2.1 成倍调整2.2 下拉出日历2.3 事件函数2.4 获取设置的日期和时间 完整代码 前言 1、不同风格的日期和时间展示 2、高级…

Django下载使用、文件介绍

【一】下载并使用 【1】下载框架 &#xff08;1&#xff09;注意事项 计算机名称不要出现中文python解释器版本不同可能会出现启动报错项目中所有的文件名称不要出现中文多个项目文件尽量不要嵌套,做到一项一夹 &#xff08;2&#xff09;下载 Django属于第三方模块&#…

无人机摄影测量---倾斜摄影测量原理与关键技术

《无人机航空摄影测量精品教程》专栏&#xff1a;无人机航测外业作业流程&#xff08;像控点布设、航线规划、仿地飞行、航拍&#xff09;和内业数据处理软件&#xff08;Pix4d、CC、EPS、PhotoScan、Globalmapper&#xff09;像控点权重调配、空三加密、DOM、DSM、DEM&#xf…

ubuntu18安装opensips3.4,开启ws/wss/http接口模块

、如果是centos 7安装则使用yum 命令。 添加库地址注意系统类型&#xff0c;选择对应的系统类型和版本 curl https://apt.opensips.org/opensips-org.gpg -o /usr/share/keyrings/opensips-org.gpg echo "deb [signed-by/usr/share/keyrings/opensips-org.gpg] https:/…

芯片工程系列(5)2.5D 3D封装

0 英语缩写 硅通孔&#xff08;Through Silicon Via&#xff0c;TSV&#xff09;硅中介层&#xff08;Silicon Interposer&#xff09;物理气象沉淀法&#xff08;Physical Vapor Deposition&#xff0c;PVD&#xff09;DRIE、CVD、PVD、CMP等设备CoWoS&#xff08;Chip on Wa…

政安晨:【深度学习实践】【使用 TensorFlow 和 Keras 为结构化数据构建和训练神经网络】(五)—— Dropout和批归一化

政安晨的个人主页&#xff1a;政安晨 欢迎 &#x1f44d;点赞✍评论⭐收藏 收录专栏: TensorFlow与Keras实战演绎 希望政安晨的博客能够对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff01; Dropout和批归一化是深度学习领域中常用的正则化技术…

pytorch如何向tensor结尾添加元素或维度--torch.cat()、torch.unsqueeze()的用法

目录 示例1 矢量后增加元素 示例2 tensor维度增加1 示例3 另一种替代unsqueeze的方法 示例1 矢量后增加元素 使用torch.cat()函数 ptorch.Tensor([1,5,0]) ptorch.cat((p, torch.Tensor([4])), 0) 结果&#xff1a; 这里&#xff0c;cat的第一个输入变量用()包绕&#xf…

中断(NVIC)的使用--EXTI--TIM

目录 中断是什么 轮询 中断 中断调用情况 中断的分类 内部中断&#xff08;TIM、UART等&#xff09; tim.c tim.h 外部中断EXTI exti.c exti.h 中断是什么 在处理事件的时候有两种方式&#xff1a;轮询和中断。 轮询 顾名思义&#xff0c;就是每轮都询问一次。比如…