views:

212

answers:

3

I have an application where I am trying to mimic the "soft description" textboxes like those found for the tags and title locations on this site.

The way I've done this is essentially to create my textbox, and depending on what happens when the mouse pointer enters or leaves the control, it updates the content of the textbox to get the effect.

The problem is what when my form is first shown, the mouse cursor immediately jumps into the first textbox, which removes the title telling the user what the textbox is for.

If I turn off AcceptTab on the textbox, then everything works as expected, but the user loses the ability to tab into the textbox.

Is there a way to turn off this automatic selection of the textbox?

+2  A: 

Could you this.Focus() on the form itself, or on some label control?

uosɐſ
"The Windows Forms controls in the following list are not selectable. Controls derived from these controls are also not selectable. ... Panel, GroupBox, PictureBox, ProgressBar, Splitter, **Label**, LinkLabel" -- http://msdn.microsoft.com/en-us/library/system.windows.forms.control.focus.aspx
R. Bemrose
No joy. :( Selecting the form implicitly selects the item with the first tabindex, which happens to be our friendly neighborhood textbox.
Billy ONeal
If you have no other controls on the form to focus on instead (an OK button?) .. What if you create a new TextBox without assigning it to the form and focusing on that. Or SuspendLayout(), add it to the form, focus on it, remove it from the form, ResumeLayout()?
uosɐſ
Removing it from the form just forces control to the next control on the tabindex.
Billy ONeal
What do you mean by "soft description". What are you trying to make it look like. You mean the "Click here to type" kind of message? Why not have a cancel button and make that tabindex 1, all your textboxes, and then an OK button last?
uosɐſ
I mean this -> http://stackoverflow.com/questions/2291580/modifying-a-textbox-control-on-the-leave-event-prevents-tabbing-out-of-the-contro
Billy ONeal
I don't have a cancel button I can use for this purpose, unfortunately.
Billy ONeal
A: 

The TabIndex property controls what order things will tab in, and on load, focus goes to the first control (ordered by TabIndex) that has AcceptTab as true. You can change the ordering so that the control that you want the user focus to start in is lowest (and have tabs work cycle through controls as you'd expect).

Alternatively, as Jason suggested, you could simply call Focus() on whatever control or the form itself in the FormLoad event.

Tanzelax
Simply repeating what I've already put in the question doesn't tell me all that much. I already stated I knew tabbing was the cause. I was looking for a way to turn off the implicit first tab when the form is shown.
Billy ONeal
A: 

I used a variant on Jason's technique. First, I created a dummy textbox with tabindex 0. That way, when the form is shown, that textbox will be selected. Next, I made the dummy textbox have zero width, so that it has no visible component.

However, once the form is loaded, I don't want the user to be able to tab over to the "nonexistant" textbox. Therefore, I added these two bits:

    //These functions prevent the textboxes from being implicitly selected.
    private void dummyBox_Leave(object sender, EventArgs e)
    {
        dummyBox.TabStop = false;
    }

    private void Main_Enter(object sender, EventArgs e)
    {
        dummyBox.TabStop = true;
        dummyBox.Select();
    }

Where Main is the name of my form.

Hope this helps someone.

Billy3

Billy ONeal