Parent Child Communication

Helloooo.!

I want to know how we can do parent child communication in our application. I am using Visual Studio 2005 express edition. If anyone have reading material no it plzzz send me toooo

Thankyou




Answer this question

Parent Child Communication

  • jaswinder_rana

    Attach a method of the parent form to the validate event of the child form. . . .

    This is c# because vb is not worth using. . .

    assumes a form,  called ChildForm, has two buttons, one with a dialog result of DialogResult.Ok the other with DialogResult.Cancel. Form1 wants to check that the data is ok when the user clicks Ok on ChildForm otherwise, let it close.

        public partial class Form1 : Form
        {
            private void button1_Click(object sender, EventArgs e)
            {
                using (ChildForm frm = new ChildForm())
                {
                    frm.FormClosing += new FormClosingEventHandler(CheckChild);
                    if (frm.ShowDialog() == DialogResult.OK)
                        InitializeApp();
                    frm.Validating -= new CancelEventHandler(CheckChild);
                }
            }

            private void CheckChild(object sender, CancelEventArgs e)
            {
                ChildForm frm = sender as ChildForm;
                if (frm != null)
                {
                    if (frm.DialogResult == DialogResult.OK)
                        e.Cancel = !EvaluateChild(frm);
                }
            }

            private void InitializeApp()
            {
                //setup app here
            }

            private void EvaluateChild(ChildForm frm)
            {
                // check ChildForm data here. Return True if ChildForm has valid data
            }
        }

     



  • Padma G

    hi,

    what do you mean by parent and child

    do you mean data relations,  xml nodes ,  treeview nodes, or what you have to make your question  clear more than that

    bye



  • Lost Web Owner

    hi,

    ok my friend really i never try this login form b4 but i tried for now and i was able to code on it just right click and chose view code and you can code it , it accepted from me at least , by the way the login form has a link to talking about how to make it

    here its the main form load method

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim myloginform As New LoginForm1

    myloginform.ShowDialog()

    MessageBox.Show(myloginform.username & vbNewLine & myloginform.password)

    myloginform = Nothing

    End Sub

    and here its the login form class by the way it has a link by default from microsoft to teach you something about it

    Public Class LoginForm1

    ' TODO: Insert code to perform custom authentication using the provided username and password

    ' (See http://go.microsoft.com/fwlink/ LinkId=35339).

    ' The custom principal can then be attached to the current thread's principal as follows:

    ' My.User.CurrentPrincipal = CustomPrincipal

    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication.

    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object

    ' such as the username, display name, etc.

    Private _username As String

    Private _password As String

    ReadOnly Property username()

    Get

    Return _username

    End Get

    End Property

    ReadOnly Property password()

    Get

    Return _password

    End Get

    End Property

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

    If Me.UsernameTextBox.Text = "myname" AndAlso Me.PasswordTextBox.Text = "123456" Then

    _username = Me.UsernameTextBox.Text

    _password = Me.PasswordTextBox.Text

    Me.Close()

    Else

    MessageBox.Show("enterusername")

    End If

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

    Me.Close()

    End Sub

     

    End Class

     



  • Wolfwang

    oooppppss!

    this:

                  frm.FormClosing += new FormClosingEventHandler(CheckChild);
                    if (frm.ShowDialog() == DialogResult.OK)
                        InitializeApp();
                    frm.Validating -= new CancelEventHandler(CheckChild);

    should have read:

                  frm.FormClosing += new FormClosingEventHandler(CheckChild);
                    if (frm.ShowDialog() == DialogResult.OK)
                        InitializeApp();
                    frm.FormClosing -= new FormClosingEventHandler(CheckChild);



  • bapper1

    Thankyou for ur guidence

     



  • Hans-Gustav

    Thankyou for ur guidence

    I will look forward to ask more from u about this language in future, also it is much better to have ur id so that i can directly mail u

    Thankyou



  • Ali Baradaran

    Well i am in a situation that there is a main form which has a sub login form as in studio 2005 edition we can add new login form but we can't code on it hope u see that, what i want to do is i want to check wether the username and password enter in the login window is correct by my main form. As my main form is Parent form and login form is its child.

    If u are still not clear then open 2005 studio edition make a form and add login form to it and see by ureself u cannt code on login form directly u have to code for it on the main form

    Thankyou.



  • Parent Child Communication