当同时按住两个键时

时间:2016-12-16 19:26:17

标签: c# winforms

private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.Up:
                YUlt = YUlt - (PDiff + 10);
                Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour); 
                break;
            case Keys.Down:
                YUlt = YUlt + (PDiff + 10);
                Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour); 
                break;
            case Keys.Left:
                XUlt = XUlt - (PDiff + 10);
                Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour);
                break;
            case Keys.Right:
                XUlt = XUlt + (PDiff + 10);
                Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour);
                break;

        }

好的,我试图制作一个winform应用程序,用键盘绘制圆圈。这个程序使用NAIT创建的GDIDrawer界面,但对于这个问题并不重要,所以不要担心Draw.AddEllipse。

上面的开关盒可以很好地绘制红点,但是下面的if语句应该起作用的方式是当用户按住F1键并按下箭头键时,将被绘制的点将具有它周围有一个白色边框。

        if (Keys.F1 && (Keys.Down || Keys.Up || Keys.Left || Keys.Right))
        {
            switch (e.KeyCode)
            {
                case Keys.Up:
                    YUlt = YUlt - (PDiff + 10);
                    Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour, 2, Color.White);
                    break;
                case Keys.Down:
                    YUlt = YUlt + (PDiff + 10);
                    Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour, 2, Color.White);
                    break;
                case Keys.Left:
                    XUlt = XUlt - (PDiff + 10);
                    Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour, 2, Color.White);
                    break;
                case Keys.Right:
                    XUlt = XUlt + (PDiff + 10);
                    Draw.AddEllipse(XUlt, YUlt, 20, 20, Colour, 2, Color.White);
                    break;

            }
        }

我需要知道的是如何使用户按住F1键以在按下箭头键时给出点边框,但是无论F1是否被按下,程序仍会绘制点

1 个答案:

答案 0 :(得分:1)

添加表单字段:

for line in f:
    if "IMAGINARY PART" not in line:
        #do stuff
    else:
        f.close()
        break

订阅bool F1Pressed; 事件处理程序:

KeyUp

您的private void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F1) F1Pressed = false; } 方法应如下所示:

KeyDown