如何在运行时将文本框添加到richtextbox

如何在运行时将文本框添加到richtextbox

本文介绍了如何在运行时将文本框添加到richtextbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有新的问题要问是否有人可以帮助我(自从我上次问前一段时间解决的同一件事时,我需要进行脑部检查:P:P:D :)

无论如何

我在表单上有richtextbox,我试图在运行时在鼠标右键单击上动态放置文本框,我有这段代码,但没有任何反应

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

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);


            }



事情是我在richtextbox中键入文本,然后我想在我输入的某些单词之间放置文本框,当光标在该单词或诸如此类的单词后面时,是否有一种更简单的方法来实现呢?



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

推荐答案

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);


           }
       }



我试过了,它可以正常工作
再次检查并确保此代码块位于side richTextBox_MouseDown
不在Form1_MouseDown



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


这篇关于如何在运行时将文本框添加到richtextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:19