禁用调度器控件上的箭头键 [英] disable arrow key on scheduler control

查看:148
本文介绍了禁用调度器控件上的箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法来禁用左右箭头键?因为我不想让用户在 10 October 之前看到一个日期,而且在 16 october之后的日期





我尝试这段代码

  private void schedulerControl1_KeyDown(object sender,KeyEventArgs e)
{
if(e.KeyCode == Keys.Right)
{

e.Handled = true;
}
}

仍然可以点击箭头键,我已经检查 schedulercontrol 属性没有 keypreview 。或者可能设置为禁用用户不能点击或专注于单元格



nb:iam使用 devexpress 与组件调度程序

解决方案

可以使用IKeyboardHandlerService。

  public partial class Form1:Form 
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender,EventArgs e)
{
IKeyboardHandlerService oldKeyboardHandler =(IKeyboardHandlerService)schedulerControl1.GetService(typeof(IKeyboardHandlerService));
if(oldKeyboardHandler!= null)
{
MyKeyboardHandlerService newKeyboardHandler = new MyKeyboardHandlerService(schedulerControl1,oldKeyboardHandler);
schedulerControl1.RemoveService(typeof(IKeyboardHandlerService));
schedulerControl1.AddService(typeof(IKeyboardHandlerService),newKeyboardHandler);
}
}
}

public class MyKeyboardHandlerService:KeyboardHandlerServiceWrapper
{
IServiceProvider provider;

public MyKeyboardHandlerService(IServiceProvider provider,IKeyboardHandlerService service)
:base(service)
{
this.provider = provider;
}

public override void OnKeyDown(KeyEventArgs e)
{
if(!(e.KeyCode == Keys.Left || e.KeyCode == Keys .Right))
base.OnKeyDown(e);
}
}


is there a way to disable arrow key right and left ? because i dont want user to see a date before 10 october and date after 16 october

i have try this code

       private void schedulerControl1_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.KeyCode == Keys.Right)
        {

            e.Handled = true;
        }
    }

it still can click arrow key, and i have check that schedulercontrol properties got no keypreview. or maybe set disable for user cant click or focus on cell

n.b : iam using devexpress with component scheduler

解决方案

You can utilize IKeyboardHandlerService.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        IKeyboardHandlerService oldKeyboardHandler = (IKeyboardHandlerService)schedulerControl1.GetService(typeof(IKeyboardHandlerService));
        if (oldKeyboardHandler != null)
        {
            MyKeyboardHandlerService newKeyboardHandler = new MyKeyboardHandlerService(schedulerControl1, oldKeyboardHandler);
            schedulerControl1.RemoveService(typeof(IKeyboardHandlerService));
            schedulerControl1.AddService(typeof(IKeyboardHandlerService), newKeyboardHandler);
        }
    }
}

public class MyKeyboardHandlerService : KeyboardHandlerServiceWrapper
{
    IServiceProvider provider;

    public MyKeyboardHandlerService(IServiceProvider provider, IKeyboardHandlerService service)
        : base(service)
    {
        this.provider = provider;
    }

    public override void OnKeyDown(KeyEventArgs e)
    {
        if (!(e.KeyCode == Keys.Left|| e.KeyCode == Keys.Right))
                        base.OnKeyDown(e);
    }
}

这篇关于禁用调度器控件上的箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆