DOCUMENT:Q190224 11-JAN-2001 [vbwin] TITLE :HOWTO: Set a Minimum and Maximum Size for a UserControl PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS: KEYWORDS:kbcode kbCtrlCreate kbVBp500 kbVBp600 kbGrpDSVB ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0 - Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0 - Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0 ------------------------------------------------------------------------------- SUMMARY ======= When you create UserControls in Visual Basic, you may want to limit the size of your UserControl. This article shows how to set a minimum and maximum size for your UserControl so that a developer who uses the control can't size the control past the preset minimum or maximum. MORE INFORMATION ================ This example uses a UserControl that is inside a Standard EXE project. You can use the same technique for a UserControl in an ActiveX Control project. When the ActiveX control is built, anyone using the ActiveX control will not be able to size it any larger or smaller then the limits you set inside the UserControl itself. NOTE: This is only intended to work within Visual Basic applications and may not work in other containers, such as Microsoft Word or Excel. Steps to Create Sample Project ------------------------------ 1. Create a new Standard EXE project. Form1 is created by default. 2. Add a UserControl to the Project by clicking Add UserControl on the Projects menu and then clicking Open. 3. Change the BackColor property of the UserControl to a different color, such as red. 4. Add two labels to the UserControl. 5. Add the following code to the code window for the UserControl: Private Sub UserControl_Resize() ' Check to see if the control is larger or smaller than the preset ' minimum or maximum size. ' If it is larger or smaller, set the size of the control. Select Case Height Case Is < 2400 Height = 2400 Case Is > 3600 Height = 3600 End Select Select Case Width Case Is < 2400 Width = 2400 Case Is > 3600 Width = 3600 End Select ' The label reports the height and width of the control in ' twips even if the container has a different scalemode. Label1.Caption = "Height: " & Height Label2.Caption = "Width: " & Width End Sub 6. Close the UserControl and it appears in the ToolBox. Place it on Form1. 7. Try resizing the UserControl. If you try to make the control larger or smaller then the limit you set in the Resize event of the UserControl, the control returns to the maximum or minimum size. (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Brian Combs, Microsoft Corporation ====================================================================== Keywords : kbcode kbCtrlCreate kbVBp500 kbVBp600 kbGrpDSVB Technology : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVBA500 kbVBA600 kbVB500 kbVB600 Version : WINDOWS:5.0 Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.