Click here to Skip to main content
11,496,146 members (441 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: VS2008 C# DirectX C#4.0 VS2010 UI , +
My application has a two forms. form1 has 8 labels and an audio element. Form2 has 8 textboxes with a save button. Both forms are opened at the start of Application. After filling Textboxes in form2. And on the click of save button. The text of labels in form1 should be replaced with Content of the textboxes..
Form1 f1= new Form1();
I can't use this code in Form2 because new object of form1 will be created With new audio element from the beginning... I don't want new audio element playing from the first.. So How do i send data from from1 to form2 with creating new object of form and How do i keep audio from restarting every time i send the data from (FORM1) to (FORM2)...
Posted 4-Nov-12 23:15pm
Edited 4-Nov-12 23:25pm
TanvirRaihan at 5-Nov-12 5:34am
You can use custom event to solve this issue.
You should have an underlying data structure with methods to change the data. Usually that is called the business logic layer.

It should also declare and fire the appropriate events to inform your UI of any changes.

It's done something like that:
public static class UnderlyingData
    // Here, the data is really stored during application lifetime
    private static string _someText = "Initial Value";
    // A publically accessible property to read and change the data
    public static string SomeText
        get { return (_someText); }
        set { _someText = value; }
    // Inform GUI of changes. Use an event for that.
    public static delegate void StringDelegate( string stringTypedParameter);
    public static event StringDelegate SomeTextChanged;
    // Change publically accessible property to fire the event
    public static string SomeText
        get { return (_someText); }
            _someText = value;
            // Fire the event
            StringDelegate eventHandler = SomeTextChanged;
            if( eventHandler != null)
public class Form1 : Form
    private void TextBox1.TextChanged(object sender, EventArgs e)
        // Pass text change to business layer
        UnderlyingData.SomeText = TextBox1.Text;
public class Form2 : Form
    private void Form2_Load(object sender, EventArgs e)
        // Subscribe to business layer's data-changed-event
        UnderlyingData.SomeTextChanged += new UnderlyingData.StringDelegate(UnderlyingData_SomeTextChanged);
    private void UnderlyingData_SomeTextChanged(string someText)
        // Do whatever your UI needs to do with the changed data
        Label42.Text = someText;

That's the minimal example. Of course, you can use the event in Form1 as well, if there is some other thing that depends on the changed data. Or you can incorporate validation checks in the property's set accessor.
Sharath2790 at 5-Nov-12 22:49pm
Any links or examples.. So that i could understand in a more better way...
lukeer at 6-Nov-12 1:54am
I updated my solution.
Timer would be a solution. How to use Timer

Another Example of Timer
lukeer at 5-Nov-12 7:40am
And exactly how do you think could a timer be of any help here?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100