Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have something new to ask if anybody can help me(I need braincheck since the last time I asked the very same thing I got solved some time ago :P :P :D :)

anyway

I have richtextbox on the form and I am trying to put at run time dynamically textboxes on right click of the mouse, I have this code but nothing happens

C#
if (e.Button == MouseButtons.Right)
            {
                int c = 0;

                TextBox newtext= new TextBox();
                newtext.Name = "newtext" + c++;
                newtext.Location = new Point(e.X, e.Y);
                newtext.Size = new System.Drawing.Size(200, 25);
                this.Controls.Add(newtext);


            }


thing is that I am typing text in richtextbox and then I want to place textbox between some words that I typed, is there a easier way to do it when cursor is behind the word or something like that
Posted

1 solution

if you want to add to richTextBox add to Richtextbox.controls not this.controls

C#
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
       {

           if (e.Button == MouseButtons.Right)
           {
               int c = 0;

               TextBox newtext = new TextBox();
               newtext.Name = "newtext" + c++;
               newtext.Location = new Point(e.X, e.Y);
               newtext.Size = new System.Drawing.Size(200, 25);
               richTextBox1.Controls.Add(newtext);
               //this.Controls.Add(newtext);


           }
       }


i tried it it is working
check it again and be sure that this code block in side richTextBox_MouseDown
not in side Form1_MouseDown
 
Share this answer
 
v2
Comments
shonezi 6-Nov-12 15:16pm    
I tried this but nothing again
shonezi 6-Nov-12 15:23pm    
I tried with flowlayoutpanel and it worked fine, maybe it's because of the richtextbox that it doesnt work
shonezi 6-Nov-12 15:29pm    
aaaa mousedown, and i was on mouseclick...thanks a lot mate, thank you 5+ :)))

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