Showing Plain Text of a Password TextBox in C# [duplicate] - c#

This question already has answers here:
How can I unmask password text box and mask it back to password?
(9 answers)
Closed 9 years ago.
I am having a textbox for password field, I want to add a Checkbox that toggles the password into plain text.
I did the following coding for it.
txtpwd.PasswordChar = (char)(byte)32;
but this simply hides not showing the plain text of what is typed in textbox field.
any body can help?

Here is the solution, I added CheckBox with name chkpwd and on its CheckedChange event i added this code
private void chkpwd_CheckedChanged(object sender, EventArgs e)
{
if (chkpwd.Checked)
txtpwd.PasswordChar = '\0';
else
txtpwd.PasswordChar = '*';
}
This will show plain text when checkbox's checked property true

Related

How would one add code to a control that was added programmatically to a windows form application in c#? [duplicate]

This question already has answers here:
C# - Add button click events using code
(3 answers)
Closed 3 years ago.
I very new to C# and I would like to add a Button to a form programmatically. When this button is pressed I want it to run some code (like a normal button woukd work). But, everywhere I have searched only shows how to add the button and not how to add code to the button.
One way to do it is to give the button a name property, then in your code you "refer" to the button by it's name like so:
void btnButton_Click(object sender, EventArgs e)
{
// your code goes here
}
where btnButton_Click is the name of the button.

Creating a Watermark in winforms [duplicate]

This question already has answers here:
Watermark TextBox in WinForms
(11 answers)
Adding placeholder text to textbox
(26 answers)
Closed 3 years ago.
I am working on a Winforms project and I would like to create a Watermark in a TextBox. I tried a code that seems to be the right solution but is incorrect.
There is my code :
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "Veuillez entrez votre nom ici";
if (textBox1.GotFocus)
{
textBox1.Text = "";
}
}
And I get this error at "GotFocus" :
CS0079 C# The event can only appear on the left hand side of += or -=
I searched on google but I didn't find any solutions to help my case.
What should I use instead of "GotFocus" to create a Watermark ?
Best regards, Zancrew.
A lazy solution
create a label and locate it where you want your watermark to be shown and disable it
then paste code below on textbox's textchanged event
label_watermark.Visible = textBox1.Text.Length<1;

C# WPF textbox GotFocus SelectAll not working [duplicate]

This question already has answers here:
How to select all text in TextBox WPF when focused?
(2 answers)
Closed 4 years ago.
I have a textbox with a GotFocus() event. The event is supposed select all text in the textbox, but it only works when I set a breakpoint on the textbox.SelectAll() command or when I step through the method. I've noticed that when I click on the textboxs bottom border it sometimes selects all.
Can anybody tell me what's going on?
The TextBox_GotFocus() method is as simple as it gets, but here it is:
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
textBox.SelectAll();
}
Edit:
My problem isn't that I don't know how to select all and the way I'm using it should work in my mind (I've used it the same way in other apps without problems). The problem is that it only works when I set a breakpoint in the method or step into the method in debugging but not when selecting the textbox in real time.
Following should help you to select all text.
private void TextBox_GotFocus(objetc sender, RoutedEventArgs e)
{
var txtControl = sender as TextBox;
txtControl.Dispatcher.BeginInvoke(new Action(() =>
{
txtControl.SelectAll();
}));
}

How to make combo box auto expand on mouse hover and close when the mouse leaves combo box in c#? [duplicate]

This question already has answers here:
Winforms: how to open combobox properly?
(5 answers)
Closed 8 years ago.
I have a windows form. In that windows form i have a combo box. I have predefined items in the combo box as Add, Remove and Delete. I want to make the combo box auto expand on mouse hover. How can I do that? I noticed that auto expand code should be given in the mouse hover event of combo box. like this
private void comboBox1_MouseHover(object sender, EventArgs e)
{
}
but I don't know how to expand the combo box. Can anyone tell me how to do that?
Ok I got it done the expanding part
private void comboBox1_MouseHover(object sender, EventArgs e)
{
comboBox1.DroppedDown = true;
}
but I want to close the combo box when I leave the mouse pointer from the combo box.. How to do that?
Use the DroppedDown Property and make it true,
private void comboBox1_MouseHover(object sender, EventArgs e)
{
var box = sender as ComboBox ;
box.DroppedDown = true;
}
comboBox1.DroppedDown = true;
This has already been answered here Open ComboBox DropDown programmatically [duplicate]
which was actually a duplicate of Winforms: how to open combobox properly?

Show tooltip text by clicking a control [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Programatically show tooltip in winforms application
When set a TooltipText on a control, and the tooltip text will be shown when user move mouse on the control.
Now I have a picturebox on a windows form, what I want is to display the tooltip text by clicking the control instead of hover it.
How to do it?
Thanks.
This code will do the trick:
private void PictureBox1_Click(object sender, EventArgs e)
{
int durationMilliseconds = 10000;
ToolTip1.Show(ToolTip1.GetToolTip(PictureBox1), PictureBox1, durationMilliseconds);
}
Tooltip has a Show function. Just use that as necessary

Categories

Resources