c# - Button displaying/hiding password from text box [duplicate] - c#

This question already has answers here:
How to use PasswordBox as TextBox? [closed]
(4 answers)
Closed 5 years ago.
I am currently making a c# application, in which I am using a text box with property PasswordChar - •. However, this text box has a button like the one below:
However, as a student and amateur, I am unable to make an if code for the button, which when pressed, shows or hides the real numbers of the password.
I think it should be something like this:
private void metroTextBox1_ButtonClick(object sender, EventArgs e)
{
if (metroTextBox1.PasswordChar='\•') metroTextBox1.PasswordChar = '\0';
else metroTextBox1.PasswordChar = '\•';
}
but I think I have at least 1 mistake here.
Please, help!

Your mistakes are in this :
textBox1.PasswordChar = '\•'
You must use == instead of = and '•' instead of '\•'
textBox1.PasswordChar == '•'
It worth be added as #Cody Gray has already noted that it is better to use UseSystemPasswordChar

Related

does c# winform has build-in input dialog? [duplicate]

This question already has answers here:
What is the C# version of VB.NET's InputBox?
(11 answers)
Closed 1 year ago.
I am wondering if c# has build-in input dialog, this dialog only has one(or only a few) text input and OK and Cancel button.
So I don't need to add a new form for such a simple job.
You can use System.Windows.Forms.MessageBox.Show to create a message box and specify that you only want an Ok and Cancel button:
using System.Windows.Forms;
MessageBox.Show("Prompt", "Caption", MessageBoxButtons.OKCancel);
The Show method returns the button clicked as a System.Windows.Forms.DialogResult:
DialogResult rst = MessageBox.Show("Prompt", "Caption", MessageBoxButtons.OKCancel);
if(rst == DialogResult.OK)
MessageBox.Show("You clicked OK");
If you are asking how to create an input box, then the question has already been asked here What is the C# version of VB.net's InputDialog?, though I would recommend that you create your own version of an input box, because the VBA version is pretty ugly - that way you can also style the input box according to your desire.

set focus to a textBox in uwp [duplicate]

This question already has answers here:
Uwp navigation example and focusing on control
(2 answers)
Closed 6 years ago.
I have a Universal Windows Platform project that has a textBox element.
I'd like to set the focus to it when a Radio Button is clicked.
In the Radio Button click event, I can say:
txtBoxID.IsEnabled = true;
txtBoxID.Text = "";
But how do I set the focus? I saw some answers saying to use:
FocusManager.SetFocusedElement(
but my FocusManager class doesn't have that method.
edit: Solved, thanks. Just needed to know what argument to pass to SetFocus. The other fellow's question which was thought to be similar was regarding an event occurring after he set focus to his control.
All the code you need is:
txtBoxID.Focus(FocusState.Programmatic);
Method is defined in Control.

why all text gets selected in RichTextBox in C#? [duplicate]

This question already has answers here:
C# RichTextBox selection problem
(2 answers)
Closed 7 years ago.
I only have form1 with RichTextBox (windows form) and I have no code.
Lets say we write "123456789" in RichTextBox via the keyboard.
The problem is: when I try to select number 9 from right to left by using the mouse then the whole text get selected automatically before even I select the rest of the text.
But I CAN select 9 from left to right without the rest of text gets selected. And also I CAN select number 1 from right to left and without the rest of text gets selected. The problem happens only when you select the last number from right to left.
you can select any number from right to left and the rest of the text does not get selected but if you select the last number from right to left then the whole text gets selected.
I checked the RichTextBox properties but nothing interesting there. TexBox does not behave like this but I do not want to use textbox.
My question is: How can I select number 9 from right to left in RichTextBox using mouse and avoid the whole text from being selected automatically. Thank you
See the answer given by Hans Passant, all credit goes to him.
(At this point I feel that giving him more rep is like taking a p*ss into Niagra Falls)
C# RichTextBox selection problem
In Hans' words:
There's a silly bug in the AutoWordSelection property implementation. The workaround is equally silly. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form, replacing the existing RTB.
using System;
using System.Windows.Forms;
public class FixedRichTextBox : RichTextBox {
protected override void OnHandleCreated(EventArgs e) {
base.OnHandleCreated(e);
if (!base.AutoWordSelection) {
base.AutoWordSelection = true;
base.AutoWordSelection = false;
}
}
}
I could definitely replicate this behaviour before, and the custom RichTextBox fixed it for me.

password for Login Application in c# windows form [duplicate]

This question already has answers here:
How to set a text box for inputing password in winforms?
(9 answers)
Closed 5 years ago.
How to display password as "**" in the text box instead of
displaying real password
on text box?
Is it possible in c#
Thanks
Just set up a property of textbox:
textBox1.UseSystemPasswordChar = true;
and you can also set the char for password what you want to:
textBox1.PasswordChar = '*';
you can also set the char for password what ever you want:
textBox1.PasswordChar = '*';
Go to the properties of password textbox and make Password char property to *
You have two options:
Set the property TextBox.PasswordChar to whatever char you want to be displayed instead of the actual char
Set the property TextBox.UseSystemPasswordChar to true. This will use and display the defaul password-char (a dot in Win 7) instead of the actual char.

Referencing variables between wpf forms [duplicate]

This question already has answers here:
How can I access one window's control (richtextbox) from another window in wpf?
(4 answers)
Closed 9 years ago.
Alright, so I have a form with textboxes and a button (Form 1), and that button opens a new form (Form 2) consisting of a textbox.
What I want to do is get the contents of one of the textboxes of the first form (like TextboxForm1.Text) and use that text in the second form, like TextboxForm2.Text = {however to reference textbox 1 from form 1}.Text;.
Is there an obvious way that I overlooked?
Thanks.
Edit: Tried both solutions and the both worked well, but making it public was much easier in the case of multiple textboxes.
http://msdn.microsoft.com/en-us/library/aa970905.aspx
<TextBox Name="TextboxForm1" x:FieldModifier="Public" />
Yes, you could use a property to expose the value of the desired textbox from the appropriate form. So, add something like the following to your window class:
public string TextBox1Text {
get { return TextBox1.Text; }
}
And then access it from the instance, as you seem to know, like this:
AnotherTextBox.Text = instance.TextBox1Text;
As for using the access modifier for the control as per nmclean's answer (i.e. FieldModifier="Public"), I would only say make the entire control public if it is needed.

Categories

Resources