How Can I Add a Drop Downmenu, Selection, add that text in a richtextfield

68 Views Asked by At

How Can I Make It So That: When I Select An Option From A Option From a Drop Down Menu, It adds a text into a richtextbox for example:

            Drop Down Menu/ComboBox >            |Are Goood|

            richtextbox:
                        ___________________________________________________
                        | (output after selecting option from dropdownmenu |
                        |                                                  |
                        |    "Waffles Are Goood"                           |
                        | (Adds Entire Text, "Waffles Are Good")           |
                        ___________________________________________________
1

There are 1 best solutions below

9
On BEST ANSWER

You use the SelectedIndexChanged event of the ComboBox(Drop Down Menu). Then try to add this code on the event function.

C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    richTextBox1.Text = main_text + " " + comboBox1.Text;
}

VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    RichTextBox1.Text = main_text + " " + ComboBox1.Text
End Sub

you need to create a string variable store the text from the richTextbox

string main_text; -- C#
Dim main_text As String -- VB

add KeyPress Event on the richtextbox

C#
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    main_text = richTextBox1.Text;
}

VB
Private Sub RichTextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
        main_text = RichTextBox1.Text
End Sub