I have a TextBox and a button: button_InputComplete. When I finished inputting the data in the TextBox I press the button and the button_Click event handler is invoked.
While the button_Click event handler is executing there remains a cursor in the TextBox at the end of the input data (a vertical blinking line).
I would like to hide this cursor. I do not mean the mouse pointer but the cursor in the TextBox (the vertical blinking line). I also need to be able to restore it.
The Cursor.Hide() statement hides the mouse pointer.
I tried to move the focus away from the TextBox with the statement: this.Select(); but the cursor remained in the TextBox.
I also tried the statement: control.Select(); where control is an instance of another control located on the form (not the TextBox), but neither this worked (the cursor remained in the TextBox).
Any help with an idea would be greatly appreciated.
Thank you in advance.
Related
as a part of my WinForms application, I want to move a picturebox (blue box) onto the grid as seen below.
I'm moving the picturebox according to the mouse positions (while the left mouse button is pressed down).
Now my problem is, that when dragging the picturebox over the grid, the MouseEnter event is supposed to be called (each box in the grid is a picturebox in itself, with the event attached to it). The event gets called when simply moving with the mouse over it, but as soon as I'm dragging the blue box over it, it doesn't.
So my question is, is it possible that the picturebox on top (blue box) blocks the MouseEnter event of the picturebox on the bottom from firing? And if so, is there a way to work around it? I've thought about using Drag&Drop, but this seemed as the easier solution.
Thanks in advance.
I am developing a Custom Editable Text Block for my Application. So when the User clicks on the Control, TextBox swaps in for the User to edit the Text. Everything is fine till now, Now my requirement is I want the caret index of TextBox to exactly where the user had clicked on the TextBlock.
So the user won't feel about the swap from UI Point of View.
What approach would be more appropriate? Considering the above factors?!
I am lost in ideas for this thing.
I assume you have a UserControl/Customcontrol with its own Mouse handling support, and a way to tell when to switch the content from TextBlock to TextBox.
In the mousedown event you could store the clicked position, swap to the textbox and in the Loaded event you could use GetCharacterIndexFromPoint to tell which is the position of the click and set the CaretIndex to that position. You might have to adjust your margins if you use any.
I've created a form that's maximized over the entire screen.
Within that form, and sized to fill the entire form, I've placed a panel with background color set to Red. The form's TransparencyKey is set to Red.
Therefore, the Panel is like a "keyhole" - you can see the desktop that's directly underneath it.
When the user clicks on the panel, OR, presses a key on the keyboard, I want to take action.
But, because the panel is completely transparent, when it is clicked or a key is pressed, nothing happens. If I make the panel non-transparent (setting it's background color to Blue, for example), it does respond to clicks.
What's the best way to get the panel to respond to clicks and keypresses?
Do I have to hook all mouse an keyboard events on the entire system or is there a simpler way?
The panel does not take in text input, you can set your main form to handle the keypress event.
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.form_KeyPress);
http://screensnapr.com/v/VovWAi.png
As for getting the mouse location on your panel, you can use the mouseclick event
this.panel1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseClick);
http://screensnapr.com/v/DB3kCQ.png
I have tested it, and it works on a fullsize transparent panel
I've discovered that I can use GetAsyncKeyState to respond to both keypresses and mouse clicks.
[DllImport("user32.dll")]
public static extern int GetAsyncKeyState(System.Windows.Forms.Keys vKey);
Then, I can call GetAsyncKeyState(Keys.LButton) and GetAsyncKeyState(Keys.Escape), for example. Much simpler than hooking all keyboard and mouse events.
Here is the problem:
I have a simple c# form
I have a simple c# user control containing a picturebox and other button.
My form contains one instance of the user control.
I want that when the user do a mouseEnter in the picture box, the mouse cursor change and when the user do a mouseLeave of the picturebox, the mouse go back to normal.
What is happening now is that the events are not fired at all. I put break point into MouseOver, MouseEnter, MouseMove, MouseLeave, etc and none of thems fired. It's the first time I have this problem in C#.
I think it has something to do with the "routed event" but I can't figure it out. If there is another way to achieve what I'm doing, this will also be considered a solution. What is important is that at the end, the user control will be the master of the mouse cursor over his "territory".
Thanks in advance!
What events are you using? The UserController.MouseEnter and UserController.MouseLeave events or the PictureBox.MouseEnter and PictureBox.MouseLeave events?
You should use the latter as the PictureBox will handle the event if the mouse enters the user controller directly through the PictureBox.
As InBetween wrote, PictureBox.MouseXXX should be firing. You can trap those in your UserControl.
If you want the event to be fired on behalf of UserControl, just disable the PictureBox. Be aware though that the event would fire for any mouse position over the UserContrl, not only the PictureBox.
I have a c# .net 2.0 winForm with a textbox and a trackbar. The textbox Validating event sets e.cancel if the user clicks the trackbar and the validation fails. I am then left with the cursor in the textbox, but the mouse focus is still on the trackbar so moving the mouse moves the trackbar.
I have tried SetFocus in the validating event (bad according to MSDN but I tried anyway) but the mouse stays on the trackbar.
How do I detach the mouse focus from the trackbar?
Are you displaying the validation error message in a message box. If that is the case the mouse release of trackbar wouldnt have fired as the message box would have taken control and that's the reason you are seeing the trackbar moving after you exit the message box.
MessageBox and validating event dont go well with each other. Best way to do it is to use a ErrorProvider.