Click here to Skip to main content
15,922,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have twoRichTextBoxes in form1, once select specific texts in form1 richTextBox1 and press a shortcut key, then form1 richTextBox1 selected text values transfer to the form2 textBoxe1.

My problem is I cannot transfer form2 textbox1 value to the form1 richTextBox2 while keeping form1.

Also, above process should need to continue as print value to each line in the form1 richtextbox2.

Waiting for a better solution with source code.

C#
Form1
//This is not working properly
public string TextConvert
        {
            get { return richTextBox2.Text; }
            set { richTextBox2.Text = value; }
        }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Space))
            {
                Box form = new Box();
                form.TextExport = richTextBox1.SelectedText;
                form.ShowDialog();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }


C#
Form2
//This is not working properly
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
                if (keyData == (Keys.Enter))
                {

                    MessageBox.Show("Hi");
                    MainWindow form1 = new MainWindow();
                    form1.TextConvert = textBox1.Text;
                    this.Close();
                }
            return base.ProcessCmdKey(ref msg, keyData);
        }
public string TextExport
        {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }
Posted

you could try this. this would allow you to get the texboxvalue from form2.

in form1

C#
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Space))
            {
                Box form = new Box();
                form.TextExport = richTextBox1.SelectedText;
                form.ShowDialog();
                
                richTextBox1.Text = richTextBox1.Text + "\n" + form.texvalue; //this will get the value of texvalue from form2.

            }
            return base.ProcessCmdKey(ref msg, keyData);
        }


in form2

C#
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
                if (keyData == (Keys.Enter))
                {
 
                    MessageBox.Show("Hi");
                    MainWindow form1 = new MainWindow();
                    texvalue = textBox1.Text; //put the value of the textbox to textvalue
                    this.Close();
                }
            return base.ProcessCmdKey(ref msg, keyData);
        }
public string TextExport
        {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }
public string texvalue = String.Empty; //we will access this from form1


sorry for the terms i use i'm not good at them.
hope this will help you this time.
 
Share this answer
 
Comments
abdulsafran 28-Feb-13 5:34am    
Thanks a lot my friend.
ZaneArellano 28-Feb-13 5:46am    
your welcome
this code overwrites the current value of the richtextbox
with the one you are passing from form2.


C#
public string TextConvert
{
      get { return richTextBox2.Text; }
      set { richTextBox2.Text = value; }
}


you could try replacing that with this
C#
public string TextConvert
{
      get { return richTextBox2.Text; }
      set { richTextBox2.Text = richTextBox2.Text+"\n"+value; }
}
 
Share this answer
 
v2
Comments
abdulsafran 27-Feb-13 6:08am    
Thanks for the response, but my problem is output is not view in the richtextBox2, please advise?
ZaneArellano 27-Feb-13 22:01pm    
sorry for the late reply.

are you not getting the value your passing to form1 from form2?
abdulsafran 27-Feb-13 12:23pm    
Any Update?

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