disable arrow key on scheduler control

泪湿孤枕 提交于 2019-12-12 03:04:38

问题


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


回答1:


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);
    }
}



回答2:


Refer these DevExpress threads which may be similar to your requirement and the SchedulerControl.LimitInterval Property of the control:

Restrict TimelineView to show only selected date range
Scheduler: Limit days/hours displayed in Gantt-view
Restricting Date Range in Schedule Control, TimeScale view
Limit timeline view to specified interval (1 day?)
Timeline view : how to adjust the number of visible days



来源:https://stackoverflow.com/questions/40018903/disable-arrow-key-on-scheduler-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!