在 C# 中,旋扭控件(Knob control)是一个非常直观的控件,它通常用于表示进度、音量控制或旋转调整器等。在 Windows Forms 中,并没有直接提供旋扭控件,但你可以通过自定义绘制和处理鼠标事件来实现一个简单的旋扭控件。
下面是一个简单的旋扭控件示例,使用 C# 和 Windows Forms 来实现:
1. 创建旋扭控件
using System;
using System.Drawing;
using System.Windows.Forms;
public class KnobControl : Control
{
private float _value;
private float _minValue = 0f;
private float _maxValue = 100f;
private float _startAngle = -90f;
private float _endAngle = 270f;
private bool isRotating = false;
private PointF center;
public KnobControl()
{
this.Width = 150;
this.Height = 150;
this.DoubleBuffered = true; // 防止闪烁
this.Center = new PointF(this.Width / 2, this.Height / 2);
}
public float Value
{
get { return _value; }
set
{