Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: User-controls VB.NET
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 20-Nov-11 9:59am
Comments
SAKryukov at 20-Nov-11 15:42pm
   
Do you mean sizing handles which appear only when working with the Designer?
--SA
fadi77_net at 20-Nov-11 16:31pm
   
yes, the white squires that appears on the control at design time.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :)
 
Valery.
  Permalink  
Comments
fadi77_net at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello,
 
It does work but probably I did not give enough details. Frown | :(
 
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:
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:
 
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.
  Permalink  
Comments
fadi77_net at 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)

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 26 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100