Basically I want them to press the enter key and then something happens...how can I do this?
C# help....?
Hello,
In C# you make an event to KeyPress for any control, and you do the following.
In C#, the KeyPress event has KeyPressEventArgs parameter that contains the KeyChar, you could use any other KeyEvent if you want and you do something like the following. In this case, I made a Message Box Appear
================
if (e.KeyChar == (char)Keys.Enter)
{
MessageBox.Show("pressed enter");
}
============
I formatted the full working code here:
http://pastebin.com/m3bb7d2f0
If your looking for something different, such as, a Message Box, and you want to decide if the message box has been entered.
You can do something like this
================
if ( MessageBox.Show( "Press Y or N" , "Some Dialog", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// a 'DialogResult.Yes' value was returned
Console.Writeline("YES");
}
else
{
Console.Writeline("NO");
}
================
I hope this answers your question.
Good Luck
Reply:add two buttons to your pop up form and name then cmd_OK and CMD_Cancel
Go to the properties of the form and set the acceptbutton to CMD_OK and the cancelbutton to CMD_CANCEL.
create this procedure to display your dialog box on form1
public void ShowMyDialogBox()
{ Form2 testDialog = new Form2();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (testDialog.ShowDialog(this) == DialogResult.OK)
{ // Read the contents of testDialog's TextBox.
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Not ok");
}
testDialog.Dispose();
}
Set the dialog results of the ok and cancel buttons to ok and cancel respectivley and then you can do things as god gates intended!
you will now be able to trap the type of button pressed and as an aside be able to trap wether the user pressed cancel or ok! So you can give them the options to carry on or cancel!!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment