Click here to Skip to main content
15,901,426 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
OriginalGriff5-Dec-13 1:06
mveOriginalGriff5-Dec-13 1:06 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
_Q12_5-Dec-13 1:18
_Q12_5-Dec-13 1:18 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
HobbyProggy5-Dec-13 3:25
professionalHobbyProggy5-Dec-13 3:25 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
Pete O'Hanlon5-Dec-13 21:12
mvePete O'Hanlon5-Dec-13 21:12 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
HobbyProggy5-Dec-13 21:43
professionalHobbyProggy5-Dec-13 21:43 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
Pete O'Hanlon5-Dec-13 22:46
mvePete O'Hanlon5-Dec-13 22:46 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
Mycroft Holmes5-Dec-13 1:42
professionalMycroft Holmes5-Dec-13 1:42 
GeneralRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
BBatts5-Dec-13 10:29
BBatts5-Dec-13 10:29 
That's it, but it's not very elegant. You can use properties to return the value of visual objects. Like so. There is no reason to create that form and leave it in memory. It better to use it and then destroy it as soon as you're done.

C#
public partial class Form1 : Form
        {            
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                using (Form2 f2 = new Form2())
                {
                    f2.ShowDialog();
                    //f2.Show(); //this doesn't work because ShowDialog is required to stop the process and wait for input, show to show the form and moves on
                    label1.Text = f2.TextValue;
                }
            }
        }
        
        public partial class Form2 : Form
        {
            public string TextValue
            {
                get { return textBox1.Text; }
                set { textBox1.Text = value; }
            }

            public string LabelValue
            {
                get { return label1.Text; }
                set { label1.Text = value; }
            }

            public Form2() 
            { 
                InitializeComponent(); 
            }
        }

AnswerRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
OriginalGriff4-Dec-13 21:49
mveOriginalGriff4-Dec-13 21:49 
AnswerRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
DRAYKKO5-Dec-13 7:49
professionalDRAYKKO5-Dec-13 7:49 
AnswerRe: How do i take the text from Form2.textbox and paste it into Form1.textbox? Pin
WuRunZhe9-Dec-13 2:41
WuRunZhe9-Dec-13 2:41 
QuestionCreate excel 97-2003 by Open XML SDK 2.5 ? Pin
emma.sun.sts4-Dec-13 15:36
emma.sun.sts4-Dec-13 15:36 
AnswerRe: Create excel 97-2003 by Open XML SDK 2.5 ? Pin
Richard MacCutchan4-Dec-13 22:16
mveRichard MacCutchan4-Dec-13 22:16 
GeneralRe: Create excel 97-2003 by Open XML SDK 2.5 ? Pin
emma.sun.sts8-Dec-13 15:22
emma.sun.sts8-Dec-13 15:22 
GeneralRe: Create excel 97-2003 by Open XML SDK 2.5 ? Pin
Richard MacCutchan8-Dec-13 22:05
mveRichard MacCutchan8-Dec-13 22:05 
Questionhow to read value at specifix XML node Pin
bimbambumbum4-Dec-13 11:10
bimbambumbum4-Dec-13 11:10 
AnswerRe: how to read value at specifix XML node Pin
Jason Gleim4-Dec-13 13:05
professionalJason Gleim4-Dec-13 13:05 
AnswerRe: how to read value at specifix XML node Pin
PIEBALDconsult4-Dec-13 13:34
mvePIEBALDconsult4-Dec-13 13:34 
AnswerRe: how to read value at specifix XML node Pin
HobbyProggy5-Dec-13 4:01
professionalHobbyProggy5-Dec-13 4:01 
GeneralRe: how to read value at specifix XML node Pin
bimbambumbum5-Dec-13 7:19
bimbambumbum5-Dec-13 7:19 
QuestionPlease answer it is my biggest problem. Pin
Tera Mind4-Dec-13 10:59
professionalTera Mind4-Dec-13 10:59 
AnswerRe: Please answer it is my biggest problem. Pin
Mycroft Holmes4-Dec-13 11:44
professionalMycroft Holmes4-Dec-13 11:44 
GeneralRe: Please answer it is my biggest problem. Pin
Tera Mind4-Dec-13 12:01
professionalTera Mind4-Dec-13 12:01 
GeneralRe: Please answer it is my biggest problem. Pin
Mycroft Holmes4-Dec-13 16:13
professionalMycroft Holmes4-Dec-13 16:13 
AnswerRe: Please answer it is my biggest problem. Pin
OriginalGriff4-Dec-13 11:57
mveOriginalGriff4-Dec-13 11:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.