您的位置:首页 > 科技 > IT业 > 中装建设为什么不涨_东莞市城市建设管理局_广告联盟app_南昌seo优化公司

中装建设为什么不涨_东莞市城市建设管理局_广告联盟app_南昌seo优化公司

2025/1/20 1:35:35 来源:https://blog.csdn.net/weixin_43050480/article/details/144299698  浏览:    关键词:中装建设为什么不涨_东莞市城市建设管理局_广告联盟app_南昌seo优化公司
中装建设为什么不涨_东莞市城市建设管理局_广告联盟app_南昌seo优化公司

C# GDI小熊进度条

在这里插入图片描述
1、添加自定义控件winform

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 xiaoxiong
{public partial class CustomControl1 : Control{private int progress;private const int BearWidth = 50;private const int BearHeight = 50;public int Progress{get { return progress; }set{if (value < 0) value = 0;if (value > 100) value = 100;progress = value;this.Invalidate(); // Force a repaint}}public CustomControl1(){InitializeComponent();}protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);Graphics g = e.Graphics;g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;// Draw the progress bar backgroundRectangle progressBarRect = new Rectangle(0, 0, this.Width, this.Height);g.FillRectangle(Brushes.LightGray, progressBarRect);// Calculate the width of the filled part of the progress barint filledWidth = (int)((double)this.Width * progress / 100);// Draw the filled part of the progress barg.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0, filledWidth, this.Height));// Draw the bear (simplified representation)int bearX = this.Width - BearWidth - 10; // Position the bear to the right of the progress barint bearY = (this.Height - BearHeight) / 2;g.FillEllipse(Brushes.Brown, bearX, bearY, BearWidth, BearHeight); // Bear's headg.FillEllipse(Brushes.Black, bearX + BearWidth / 4, bearY + BearHeight / 4, BearWidth / 2, BearHeight / 2); // Bear's left eyeg.FillEllipse(Brushes.Black, bearX + BearWidth * 3 / 4, bearY + BearHeight / 4, BearWidth / 2, BearHeight / 2); // Bear's right eyeg.DrawArc(Pens.Black, bearX + BearWidth / 4, bearY + BearHeight / 2, BearWidth / 2, BearHeight / 2, 0, 180); // Bear's left earg.DrawArc(Pens.Black, bearX + BearWidth * 3 / 4, bearY + BearHeight / 2, BearWidth / 2, BearHeight / 2, 0, -180); // Bear's right ear}}
}

2、编译后添加winform窗口并找到上面的CustomControl1 控件,根据定时器即可使用该控件

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 xiaoxiong
{public partial class Form1 : Form{private CustomControl1 bearProgressBar;public Form1(){InitializeComponent();bearProgressBar = new CustomControl1{Location = new Point(10, 10),Size = new Size(300, 50),Progress = 10 // Set initial progress};this.Controls.Add(bearProgressBar);}public int i = 0;private void timer1_Tick(object sender, EventArgs e){i=i+1;bearProgressBar.Progress = i;}}
}

源码:
https://download.csdn.net/download/weixin_43050480/90091764

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com