Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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();
f1.Label1.Text=textbox1.Text;
f1.Label2.Text=textbox2.Text;
f1.Label3.Text=textbox3.Text;
.....
..
...
..
f1.show();
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 22:15pm
Edited 4-Nov-12 22:25pm
v3
Comments
TanvirRaihan at 5-Nov-12 5:34am
   
You can use custom event to solve this issue.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
 
[Edit]
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); }
        set
        {
            _someText = value;
 
            // Fire the event
            StringDelegate eventHandler = SomeTextChanged;
            if( eventHandler != null)
            {
                eventHandler(_someText);
            }
        }
    }
}
 
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.
[/Edit]
  Permalink  
v2
Comments
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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Timer would be a solution. How to use Timer
 
Another Example of Timer
  Permalink  
Comments
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 468
2 Abhinav S 305
3 sanket saxena 295
4 Tadit Dash 160
0 Sergey Alexandrovich Kryukov 8,482
1 OriginalGriff 4,830
2 Peter Leow 3,794
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid