Displaying error message with wpf TextBlock control [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am quit new to WPF, so pardon me for the newbie question.
I have a wpf user login form where user can enter their username and password. I also added a TextBlock element which I set visibility to hidden. When user login fail I will like to set the text block visible with a string error message from my UserAuthentication class. How can bind my the error message to my TextBlock and also set it visible?

Add a string property like ErrorMessage to your ViewModel used as DataContext and set its value on error.
Then to show the message, you need to set binding on Visibility property on TextBlock using BoolToVisibilityConverter and bind to bool property on ViewModel (like ShowErrorMessage).

Related

Purpose of Control.Validate() [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I would like to know...
why Control.Validate() exists?
in which cases it should/n't be used?
in which cases it could be handy?
I'll give you an example as the msdn does here : Control.Validate(Event).
A simple example is when you are trying to "validate" an Email address that the user enters on a TextBox. If the e-mail address is not in the standard format (containing "#" and "."), the validation fails, an ErrorProvider icon is displayed, and the event is canceled. This example requires that a TextBox and ErrorProvider control have been created on a form.
And this is the function of it :
If the CausesValidation property is set to false, the Validating and Validated events are suppressed.
If the Cancel property of the CancelEventArgs is set to true in the Validating event delegate, all events that would usually occur after the Validating event are suppressed.

how can I make my textbox capture characters why textbox does not capture input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
when I put a breakpoints on my textbox it shows textbox.length = "" even if there are characters in the textbox
There is no Length property present in TextBox Class.
Probably you mean to Check the Length on Textbox Text property which is of string type.
textbox.Text.Length
More info about the code would be nice. Is your Textbox really enabled? No transparent layer in front of it? You used the mySQL-Tag. Does that mean you use some kind of binding in textbox? Possibly you can't change the content of your textbox, because the database-binding / connection is read-only?
Is there really some textbox.length property?? Are you sure you are referring to the right property? Try this:
Convert.ToString(textBox1.TextLength)

Find a label in WinForms which contains certain text? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In C# Windows form application, how to find the label on the form which contains the text I'm looking for?
For example: I am trying to search a label whose Text property contains "25".
You can find it using linq this way:
var control = this.Controls.OfType<Control>().Where(x => x is Label && x.Text.Contains("25"));
or as #Sayse suggested just filter on Label type:
var Labelcontrol = this.Controls.OfType<Label>().Where(x => x.Text.Contains("25"));
Explanation:
If we want to fetch all controls of the form we have to do :
var AllControls = this.Controls.OfType<Control>();
and if we want to fetch only Controls of Type Label then:
var LabelControls = this.Controls.OfType<Label>();
Here this refers to current form of application.
UPDATE:
If you have label in nested controls, means inside some user control or some other control, then you need to check recrursively as in this SO post (How to get ALL child controls of a Windows Forms form of a specific type)

C# ParentForm.ActiveControl.Name [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
if (Operators.CompareString(this.ParentForm.ActiveControl.Name, this.Name, false) == 0)
{
base.Focus();
}
From What I have experience in VB6,the above code doesn't work because they are never equal if the users didn't change to the same name.
From Example, the UserControl Name is ucCalendar, When I drag to my From, the name will automatically change to ucCalendar1,even though I can change to ucCalendar but usually we won't do that.
I think the coder want to compare whether the UserControl is the only control or ActiveControl on the Form so that he can force to focus it.
I don't know this C# works or not. Please tell me.
There is nothing in the WinForms code saying that two controls can not have the same name. The reason you think that is that you're looking at it from the designer perspective, when you use the designer it won't let you have two controls with the same name just because it uses there as field names for them in the code, and as you probably know there can not be two fields / properties / variables with the same name in the same scope. As a matter of fact there is no need for the Control's Name property to be anything.

How to allow only valid values in a combobox? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}

Categories