Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I ran my code then it showed many form on windows, I don't know why. I already have shared code and the picture below
Thanks for helping

What I have tried:

This is my code
C#
public class Mean
        {
            static public string nghia;

        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            string a = null, text = null;
            a = Clipboard.GetText();
            text = a.ToLower();
            for (int i = 0; i < cbbtu.Items.Count; i++)
            {
                if (cbbtu.Items[i].ToString() == text)
                {
                    cbbtu.SelectedIndex = i;
                    Form clipbr = new clp();
                    clipbr.Show();
                }
            }
        }

This is problem
abc.png - Google Drive[^]
Posted
Updated 24-Oct-16 6:05am
Comments
F-ES Sitecore 24-Oct-16 11:17am    
You are showing a form in a loop so you will get one form per cbbtu.Items.Count as long as the "if" condition is true. If you don't understand this then you need to go back and learn c# from the very basics to understand what it is doing.
Midi_Mick 24-Oct-16 11:25am    
Also, every time your timer fires, it will create a new form for stuff that's already been done. Either you need to stop the timer after you've processed the clipboard, or you need to keep tabs on which bits of text have already had a form created for them, and not do it again.

1 solution

If you want to show each form one after the other, then use ShowDialog instead of Show to display it - the code will then "stop" and wait for the new form to be closed before continuing with the loop.

But each form you create will show the same thing - you probably need to add a property or constructor to the clp form in order to send it data for it to display.
 
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