I am using the input box from visual basic in c# and I couldn't figure out how I know what button has been pressed. The input box return the string that has been written.
How I know if the cancel button has been clicked or the OK button?
Thank you very much for the help, I didn't find the answer :)
This is what I tried:
string notineName = Interaction.InputBox("Enter the notice name:", "Enter notice name", "");
If you have another way to do input box ( I wanted to make my own but I don't know how to return what button has been clicked) please write it here.
If the user clicks Cancel, a zero-length string is returned.
Try having a look at this documentation. MSDN
As an alternative you could use dialog boxes.
InputDialog dialog = new InputDialog("Caption Here", "Label Text Here", "Default Textbox String");
if (dialog.ShowDialog() == DialogResult.OK)
{
string result_text = dialog.ResultText;
// use result_text...
}
else
{
// user cancelled out, do something...
}
Here an enum result determines what button was selected.
string a;
a = Interaction.InputBox("message", "message");
if (a.Length > 0)
{
comboBox2.Items.Add(a);
// ok
}
else
{
// cancel
}
Related
I'm using MudAutoComplete to implement suggestions based on user entering text, It works perfectly.
My problem is that when user write a text & press Enter, in KeyDown eventHandler i've get the first suggestion in the list instead of current text which user entered!!
For example, when user enter "Alfki", The following suggestions show :
Hi Alfki
Alfki Bye..
Alfki Bye 2
Now, when user hit Enter after Alfki, In KeyDown eventHandler, I've got "Hi Alfki" in bound-value instead of "Alfki"!
Where is my problem and how to solve it?
Thanks ...
Updated ..
Here is my sample code :
<MudAutocomplete T="string"
Variant="Variant.Outlined"
#ref="#_txtAutoCompelete"
ResetValueOnEmptyText="true"
CoerceText="true"
#bind-Text="_strSearchQuery"
SearchFunc="#SearchQuery"
OnKeyUp="#SearchQueryResult"
Adornment="Adornment.End"
AdornmentIcon="#Icons.Filled.Search"
AdornmentColor="Color.Success">
</MudAutocomplete>
#code{
private string _strSearchQuery;
private async Task SearchQueryResult(KeyboardEventArgs e)
{
if (e.Code == "Enter" || e.Code == "NumpadEnter")
{
string strText = _txtAutoCompelete.Text; // first suggestion, not current text!
string strValue = _txtAutoCompelete.Value; // first suggestion, not current text!
string strCurrentText = _strSearchQuery; // first suggestion, not current text!
}
}
}
I have a web form with a text box where the user enters a URL so by default I have put an https:// but if the user does not enter a URL after and leaves it empty I want to show an error. I have used
if (textBox1.TextLength <= 9)
{
// code
}
Instead of Length check, use equality operator with .Text property to check exact text in the text box.
//This means, there is only "https://" is written in the text box
if(textBox1.Text == "https://")
{
//Show an error. Here user did not enter anything
}
else
{
//Your implementation
}
I am having trouble with creating a form that requires the user to enter information in the fields, Confirm an email and password entry, and go onto the next form when all those fields are matched/filled in. Individually, the code I have works, but I cannot seem to find a way to make it so that all the requirements are met before going onto the next form. At the moment it just goes onto the next form if i click the continue button.
some excerpts of the code i have are:
if (string.IsNullOrEmpty(email))
{
lblRequirementsError.Text = ("All required fields have not been filled.");
}
if (txtBoxEmail.Text != txtBoxConfirmEmail.Text)
{
lblEmailError.Text = ("Email reentry does not match. Please reenter.");
}
if (txtBoxPassword.Text != txtBoxConfirmPassword.Text)
{
lblPasswordError.Text = ("Password reentry does not match. Please reenter.");
}
this.Hide();
frmBilling secondForm = new frmBilling();
secondForm.Show();
The problem is the form is created and opened regardless of the if results, because the code for it is outside the ifs. First, check that no fields are empty, and then, check that the validation has been met, THEN open the new window. Something like this should work:
//If both email and password are not empty
if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
{
//if both email and password math the re entry
if (txtBoxEmail.Text == txtBoxConfirmEmail.Text &&
txtBoxPassword.Text == txtBoxConfirmPassword.Text)
{
//execute the code to open the new form
this.Hide();
frmBilling secondForm = new frmBilling();
secondForm.Show();
}
}
if (! txtBoxEmail.Text.Equals( txtBoxConfirmEmail.Text))
{
lblEmailError.Text = ("Email reentry does not match. Please reenter.");
}
if (! txtBoxPassword.Text.Equals( txtBoxConfirmPassword.Text))
{
lblPasswordError.Text = ("Password reentry does not match. Please reenter.");
}
are you using web applications forms in visual studio 2012. You can use field validators inside the .ASPX file for any field that you want to validate before form submission. This is much easier that writing everything in C#.
You can use the DataAnnotation if you are binding or converting your controls to the data objects. Then it will be easy to validate. Please see the link for more details
http://msdn.microsoft.com/en-us/library/dd901590(VS.95).aspx
Try this:
bool validationStatus = default(bool);
if (string.IsNullOrEmpty(email))
{
lblRequirementsError.Text = ("All required fields have not been filled.");
validationStatus = true;
}
if (txtBoxEmail.Text != txtBoxConfirmEmail.Text)
{
lblEmailError.Text = ("Email reentry does not match. Please reenter.");
validationStatus = true;
}
if (txtBoxPassword.Text != txtBoxConfirmPassword.Text)
{
lblPasswordError.Text = ("Password reentry does not match. Please reenter.");
validationStatus = true;
}
if(!validationStatus)
{
Hide();
frmBilling secondForm = new frmBilling();
secondForm.Show();
}
I was hoping someone could help with an error check for my paste method. I would like to prevent pasting anything that is not a numeric value from clipboard into my textBox. The coding for pasting is listed below.
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
// Determine if there is any text in the Clipboard to paste into the text box.
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
// Determine if any text is selected in the text box.
if (textBox1.SelectionLength > 0)
{
// Ask user if they want to paste over currently selected text.
if (MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) == DialogResult.No)
// Move selection to the point after the current selection and paste.
textBox1.SelectionStart = textBox1.SelectionStart + textBox1.SelectionLength;
} // end if
} // Paste current text in Clipboard into text box.
textBox1.Paste();
} // end pasteToolStripMenuItem
If you want to include Currency symbols, decimal places, Thousand seperators etc. Int.Parse is probably your best bet
public bool IsValidNumber(string input)
{
int val = 0;
return int.TryParse(input.Trim(), NumberStyles.Any, null, out val);
}
"$100,000" = true
"100.002" = true
"1000,44j" = false
etc.
The Message Boxes of WPF could be customized as i understand.
I was wondering is it possible to add a CheckBox to the WPF MessageBox with say - Don't show this message again etc.?
Possible, you can change the WPF control styles and templates as per your requirement, see these links for further references:
Custom Message Box
http://blogsprajeesh.blogspot.com/2009/12/wpf-messagebox-custom-control.html
http://www.codeproject.com/Articles/201894/A-Customizable-WPF-MessageBox
http://www.codeproject.com/Articles/22511/WPF-Common-TaskDialog-for-Vista-and-XP
Could just use a Window
Passed checked in the ctor so you can get the value back
bool checked = false;
Window1 win1 = new Window1(ref input);
Nullable<bool> dialogResult = win1.ShowDialog();
System.Diagnostics.Debug.WriteLine(dialogResult.ToString());
System.Diagnostics.Debug.WriteLine(checked.ToString());
I realize this is a very old thread, but I was searching this matter today and was surprised to see no replies mentioning Ookii: https://github.com/ookii-dialogs/ookii-dialogs-wpf
I was already using it for Folder Browsing. Now I wanted to add a "Don't Show Again" checkbox whenever the main window is closed, and it's really simple to use it.
Here's my code:
using Ookii.Dialogs.Wpf;
//create instance of ookii dialog
TaskDialog dialog = new();
//create instance of buttons
TaskDialogButton butYes = new TaskDialogButton("Yes");
TaskDialogButton butNo = new TaskDialogButton("No");
TaskDialogButton butCancel = new TaskDialogButton("Cancel");
//checkbox
dialog.VerificationText = "Dont Show Again"; //<--- this is what you want.
//customize the window
dialog.WindowTitle = "Confirm Action";
dialog.Content = "You sure you want to close?";
dialog.MainIcon = TaskDialogIcon.Warning;
//add buttons to the window
dialog.Buttons.Add(butYes);
dialog.Buttons.Add(butNo);
dialog.Buttons.Add(butCancel);
//show window
TaskDialogButton result = dialog.ShowDialog(this);
//get checkbox result
if (dialog.IsVerificationChecked)
{
//do stuff
}
//get window result
if (result != butYes)
{
//if user didn't click "Yes", then cancel the closing.
e.Cancel = true;
return;
}