Calling Button Operation??

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2009
Posts: 57
Reputation: facadie has a little shameless behaviour in the past 
Solved Threads: 0
facadie facadie is offline Offline
Junior Poster in Training

Calling Button Operation??

 
0
  #1
Sep 15th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 56
Reputation: konczuras is an unknown quantity at this point 
Solved Threads: 1
konczuras konczuras is offline Offline
Junior Poster in Training

Re: Calling Button Operation??

 
0
  #2
Sep 15th, 2009
Originally Posted by facadie View 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
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 914
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 146
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: Calling Button Operation??

 
0
  #3
Sep 15th, 2009
Originally Posted by facadie View 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
Try this, and create a new thread for question about password encryption/decryption.

  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()
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 111
Reputation: papanyquiL is on a distinguished road 
Solved Threads: 11
papanyquiL papanyquiL is offline Offline
Junior Poster

Re: Calling Button Operation??

 
0
  #4
Sep 15th, 2009
For password encryption you can use SHA-1. It's actually hashing not encryption, but I think for your purposes it would work fine...

  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. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 57
Reputation: facadie has a little shameless behaviour in the past 
Solved Threads: 0
facadie facadie is offline Offline
Junior Poster in Training

Re: Calling Button Operation??

 
0
  #5
Sep 15th, 2009
i've changed the class of BTNOK to public but it still inaccessible due to protection area.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 57
Reputation: facadie has a little shameless behaviour in the past 
Solved Threads: 0
facadie facadie is offline Offline
Junior Poster in Training

Re: Calling Button Operation??

 
0
  #6
Sep 15th, 2009
Originally Posted by papanyquiL View Post
For password encryption you can use SHA-1. It's actually hashing not encryption, but I think for your purposes it would work fine...

  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 .
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 57
Reputation: facadie has a little shameless behaviour in the past 
Solved Threads: 0
facadie facadie is offline Offline
Junior Poster in Training

Re: Calling Button Operation??

 
0
  #7
Sep 15th, 2009
Originally Posted by konczuras View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 351
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 63
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Calling Button Operation??

 
0
  #8
Sep 25th, 2009
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:
  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 351
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 63
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Calling Button Operation??

 
0
  #9
Sep 25th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Tags
buttons, decryption, encryption

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC