当前位置: 首页 > news >正文

自定义控件----流动线条

实现效果如下:

 

微信截图_20250729085939

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
internal class Mybutton : Button
{
int offset = 0;//定义流动条得偏移量
Timer timer = null;//流动条流动定时器
//定义多边形点位
Point point1, point2, point3, point4, point5, point7, point8;
Point[] points = null;
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);

}
//构造方法用于处理事件
public Mybutton()
{
timer = new Timer();
timer.Interval = 100; // 设置定时器间隔为50毫秒
timer.Tick += new EventHandler(TimerTick);
timer.Start();
}

//定义阀门的颜色属性
private Color _valuecolor = Color.Red;
[Description("阀门颜色"), Category("自定义")]
public Color ValueColor
{
get
{
return _valuecolor;
}
set
{
_valuecolor = value;
Refresh();//刷新控件
}
}

protected override void OnPaint(PaintEventArgs pevent)//重绘方法
{
base.OnPaint(pevent);//执行基类自己得方法
this.Text = "";
point1 = new Point(this.Width / 4, this.Height / 3);
point2 = new Point(this.Width / 4, this.Height / 3 * 2);
point3 = new Point(this.Width / 2, this.Height / 2);
point4 = new Point(this.Width / 4 * 3, this.Height / 3);
point5 = new Point(this.Width / 4 * 3, this.Height / 3 * 2);
points = new Point[] { point1, point2, point3, point4, point5 };

Graphics graphics = pevent.Graphics;//获得画板
graphics.DrawPolygon(new Pen(ValueColor), points);//画多边形
graphics.FillPolygon(new SolidBrush(ValueColor), points);//填充图形

//画流动线
Pen pen1 = new Pen(ValueColor, 10);
pen1.DashStyle = DashStyle.Dash;
pen1.DashPattern = new float[] { 5, 2 };
graphics.DrawLine(pen1, offset, this.Height / 2, this.Width + offset, this.Height / 2);

}

private void TimerTick(object sender, EventArgs e)
{

offset += 2; // 每次定时器触发,移动偏移量
if (offset > 100) offset = 0; // 如果偏移量过大,重置为0,这里可以根据需要调整重置条件
this.Invalidate();// 请求重绘窗体
}

}
}

http://www.vanclimg.com/news/1318.html

相关文章:

  • 2023年八大最佳Codecademy替代平台
  • CF2018D 题解
  • Apple MagicKeyboard
  • 剑指offer-16、合并两个有序链表
  • 区分引用变量和内表变量
  • 线程
  • 进程
  • 进程API函数
  • 〆250729〆Windows 系统中 C:\ProgramData 目录说明
  • .NET 10 中的新增功能系列文章1——运行时中的新增功能
  • cv2安装测试的一个案例-面部检测
  • gitlab重置管理员root密码
  • 线程API
  • 1000子读后感
  • Teamcenter: 度量单位
  • .NET 9 的免费午餐:GZip 性能提升38.3%
  • 暑假本校集训
  • 20250729-33
  • FHQ Treap 学习笔记
  • C#/.NET/.NET Core技术前沿周刊 | 第 48 期(2025年7.21-7.27)
  • Metasploit Pro 4.22.8-2025071801 (Linux, Windows) - 专业渗透测试框架
  • test的启动方法
  • Lombok @Builder失效问题排查与解决方案
  • 亚马逊Q Developer:用自然语言构建机器学习模型
  • day07
  • 读心与芯:我们与机器人的无限未来08计算思维
  • 前馈电容技术解析!
  • 7/29
  • js高级第一天
  • Git 小白极速入门笔记