c#画直线
c# 直线
2023-09-11 14:21:59 时间
c#画直线
本文实例讲述了C#使用GDI绘制矩形的方法。分享给大家供大家参考。具体实现方法如下:
1 2 3 |
|
代码
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 WindowsFormsApp11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//创建Graphics对象
Graphics GPS = this.CreateGraphics();
//创建黑色pen对象
Pen MyPen = new Pen(Color.Black, 2f);
//确定起点和终点
Point pt1 = new Point(70, 20);
Point pt2 = new Point(200, 320);
//使用DrawLine方法绘制直线
GPS.DrawLine(MyPen, pt1, pt2);
}
private void button2_Click(object sender, EventArgs e)
{
Graphics GPS = this.CreateGraphics();
Pen MyPen = new Pen(Color.Red, 2f);
GPS.DrawLine(MyPen, 50,20,300,200);
}
}
}
运行结果
相关文章
- C#子线程中更新ui-----c# 多线程多文件批量下载
- C# 第三方DLL,可以实现PDF转图片,支持32位系统、64位系统
- C#基础知识之方法重载总结
- [C#] c# 验证手机号码 最新的17手机号
- Win10系列:C#应用控件进阶6
- C#.NET常见问题(FAQ)-如何在不同窗体之间传递值
- C#.NET常见问题(FAQ)-Combobox如何设置不可以编辑
- C#如何设置窗体不能修改大小
- c# string 扩展方法
- C# 字符串操作--减少垃圾回收压力
- Atitit usbQb212 oo 面向对象封装的标准化与规范解决方案java c# php js
- C# 委托(Delegate)
- C#红包波动系数·高可用性,适合企业级开发
- (八十五)c#Winform自定义控件-引用区块-HZHControls
- C#里在子窗口与父窗口之间进行数据传送