switchen tussen onderdelen in een form

Status
Niet open voor verdere reacties.

badboyR

Gebruiker
Lid geworden
11 apr 2012
Berichten
28
Hallo allemaal, ik ben nog steeds bezig met mijn listbox. Ik wil door kunnen typen in de richtextbox terwijl de listbox wordt geupdate terwijl ik type. Is er een mogelijkheid om van de listbox naar de richtextbox over te springen, en wat gebeurt er dan met de selectie?

Nu heb ik het nog op een andere manier aangepakt:
Code:
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Contains(' '))
            {
                string[] parts = richTextBox1.Text.Split(' ');
                string Woord = parts[parts.Length - 1];
                if (Woord.Length > 1)
                {
                    string Temp = Regex.Replace(Woord, @"\t|\n|\r", "");
                    Woord = Temp;
                    Temp = Woord.TrimStart(' ');
                    string[] Lijst = GetList(Temp);
                    int Niks = -1;
                    foreach (string ding in Lijst)
                    {
                        if (ding != null)
                        {
                            Niks++;
                        }
                    }

                    if (Niks != -1)
                    {
                        Niks++;
                        string[] TempIndex = new string[Niks];
                        Niks--;
                        for (int i = Niks; i > -1; i--)
                        {
                            TempIndex[i] = Lijst[i];
                        }
                        int CurrentTagStart = richTextBox1.SelectionStart;
                        Point p = richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart);
                        p.Y += (int)richTextBox1.Font.GetHeight() * 3;
                        listBox1.Location = p;
                        listBox1.Show();
                        ActiveControl = listBox1;
                        this.listBox1.Items.Clear();
                        this.listBox1.Items.AddRange(TempIndex);
                    }
                    else
                    {
                        this.listBox1.Visible = false;
                    }
                }
            }
        }

        private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                try
                {
                    string Text = listBox1.SelectedItem.ToString();
                    string[] parts = richTextBox1.Text.Split(' ');
                    string Woord = parts[parts.Length - 1];
                    richTextBox1.Text.Replace(Woord, Text); // Kan problemen veroorzaken
                    this.listBox1.Visible = false;
                }
                catch 
                {
                    // Vragen om iets te selecteren?
                }
            }

            if (e.KeyChar == (char)27)
            {
                listBox1.Visible = false;
            }

            if (e.KeyChar != (char)13 && e.KeyChar != (char)27 && e.KeyChar != (char)38 && e.KeyChar != (char)40)
            {
                if (Char.IsLetterOrDigit(e.KeyChar) || e.KeyChar == '_')
                {
                    richTextBox1.Text += e.KeyChar.ToString();
                }

                if (e.KeyChar == (char)8)
                {
                    int Temp = richTextBox1.Text.Length;
                    Temp--;
                    richTextBox1.Text.Remove(Temp);
                }
            }
        }

        private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)27)
            {
                listBox1.Visible = false;
            }
        }

Er zijn hier echter een paar problemen mee, als ik op backspace druk (char 8) wordt de functie wel uitgevoerd, maar verdwijnt de laatste letter niet. Ook is de rest nogal onstabiel.

Weet iemand een betere manier om dit te doen?
 
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan