943,712 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2050
  • C# RSS
Sep 15th, 2009
0

Calling Button Operation??

Expand Post »
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
Similar Threads
Reputation Points: 1
Solved Threads: 0
Junior Poster in Training
facadie is offline Offline
57 posts
since Sep 2009
Sep 15th, 2009
0

Re: Calling Button Operation??

Click to Expand / Collapse  Quote originally posted by facadie ...
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)

Form1 form1 = new Form1();
form1.BTNOK(sender, e);

This should do it, but uses too much resources for the purpose, I think.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
konczuras is offline Offline
59 posts
since Oct 2008
Sep 15th, 2009
0

Re: Calling Button Operation??

Click to Expand / Collapse  Quote originally posted by facadie ...
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.

C# Syntax (Toggle Plain Text)
  1. // in form1 where calling form2
  2. Form form2 = new Form();
  3. DialogResult result = form2.ShowDialog();
  4. if (result == DialogResult.OK) // or whatever result you want to return
  5. {
  6. //call your handler to save or whatever
  7. }
  8.  
  9. // inside form2's button handler:
  10. this.DialogResult = DialogResult.OK; // will be returned from form2.ShowDialog()
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Sep 15th, 2009
0

Re: Calling Button Operation??

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

c# Syntax (Toggle Plain Text)
  1. public static string EncryptSHA1(string text, Encoding enc)
  2. {
  3. byte[] buffer = enc.GetBytes(text);
  4. SHA1CryptoServiceProvider cryptoTransformSHA1 =
  5. new SHA1CryptoServiceProvider();
  6. string hash = BitConverter.ToString(
  7. cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
  8.  
  9. return hash;
  10. }
Reputation Points: 55
Solved Threads: 18
Junior Poster
papanyquiL is offline Offline
168 posts
since May 2009
Sep 15th, 2009
0

Re: Calling Button Operation??

i've changed the class of BTNOK to public but it still inaccessible due to protection area.
Reputation Points: 1
Solved Threads: 0
Junior Poster in Training
facadie is offline Offline
57 posts
since Sep 2009
Sep 15th, 2009
0

Re: Calling Button Operation??

Click to Expand / Collapse  Quote originally posted by papanyquiL ...
For password encryption you can use SHA-1. It's actually hashing not encryption, but I think for your purposes it would work fine...

c# Syntax (Toggle Plain Text)
  1. public static string EncryptSHA1(string text, Encoding enc)
  2. {
  3. byte[] buffer = enc.GetBytes(text);
  4. SHA1CryptoServiceProvider cryptoTransformSHA1 =
  5. new SHA1CryptoServiceProvider();
  6. string hash = BitConverter.ToString(
  7. cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
  8.  
  9. return hash;
  10. }
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 .
Reputation Points: 1
Solved Threads: 0
Junior Poster in Training
facadie is offline Offline
57 posts
since Sep 2009
Sep 15th, 2009
0

Re: Calling Button Operation??

Click to Expand / Collapse  Quote originally posted by konczuras ...
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)

Form1 form1 = new Form1();
form1.BTNOK(sender, e);

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.
Reputation Points: 1
Solved Threads: 0
Junior Poster in Training
facadie is offline Offline
57 posts
since Sep 2009
Sep 25th, 2009
0

Re: Calling Button Operation??

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:
C# Syntax (Toggle Plain Text)
  1. DialogResult result = MessageBox.Show("Do you want to save changes to your setting?", "Save before exit?", MessageBoxButtons.YesNoCancel);
  2. if (result == DialogResult.Yes)
  3. {
  4. //save changes
  5. }
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009
Sep 25th, 2009
0

Re: Calling Button Operation??

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.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: need to get a running process
Next Thread in C# Forum Timeline: How to click on button on web page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC