Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all
I am creating a user control, it is numerical text box, but I have a problem, I want to remove the height sizing handles from my control and keep the width sizing handles.
Can you help me please?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Nov-11 15:42pm    
Do you mean sizing handles which appear only when working with the Designer?
--SA
fadi77_net 20-Nov-11 16:31pm    
yes, the white squires that appears on the control at design time.

Hello,

You will need to add a designer for your user control and use SelectionRules. (add a reference to System.Design.dll)

Public Overrides ReadOnly Property SelectionRules As SelectionRules
Get
    Return MyBase.SelectionRules And Not SelectionRules.AllSizeable
End Get
End Property


To add a designer add a designer attribute:

<designer(gettype(mydesigner))> _
Public Class MyUserControl
	Inherits System.Windows.Forms.UserControl


Then add a new designer class :
Imports System.Windows.Forms.Design

Public Class MyDesigner
	Inherits System.Windows.Forms.Design.ControlDesigner

    Public Overrides ReadOnly Property SelectionRules() As System.Windows.Forms.Design.SelectionRules
        Get
            Return MyBase.SelectionRules And Not SelectionRules.AllSizeable
        End Get
    End Property
End Class


That should do the trick... I am a C# developer excuse the VB.net errors :)

Valery.
 
Share this answer
 
Comments
fadi77_net 22-Nov-11 17:08pm    
This code is not working, there are some errors. Can you write it in C# please? I will change it from C# to VB
Hello,

It does work but probably I did not give enough details. :(

First make sure you target .Net4 not .Net4 client profile, go to project properties, Compile tab, Advanced Compile options, at the bottom select .Net 4 (not the default .Net4 client profile)

Second create your user control. (I called it UserControl1)

Third add a reference in you project to "System.Design.dll" (it is located in C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 )

Fourth add a new class in your project, and use this code:
VB
Imports System.Windows.Forms.Design

Public Class UserControl1Designer
    Inherits System.Windows.Forms.Design.ControlDesigner

    Public Overrides ReadOnly Property SelectionRules() As System.Windows.Forms.Design.SelectionRules
        Get
            Return MyBase.SelectionRules And Not SelectionRules.AllSizeable
        End Get
    End Property
End Class


Fifth Open up the code of your user control (press F7 if you are in the designer)
make sure it looks like something like that:

VB
Imports System.ComponentModel

<designer(gettype(usercontrol1designer))>
Public Class UserControl1
    Inherits System.Windows.Forms.UserControl
End Class

Done.

Now when you will drag your usercontrol on a form you will notice that it is not resizable.

Valery.
 
Share this answer
 
Comments
fadi77_net 1-Dec-11 13:00pm    
Thank you very much, it is working properly now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900