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
Related
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;
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();
}));
}
This question already has answers here:
How to create a right click event handler in c#
(4 answers)
Closed 7 years ago.
I'm a beginner, so this may be easy. But i could not find it. I want to add a right click event to a windows form. but when i look properties/events menu of the form, I could not find any right click event. Is there a menu or code example for that? i prefer to use it auto constructed like double clicking for click event, so it is better to me if you can show me how can i find that property if it exists.
Thanks for helping.
its a mousedown event,
private void btn_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
// do your stuff
}
}
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?
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
(C#) How to detect when a windows form is being minimized
First of all my code:
private void Form1_Load(object sender, EventArgs e)
{
this.MinimumSizeChanged += new EventHandler(Form1_MinimumSizeChanged);
}
void Form1_MinimumSizeChanged(object sender, EventArgs e)
{
MessageBox.Show("1");
}
so, my program idea is, when the program get minized i will do a system tray, but this event never happnd. how can i know when the user do a minize screen(minize the program).
i have tryed everything. any ideas?
MinimumSizeChanged has nothing to do with the form getting minimized. MinimumSizeChanged has to deal with when the MinimumSize properties of the form are changed.
You want to check the Resize event of the form.
In order to minimize to the system tray, add a NotifyIcon control to your form. Now, override the OnResize method and check if your WindowState property is set to FormWindowState.Minimized. If it is, Hide() your forms and show your notify icon. Make sure to set the Icon property of the NotifyIcon as well. Now just reverse the process for the case when the form is restored.