문제

나는 새로운 C#고 어떤 일에서 기존 응용 프로그램.나는 DirectX 뷰포트 구성 요소에 그것이 내가 원하는 위치를 있을 사용하여 화살표 키를 이용하시면 됩니다.

현재 저는 재정의 ProcessCmdKey 잡는 화살표를 입력하고 보내는 OnKeyPress 이벤트입니다.이 작품은,그러나 내가 원하는 사용할 수 있도록 수정(ALT+CTRL+이동).한 빨리 나가를 들고 수정 및 눌러 화살표 이벤트가 트리거되는 내가 듣고있다.

누군가에 대한 아이디어나 제안 사항이 있는 곳에 나와 함께 가야한 이?

도움이 되었습니까?

해결책

내 재정의 ProcessCmdKey 어떻게 당신이 결정하는 키를 누르면?

의 가치 keyData(두 번째 매개 변수)을 변경에 따라 키를 누르면 어떤 키를,그래서 예를 들어 왼쪽 화살표를 누르면 반드 37,shift-왼쪽을 반환 65573,ctrl+왼쪽 131109 및 alt-왼쪽 262181.

추출할 수 있 수정 및 키를 누르면 ANDing 으로 적절한 열거 값:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    bool shiftPressed = (keyData & Keys.Shift) != 0;
    Keys unmodifiedKey = (keyData & Keys.KeyCode);

    // rest of code goes here
}

다른 팁

I 회가 직접 참여 할 수있는 Tokabi 의 응답, 하지만 비교하는 키가 있는 몇 가지 추가에 대한 조언 StackOverflow.com 기.여기에 몇 가지 기능을 사용하는 데 도움을 단순화하다.

   public Keys UnmodifiedKey(Keys key)
    {
        return key & Keys.KeyCode;
    }

    public bool KeyPressed(Keys key, Keys test)
    {
        return UnmodifiedKey(key) == test;
    }

    public bool ModifierKeyPressed(Keys key, Keys test)
    {
        return (key & test) == test;
    }

    public bool ControlPressed(Keys key)
    {
        return ModifierKeyPressed(key, Keys.Control);
    }

    public bool AltPressed(Keys key)
    {
        return ModifierKeyPressed(key, Keys.Alt);
    }

    public bool ShiftPressed(Keys key)
    {
        return ModifierKeyPressed(key, Keys.Shift);
    }

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (KeyPressed(keyData, Keys.Left) && AltPressed(keyData))
        {
            int n = code.Text.IndexOfPrev('<', code.SelectionStart);
            if (n < 0) return false;
            if (ShiftPressed(keyData))
            {
                code.ExpandSelectionLeftTo(n);
            }
            else
            {
                code.SelectionStart = n;
                code.SelectionLength = 0;
            }
            return true;
        }
        else if (KeyPressed(keyData, Keys.Right) && AltPressed(keyData))
        {
            if (ShiftPressed(keyData))
            {
                int n = code.Text.IndexOf('>', code.SelectionEnd() + 1);
                if (n < 0) return false;
                code.ExpandSelectionRightTo(n + 1);
            }
            else
            {
                int n = code.Text.IndexOf('<', code.SelectionStart + 1);
                if (n < 0) return false;
                code.SelectionStart = n;
                code.SelectionLength = 0;
            }
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top