TrackBar
控件的变化方向与更改时的变化方向相反:
向上翻页/向下翻页/向上翻页/向下翻页。
这里详细说明: Why does the Trackbar value decrease on arrow up/PgUp?
有没有办法解决/扭转这种行为?
答案 0 :(得分:2)
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);
}
}
答案 1 :(得分:2)
Idle_Mind的答案很好,实际上对我很有帮助,但它有一个缺点,就是当 Up <时,它会阻止控件引发ValueChanged
和public class ProperTrackBar : TrackBar
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
int oldValue = this.Value;
switch (keyData)
{
case Keys.Up:
this.Value = Math.Min(this.Value + this.SmallChange, this.Maximum);
break;
case Keys.Down:
this.Value = Math.Max(this.Value - this.SmallChange, this.Minimum);
break;
case Keys.PageUp:
this.Value = Math.Min(this.Value + this.LargeChange, this.Maximum);
break;
case Keys.PageDown:
this.Value = Math.Max(this.Value - this.LargeChange, this.Minimum);
break;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
if (Value != oldValue)
{
OnScroll(EventArgs.Empty);
OnValueChanged(EventArgs.Empty);
}
return true;
}
}
事件单击/ kbd>,向下, PageUp 或 PageDown 。所以,这是我的版本:
$('#idItem').value