Preventing TabIndex property code from being generated.
My custom controls are not allowed tab access, much like the Label control, so I would like to prevent designer-code from being generated for the property. I have tried the following:
vb.net Code:
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Overloads Property TabIndex As Int32
Those are the same attributes I use to hide other properties that I don't want to show up in the designer-generated code, because I set them at runtime. But, it does not work. I have also tried declaring TabIndex as Shadows. The TabIndex property still shows up in the designer and in the designer-generated code.
I looked at the code for Label in Reflector and saw no mention of TabIndex at all. How does it hide it?
Re: Preventing TabIndex property code from being generated.
you could use a ControlDesigner class to remove the properties:
Code:
Imports System.ComponentModel
<DesignerAttribute(GetType(MyControlDesigner))> _
Public Class UserControl1
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Code:
Imports System.Windows.Forms.Design
Public Class MyControlDesigner
Inherits ControlDesigner
Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary)
MyBase.PreFilterProperties(properties)
Dim pi As List(Of DictionaryEntry) = properties.Cast(Of DictionaryEntry).ToList
Dim remove() As String = {"TabIndex", "TabStop"}
For x As Integer = pi.Count - 1 To 0 Step -1
If remove.Contains(pi(x).Key.ToString) Then
properties.Remove(pi(x).Key.ToString)
End If
Next
End Sub
End Class
you need a reference to System.Design