按ENTER键更改箭头的位置 [英] Change the location of an arrow by pressing ENTER key

查看:92
本文介绍了按ENTER键更改箭头的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个C#项目,我想通过按ENTER键来改变箭头的位置,不同的comboBox选择具有不同的迭代大小。实际上它可以工作,但问题是我无法在更改组合框选择之前刷新表单。我希望逐步看到迭代,但如果我更改了comboBox选项,它会移动。以下是代码:

I am working on a C# project and I want to change the location of an arrow by pressing ENTER key with different size of iteration for different comboBox selections. Actually it works but the problem is that I can not refresh the Form before changing comboBox Selection. I want to see iteration step by step but it moves if I change the comboBox selection. Here is the code:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


            if (comboBox1.SelectedIndex == 0)
            {

                this.BackColor = Color.Black;
                label1.ForeColor = Color.Silver;
                label1.Text = "Environment is Space";
                pictureBox2.Image = list.Images[4];
                t = 100; // iteration amount

            }

            else if (comboBox1.SelectedIndex == 1)
            {
                this.BackColor = Color.PaleTurquoise;
                label1.Text = "Environment is Water";
                pictureBox2.Image = list.Images[3];
                t = 50; // iteration amount

            }

            else if (comboBox1.SelectedIndex == 2)
            {
                this.BackColor = Color.DarkGoldenrod;
                label1.ForeColor = Color.Firebrick;
                label1.Text = "Environment is Honey";
                pictureBox2.Image = list.Images[2];
                t = 20; // iteration amount
            }

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {

            // Drawing arrow
            Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255), 8);
            pen.StartCap = LineCap.ArrowAnchor;
            pen.EndCap = LineCap.RoundAnchor;
            e.Graphics.DrawLine(pen, x+50, 200, x, 200);

        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            // pressed Enter => change x
            if (e.KeyChar == (char)Keys.Return)
            {
                e.Handled = true;
                if (x < y)
                {
                    x += t;

                }
            }
        }



更清楚:

我想要:点击 - >输入+ Move->箭头+点击 - >输入+移动 - >箭头

现在它的工作方式如下:Click->输入+更改 - > comboBox + Move->箭头



非常感谢!


To be more clear:
I want like: Click-> Enter + Move-> Arrow + Click->Enter + Move -> Arrow
Now it works like: Click-> Enter + Change-> comboBox + Move->Arrow

Thanks a lot!

推荐答案

this.Refresh()是回答。要绘制刚刚完成的内容,您需要将此行添加到代码中。
this.Refresh() is answer. To draw what just you did, you need to add this line to your code.


这篇关于按ENTER键更改箭头的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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