|
-
Oct 20th, 2002, 04:36 PM
#1
Thread Starter
Member
Resize Form Controls !!!!!!!!!!!!
I have ( as first shot ) a small class that resizes my controls in the main form of me vb.net app. I can use this stupit anchors from .net.
The only problem is that this class is a bit slow, not to much, but i think it could be better !
This is me challenge for everyone here in this forum to help me speed up this class. Or maybe someone has a much better idea.
This is the class (forget the error handling) :
VB Code:
Imports System.Drawing
Imports System.Convert
Imports System.Windows.Forms
Public Class clsResize
Implements IDisposable
#Region " Declare private vars "
Private blnDisposed As Boolean
Private objFormSize As Size
Private colControls As New Collection()
Private Structure Properties
Dim Left As Integer
Dim Top As Integer
Dim Width As Integer
Dim Height As Integer
Dim FontSize As Single
End Structure
#End Region
#Region " Initialize and dispose "
Public Sub New(ByRef frm As Form)
' initialize the resize class by collecting control properties
Dim objControl As Control
Dim stuCtrlProp As Properties
' store original form size
objFormSize = frm.Size
' for controls who don't support all the properties resume on error
On Error Resume Next
For Each objControl In frm.Controls
With stuCtrlProp
.Left = objControl.Left
.Top = objControl.Top
.Width = objControl.Width
.Height = objControl.Height
.FontSize = objControl.Font.Size
End With
colControls.Add(stuCtrlProp, objControl.Name)
Next
' clean up
objControl = Nothing
' we made a new instance so set blnDisposed to false
blnDisposed = False
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
' clean up objects
If Not blnDisposed Then
objFormSize = Nothing
colControls = Nothing
blnDisposed = True
End If
End Sub
#End Region
#Region " Resize the from "
Public Sub Resize(ByRef frm As Form)
Dim dblRatioX As Double
Dim dblRatioY As Double
Dim intWinMax As Integer
Dim objControl As Control
Dim stuCtrlProp As Properties
' setup scaling ratios
intWinMax = 40
dblRatioY = 1.0# * (objFormSize.Height - intWinMax) / (frm.Height - intWinMax)
dblRatioX = 1.0# * objFormSize.Width / frm.Width
' for comboboxes, timeres and other nonsizible controls resume on error next
On Error Resume Next
' reposition and resize the controls
For Each objControl In frm.Controls
stuCtrlProp = CType(colControls.Item(objControl.Name), Properties)
With stuCtrlProp
objControl.SetBounds(ToInt32(.Left / dblRatioX), ToInt32(.Top / dblRatioY), ToInt32(.Width / dblRatioX), ToInt32(.Height / dblRatioY))
objControl.Font = New Font(objControl.Font.Name, ToSingle(.FontSize / dblRatioX) + ToSingle(.FontSize / dblRatioX) Mod 2)
End With
Next
' clean up
objControl = Nothing
End Sub
#End Region
End Class
Last edited by Josch; Oct 20th, 2002 at 04:39 PM.
-
Oct 20th, 2002, 05:33 PM
#2
PowerPoster
What is wrong with the anchors?
-
Oct 20th, 2002, 07:49 PM
#3
Hyperactive Member
Yes good use of the anchor property normally works a treat.
-
Oct 21st, 2002, 02:07 PM
#4
Thread Starter
Member
Please try the anchors with a form that only consists of pictureboxes and textboxes on bitmap backgound where you can't use panels to group controls.
-
Oct 21st, 2002, 07:49 PM
#5
PowerPoster
Why can't you use panels to group controls? You can set the panel's backcolor to transparent.
-
Oct 22nd, 2002, 01:13 PM
#6
Thread Starter
Member
Originally posted by hellswraith
Why can't you use panels to group controls? You can set the panel's backcolor to transparent.
Transparent background color does not work.
-
Oct 22nd, 2002, 05:35 PM
#7
PowerPoster
Send me the code of your form, basically just the VS created code for your controls. Let me see what your doing.
I have had to write some resize code, but I still used anchoring on every control. It just depends on how you want to resize things.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|