Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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;

                }
            }
        }

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!
Posted
Updated 19-Dec-14 1:04am
v2
Comments
BillWoodruff 19-Dec-14 9:33am    
Not clear: what does "different size of iteration" mean ? What is 'pictureBox2 used for ?

1 solution

this.Refresh() is answer. To draw what just you did, you need to add this line to your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900