Caret moves to the beginning of textbox when tooltip is displayed - c#

One of our customers showed me the problem described in subject. Every textbox in our application has a tooltip: when the control is selected, user starts typing; shortly after, tooltip is displayed if user leaves the cursor over the control. At the same moment, caret is moved at the beginning of texbox control, so if the user is typing, say "hello world" it comes up with something like "rldhello wo".
I'm using a custom UserControl. Tooltip is dropped on UserControl along with a Texbox and its value is set when the UserControl is loaded and when undelying property content for Textbox changes by the following code:
myTooltip.ToolTipTitle = title;
myTooltip.SetToolTip(myTextbox, content);
When user types, undelying property displayed in Texbox is updated, causing the refresh.
Do you have any experience or suggestion about this issue?

Related

What happen actually when TextBox got selected ? or got focused..?

I am trying to code for "Hint Text in Text Box" in C#. It works this way:
Initially show "Hint Text" with inactive caption color
Blank the text box if all the hint text is selected
Shows the user input text (after typing in this)
If user deletes his text and goes to the next control, then it shows the hint text again.
I need a help on 2nd point: It's not clearing the text box if its content is not selected. It receives the input text mixed with "hint text".
On which event I need to write the code txtBox1.Clear(); to achieve my aim?
Assuming this is WinForms: Look at the Enter and Leave events. They will be called when a control gets or loses focus. You then need to decide whether the value in the text box is your default hint or entered by the user.
For WPF: There are nice solutions out there that use adorners to achieve what you want. You could google for WPF textbox watermark adorner.

How to Insert the Cursor at the Beginning of Text in a Textbox Using WPF

I have a listbox which, when an item is selected, is used to populate a set of controls such as textboxes, radio buttons, and the like. What I want to do is cause the cursor to appear in the first textbox after the selected item is parsed into the respective controls. After spending time reading a number of posts here and researching on MSDN, I am still unable to accomplish this simple task.
In the code, I have txtInstName.Focus();. I have confirmed by checking the Keyboard.FocusedElement property that txtInstName does in fact have the focus. So how do I put the cursor at the beginning of the text in txtInstName? I've tried txtIns6tName.Select(0,0); but that does not insert the cursor where I want it.
Any ideas?
You can use the following property
MyTextBox.CaretIndex = someInt32;
this property gets or sets the insertion position index of the caret.

How does ToolTip show Popup on a control?

When set a TooltipText on a control, and the tooltip text will be shown when user move mouse on the control. Tooltip will detect MouseEnter or MouseLeave or anything for this purpose?
I want to know how does a Tooltip show Popup on a control?
Assume that I have a user control with name 'UserControlX'. On UserControlX, I put a button and set Dock property to Fill. I add a UserControlX on Form1, add a ToolTip and set a text to this usercontrol. ToolTip will be not shown when user move mouse on control because user is moving mouse on usercontrol's button, not usercontrol, so the tooltip will never show.
Please help me how to solve this problem so that when move mouse on UserControlX, the tooltip will be shown. Thanks.
I believe the tooltip displaying on mouse-over is defined within the control's default template. if you view the default template you will likely see a reference to a tooltip in there. If you go further and view the Tooltip's default template, you will see how it is composed as well as what events it listens to.
To answer your question, you could do what Adrian suggests and put the tooltip on the button as well as the parent control.
If you have time to mess around a bit, you COULD try to see if there is a tooltip displayed event or something to that effect for the button, and then simply invoke the parent control's tooltip manually. It could be considered a hack, but worth a try, maybe.

how to lose control from text box when clicked outside

I have a textbox in a windows form. Currently the focus is on the textbox and i enter some text. Now I click outside the textbox but within the window. This action does not make the text box to lose the focus. The cursor still blinks in the text box. If the click was on another control then the text box would lose the control.
How would I make the text box to lose control when clicked outside of it (not just on another control but anywhere inside the form)?
Thanks in advance.
Datte
Because you click on a control that has no ability of taking the focus (like a form, a label, etc). If you click for instance on another text box the focus should move..
To move the focus programmatically (i.e. in the OnClick event of the Form) use the control.Focus method.

Tabbing to invisible control in WinForms

I have a note editor control in my Windows Forms application:
alt text http://img82.imageshack.us/img82/2033/tabtohiddencontrol.png
I want to make this control accessible through the keyboard: I want to be able to TAB to it, TAB through the controls, and TAB out of it.
Normally this is an easy task, however, the issue is the hidden subject textbox. By design, the subject is editable only when the user clicks on the subject label.
When my control receives focus, I want to start editing the subject; make the subject text box visible and focused.
WinForms doesn't like this; my subject text box is hidden, and so WinForms skips over it when tabbing in and out of my control. How can I make this work?
You will have to add code in previous code's lostfocus (or keypress to check for TAB). And, you will have to add code in next control (after the label textbox) to check for Shift+TAB.
You could also add a label before Subject with mnemonic, so user can press ALT+S to reach there.
This is what I could think of right away.
Correct me, if I have not understood your question.
When the user clicks on the subject label, unhide the subject textbox and set the focus to it.
Controls must be visible and enabled to be part of the tab order; you cannot tab into a control that is invisible or disabled.

Categories

Resources