Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've heard that you can somehow make a form return true or false, probably by overriding the windows form class somehow ... Here is my problem:

 

I have a form that I am trapping KeyPress events (turning KeyPreview On) and checking the key's for validity (this is for reading a magnetic stripe) ... it has specific characters that mark the beginning and end of the "data string" ... so I watch for these using the KeyPress event ... if I am able to get all the data successfully then I want the form to return True and go through validation, if it didn't read the swipe properly then it returns False, so a warning can be displayed to the user and they can swipe the card again ...

 

Any ideas?

 

Thanks (again)!

M.

  • *Gurus*
Posted

The form has a built-in method for doing this. When you call ShowDialog() on a form, it returns one of many dialog result constants, the most common of which are Ok and Cancel.

 

In your form, as soon as you set the dialogresult, the form will hide and code will return to the calling procedure.

 

DialogResult = DialogResult.Cancel
'or
DialogResult = DialogResult.Ok

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...