Question Get rid of designer resize handles

Pirahnaplant

Well-known member
Joined
Mar 29, 2009
Messages
75
Programming Experience
3-5
How can I make my UserControl not have the resizing handles when placed on a form in design mode; similar to a label or a textbox?
 
This is how the ControlDesigner for Label does it:
VB.NET:
Friend Class LabelDesigner
    Inherits ControlDesigner
    ' Methods
    Public Sub New()
        MyBase.AutoResizeHandles = True
    End Sub
 
    ' Properties
    Public Overrides ReadOnly Property SelectionRules() As SelectionRules
        Get
            Dim _selectionRules As SelectionRules = MyBase.SelectionRules
            Dim component As Object = MyBase.Component
            Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(component).Item("AutoSize")
            If ((Not descriptor Is Nothing) AndAlso CBool(descriptor.GetValue(component))) Then
                _selectionRules = (_selectionRules And Not SelectionRules.AllSizeable)
            End If
            Return _selectionRules
        End Get
    End Property

End Class

'(the code for text alignment snaplines was removed)
To define this Designer for your control:
VB.NET:
Imports System.Windows.Forms.Design
Imports System.ComponentModel

<Designer(GetType(LabelDesigner))> _
 Public Class UserControl1
Requires reference to System.Design.

With this configured resize handles depends on the AutoSize property.

Code courtesy of .Net class library and .NET Reflector, class browser, analyzer and decompiler for .NET :)
 
Back
Top