111,094
社区成员




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace VolumeShow
{
public partial class VolumeShow : UserControl
{
private VerticalProgressBar _progressbar = new VerticalProgressBar();
public VolumeShow()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
OnForeColorChanged(EventArgs.Empty);
OnResize(EventArgs.Empty);
_progressbar.Minimum = 0;
_progressbar.Maximum = 100;
_progressbar.Left = pictureBox1.Left;
_progressbar.Width = 8;
_progressbar.Height = pictureBox1.Top-10;
this.Controls.Add(_progressbar);
}
public int Volume
{
get { return _progressbar.Value; }
set {
if (Math.Abs(_progressbar.Value - value) < 5) return;
_progressbar.Value = value>100 ? 100: value;
}
}
private void VolumeShow_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
Point[] ps = new Point[3];
ps[0].X = _progressbar.Location.X + _progressbar.Width;
ps[0].Y = _progressbar.Location.Y;
ps[1].X = _progressbar.Location.X + _progressbar.Width;
ps[1].Y = pictureBox1.Top-10;
ps[2].X = _progressbar.Location.X + _progressbar.Width + 16;
ps[2].Y = _progressbar.Location.Y;
g.FillPolygon(new SolidBrush(Color.LightGray), ps);
Pen pen = new Pen(Color.LightGray,1);
g.DrawLine(pen, new Point(_progressbar.Location.X + _progressbar.Width, _progressbar.Location.Y),
new Point( _progressbar.Location.X + _progressbar.Width + 20, _progressbar.Location.Y));
g.DrawLine(pen, new Point(_progressbar.Location.X + _progressbar.Width, (pictureBox1.Top - 10)/2),
new Point(_progressbar.Location.X + _progressbar.Width + 20, (pictureBox1.Top - 10)/2));
g.DrawLine(pen, new Point(_progressbar.Location.X + _progressbar.Width, pictureBox1.Top - 10),
new Point(_progressbar.Location.X + _progressbar.Width + 20, pictureBox1.Top-10));
g.Dispose();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VolumeShow
{
public partial class VerticalProgressBar : ProgressBar
{
public VerticalProgressBar()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= 0x04;
return cp;
}
}
}
}
订阅的代码
namespace VolumeShow
{
partial class VolumeShow
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = global::VolumeShow.Properties.Resources.Volume_son_24px_1075745_easyicon_net;
this.pictureBox1.InitialImage = null;
this.pictureBox1.Location = new System.Drawing.Point(0, 199);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(28, 24);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// VolumeShow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.pictureBox1);
this.Name = "VolumeShow";
this.Size = new System.Drawing.Size(48, 226);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.VolumeShow_Paint);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
}
}