TrackBar
控件的变化方向与通过以下方式更改时应有的方向相反:
向上翻页/向下翻页/向上箭头/向下箭头。
这里详细提到了这一点: Why does the Trackbar value decrease on arrow up/PgUp?
有办法修复/扭转这种行为吗?
最佳答案
呃...我以前从来没有注意到这一点。这是我对 @Hans 的建议的看法:
public class MyTrackBar : TrackBar
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Up:
this.Value = Math.Min(this.Value + this.SmallChange, this.Maximum);
return true;
case Keys.Down:
this.Value = Math.Max(this.Value - this.SmallChange, this.Minimum);
return true;
case Keys.PageUp:
this.Value = Math.Min(this.Value + this.LargeChange, this.Maximum);
return true;
case Keys.PageDown:
this.Value = Math.Max(this.Value - this.LargeChange, this.Minimum);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
关于c# - 如何更改按下键盘按键时的 TrackBar 控件操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16801083/