c# - 如何更改按下键盘按键时的 TrackBar 控件操作?

标签 c# .net vb.net winforms

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/

相关文章:

c# - GroupBox 中是否有任何属性指示已检查嵌套控件?

c# - 序列不包含具有 LINQ FirstOrDefault 的元素

c# - Windows 登录的使用条件对话框

c# - ASP.NET 动态更改用户控件源

vb.net - VB6调用VB.NET调用第三方COM dll错误

c# - WPF 绑定(bind)警告

c# - 在异步方法内部调用时,方法是否必须是异步的?

c# - C#嵌套Elasticsearch将GUID转换为数组

vb.net - 将希腊字符转换为 Unicode

asp.net - 在 VB.NET 中组合 B 列中的数据库单元格以匹配 A 列中的单元格