简体   繁体   中英

How to remove a LinkLabel as a tab stop when using .NET 3.5?

When a user tabs through the fields they have to tab through a LinkLabel to get to the next field. I would rather them go straight from field to field without stopping on the LinkLabel. However, in .NET 3.5 the LinkLabel does not have a TabStop property to set equal to false. Upgrading to .NET 4.0 or .NET 4.5 is not an option today.

I've tried two other possible ways of skipping the LinkLabel that do not work.

  1. Put the LinkLabel on a panel and set the TabStop property on the panel to false. The LinkLabel still gets tabbed to.

  2. Process the Enter event on the LinkLabel and use SendKeys or some such nonsense to continue to the next control. This doesn't work because it makes the Click event stop firing.

I also considered setting the TabIndex for all LinkLabels on the form to a much higher value than the rest of the controls. However, that would not work either

Each field is a TextBox or ComboBox on a panel with a Label. The ComboBox fields have an additional control on the Panel with them: a LinkLabel that says "Edit Items". Each of these Panels are on the main FlowLayoutPanel.

Correct me if I'm wrong. The way I understand tab order of controls on nested panels is that each Panel would have its own Tab Order. Then the tab order of each is combined in series based on the TabIndex of each Panel to determine the effective tab order of the controls on the form. Right? So setting the TabIndex of each LinkLabel to a number in the high 200s would not fix the original problem, the way I see it.

Has anyone seen this challenge before? How did you solve it? I feel like I may have to do something drastic like sub-class the LinkLabel control. What would you do?

That was a mistake, LinkLabel inherits from Label which doesn't have meaningful support for focusing. So the property is hidden in the Properties window, like it is for Label. .NET 4.0 corrected this mistake.

It is not a real problem, the property is still available. Just set it in code instead:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        linkLabel1.TabStop = false;
    }
    // etc..
}

Note that the property is also hidden for IntelliSense so don't be surprised that you don't get help.

With LinkLabel , we should set TabStop property by code, cannot setting by change Properties Windows.

When VisualStudio generates code from GUI, it do like this:

this.linkbThread.TabIndex = 31;        //first
this.linkbThread.Text = "My URL";      //second

But MSDN said:

"However, be aware that adding new links to the Links collection will automatically set the TabStop property to true again."

So if we change TabStop property in Properties Windows, or insert code linkbThread.TabStop = false before the assign linkbThread.Text = "My URL" , it isn't worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM