Hi!!!
I have made a window application Form in which there is a textbox in which I am entering string of data.
Also there is a toolbar for entering symbols which are not present on keyboard.
Now for entering each symbol in textbox i have used :

textBoxEquation.AppendText("÷");
            this.textBoxEquation.Focus();

but problem is that If I use bracket and try to enter any symbolfrom toolbar inside that, then in that case symbol does not appear inside bracket but it gets appended outside the bracket(because i have used Appendtext)...........
How can I enter symbols or characters using toolbar inside bracket as well as outside bracket.
Kindly provide some solution............ :)

This code works perfectly with me:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.AppendText("(");
            textBox1.AppendText("÷");
            textBox1.AppendText(")");
            textBox1.AppendText("÷");
        }
    }
}

You don't have to use the Focus method, the textbox still has the focus.

This code works perfectly with me:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.AppendText("(");
            textBox1.AppendText("÷");
            textBox1.AppendText(")");
            textBox1.AppendText("÷");
        }
    }
}

You don't have to use the Focus method, the textbox still has the focus.

Thanks for your reply.....
but i am appending the text in textbox on button click.
And also i don't want to append the text like this, i have multiple buttons, the code you provided me is working only for one symbol....
So kindly help me regarding this..................

try this:

string text = textBoxEquation.Text;
            int index = textBoxEquation.SelectionStart;
            text = text.Insert(index, "÷");
            textBoxEquation.Text = text;
            textBoxEquation.Focus();
            textBoxEquation.SelectionStart = index + 1;
            textBoxEquation.SelectionLength = 0;

That will result in the character being added wherever the user is currently typing rather than on the end of the string :)

Remember to mark the thread as solved if this has answered your question

What about this then:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.AppendText("(");
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.AppendText("÷");
            textBox1.Focus();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.AppendText(")");
            textBox1.Focus();
        }
    }
}

On the form i have made a button for bracket"{}" , And another button of divide and alphabets.Now when i click on "{}" button in the textBox i'll get {}, and now i want to insert various symbols inside it by using individual buttons which are present in my application......
Now tell me how can i apply the code on each button click.
to form a string like "{gddh/kmh ÷ igk*lfgh+6767-686}
So kindly help me regarding this........................

What is wrong with first typing the left barcket and afterwards typing the right bracket? You don't evne have to use buttons for that, just use the keyboard.

try this:

string text = textBoxEquation.Text;
            int index = textBoxEquation.SelectionStart;
            text = text.Insert(index, "÷");
            textBoxEquation.Text = text;
            textBoxEquation.Focus();
            textBoxEquation.SelectionStart = index + 1;
            textBoxEquation.SelectionLength = 0;

That will result in the character being added wherever the user is currently typing rather than on the end of the string :)

Remember to mark the thread as solved if this has answered your question

As i said, my code will insert the symbol wherever the user is typing (at the caret).
The last two lines move the caret on one space to put it after the newly inserted symbol.

Edited 7 Years Ago by Geekitygeek: n/a

What is wrong with first typing the left barcket and afterwards typing the right bracket? You don't evne have to use buttons for that, just use the keyboard.

Thanks for your reply once again Mr. ddanbe
But what about the symbols which are not present on keyboard like ÷ , etc.
Actually for these symbols i have used buttons.
And i know there is nothing wrong about your suggestion.
But i want that if a user want to insert brackets "{}" first and then he go back and insert the symbol between those brackets......
Kindly reply me regarding this............

do i need to bump myself again? Heeelllooo? is this thing on.. *blows on the keyboard* *fffft* *fffffffft* :)

I have posted code which you can place in your button press event that will insert a string ANYWHERE in the textbox instead of at the end. It inserts it at the textboxes .SelectionStart location, which is the place in the text where the cursor/caret is currently placed..whever the user is currently typing.

Is there a bug on the thread? Can you guys see my posts?

Comments
Sometimes you have to be like that...

THanks a lot Ryshad...:)
Actually i missed the last line of your code..........
Thats why i was getting wrong answer.......
I am extremely Sorry for such blunder...............:$

This question has already been answered. Start a new discussion instead.