c# - Changing text in another form by clicking a button -


i've been trying change text of textbox in form1 clicking button (button1 in form2 "starta") in form2 , spent 2 hours (i'm programming-newbie!). have been searching around similiar questions , found bunch, after trying lot of them can't work.

form1[design]

enter image description here

form2[design]

enter image description here

the method i'm trying right found here

in form1 wrote this:

public string starttid {         {         return this.textbox3.text;     }     set     {         this.textbox3.text = value;     } } 

i know doesn't quite make sense , set empty textbox, i've tried many different solutions think should work, textbox's text wont change when click button! in form2, when button1 clicked, wrote this:

string tiden = datetime.now.tostring("hh:mm:ss tt"); form1 first = new form1(); first.starttid = tiden; 

what i'm trying do, want text in textbox3 in form1 change current time when button1 in form2 pressed.

sorry if post bit messy, it's first , english isn't strongest language.

problem creating new form1 , update label on one, not in initial form

    form1 first = new form1();     first.starttid = tiden; 

you don't need create new form because created it. can parse form1 form2 when create form2 using constructor accept form parameter. or create property in form2 form1 , set when creating form2.

form1

form2 f2 = new form2(this); f2.show(); 

form2

public partial class form2 : form {     private form1 form1;      public form2(form1 form1)     {         initializecomponent();         this.form1 = form1;     }      private void button1_click(object sender, eventargs e)     {         form1.starttid = "set form2";     } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -