Results 1 to 2 of 2

Thread: Preventing TabIndex property code from being generated.

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    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:
    1. <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    2. 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?
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width