I have two form.

Form 1 and Form 2

In form 1, i have a few textbox and and combo box. and BTNOk [to save] and BTNCancel[when BTNCancel is click, user are prompt whether to save file if there is changes in entry]

Form 2 is the file where BTNCancel is clicked.
Display:
Do you want to save changes to your setting?
BTNYES,BTNNO, BTNCANCEL.

QUESTION

When I clicked BTNYES in form 2 how can I call BTNOK in form 1 so that it can run the event handler in form 1 BTNOK

another question. any idea of how to do password encryption/decryption

I have two form.

Form 1 and Form 2

In form 1, i have a few textbox and and combo box. and BTNOk [to save] and BTNCancel[when BTNCancel is click, user are prompt whether to save file if there is changes in entry]

Form 2 is the file where BTNCancel is clicked.
Display:
Do you want to save changes to your setting?
BTNYES,BTNNO, BTNCANCEL.

QUESTION

When I clicked BTNYES in form 2 how can I call BTNOK in form 1 so that it can run the event handler in form 1 BTNOK

another question. any idea of how to do password encryption/decryption

Hello!
You should set the BTNOK event handler in form1's class to public instead of private, this will enable you to call it from form2's class.

Then the code in form 2:

private void BTNYES (object sender, Eventargs e)
[B]
Form1 form1 = new Form1();
form1.BTNOK(sender, e);
[/B]

This should do it, but uses too much resources for the purpose, I think.

I have two form.

Form 1 and Form 2

In form 1, i have a few textbox and and combo box. and BTNOk [to save] and BTNCancel[when BTNCancel is click, user are prompt whether to save file if there is changes in entry]

Form 2 is the file where BTNCancel is clicked.
Display:
Do you want to save changes to your setting?
BTNYES,BTNNO, BTNCANCEL.

QUESTION

When I clicked BTNYES in form 2 how can I call BTNOK in form 1 so that it can run the event handler in form 1 BTNOK

another question. any idea of how to do password encryption/decryption

Try this, and create a new thread for question about password encryption/decryption.

// in form1 where calling form2
            Form form2 = new Form();
            DialogResult result = form2.ShowDialog();
            if (result == DialogResult.OK) // or whatever result you want to return
            {
                //call your handler to save or whatever
            }

            // inside form2's button handler:
            this.DialogResult = DialogResult.OK; // will be returned from form2.ShowDialog()

For password encryption you can use SHA-1. It's actually hashing not encryption, but I think for your purposes it would work fine...

public static string EncryptSHA1(string text, Encoding enc)
{
    byte[] buffer = enc.GetBytes(text);
    SHA1CryptoServiceProvider cryptoTransformSHA1 = 
    new SHA1CryptoServiceProvider();
    string hash = BitConverter.ToString(
        cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");

    return hash;
}

i've changed the class of BTNOK to public but it still inaccessible due to protection area.

For password encryption you can use SHA-1. It's actually hashing not encryption, but I think for your purposes it would work fine...

public static string EncryptSHA1(string text, Encoding enc)
{
    byte[] buffer = enc.GetBytes(text);
    SHA1CryptoServiceProvider cryptoTransformSHA1 = 
    new SHA1CryptoServiceProvider();
    string hash = BitConverter.ToString(
        cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");

    return hash;
}

as in how does this code work?
i only want to encrypt the data in textbox that is previously entered and store in textfile. and where do i put the code in exact. =X I'm quite blur .

Hello!
You should set the BTNOK event handler in form1's class to public instead of private, this will enable you to call it from form2's class.

Then the code in form 2:

private void BTNYES (object sender, Eventargs e)
[B]
Form1 form1 = new Form1();
form1.BTNOK(sender, e);
[/B]

This should do it, but uses too much resources for the purpose, I think.

i've changed the class of BTNOK to public but it still inaccessible due to protection area.

If all that form2 does is display the question and allow the user to click one of the buttons then you can use the MessageBox class to do the same thing:

DialogResult result = MessageBox.Show("Do you want to save changes to your setting?", "Save before exit?", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    //save changes
                }

Also, i would avoid making the buttons event handler public, its bad practice. If you really need to access data between forms its better to have a Private Variable on Form2 which can be accessed by Form1 using a Public Property.

This question has already been answered. Start a new discussion instead.