.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Steve Jackman
Imran Ghani
Santhakumar Munuswamy

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

how to expand all contols of a winform by Maximize a form

Posted By: Chandranshu Awasthi     Posted Date: April 15, 2011    Points:5   Category :C#

i have a form and have many controls on it. if i maximize the form the controls are not expanding

i have used anchor and dock property is there any other method

plz ans this question

Author: Mahesh             
Posted Date: April 17, 2011     Points: 20   

i had done this thing in VB6 the code is as below you can convert it, as per your application,

Option Explicit
Private nFormHeight As Integer
Private nFormWidth As Integer
Private nNumOfControls As Integer
Private nTop() As Integer
Private nLeft() As Integer
Private nHeight() As Integer
Private nWidth() As Integer
Private nFontSize() As Integer
Private nRightMargin() As Integer
Private bFirstTime As Boolean

Public Sub Init(frm As Form, Optional nWindState As Variant)

Dim I As Integer
Dim bWinMax As Boolean

bWinMax = Not IsMissing(nWindState)

nFormHeight = frm.Height
nFormWidth = frm.Width
nNumOfControls = frm.Controls.Count - 1
bFirstTime = True
ReDim nTop(nNumOfControls)
ReDim nLeft(nNumOfControls)
ReDim nHeight(nNumOfControls)
ReDim nWidth(nNumOfControls)
ReDim nFontSize(nNumOfControls)

ReDim nRightMargin(nNumOfControls)
On Error Resume Next
For I = 0 To nNumOfControls
If TypeOf frm.Controls(I) Is Line Then
nTop(I) = frm.Controls(I).Y1
nLeft(I) = frm.Controls(I).X1
nHeight(I) = frm.Controls(I).Y2
nWidth(I) = frm.Controls(I).X2
nTop(I) = frm.Controls(I).Top
nLeft(I) = frm.Controls(I).Left
nHeight(I) = frm.Controls(I).Height
nWidth(I) = frm.Controls(I).Width
nFontSize(I) = frm.FontSize
nRightMargin(I) = frm.Controls(I).RightMargin
End If

If bWinMax Or frm.WindowState = 2 Then ' maxim
frm.Height = Screen.Height
frm.Width = Screen.Width
frm.Height = frm.Height * Screen.Height / 7290
frm.Width = frm.Width * Screen.Width / 9690
End If

bFirstTime = True

End Sub

Public Sub FormResize(frm As Form)

Dim I As Integer
Dim nCaptionSize As Integer
Dim dRatioX As Double
Dim dRatioY As Double
Dim nSaveRedraw As Long

On Error Resume Next
nSaveRedraw = frm.AutoRedraw

frm.AutoRedraw = True

If bFirstTime Then
bFirstTime = False
Exit Sub
End If

If frm.Height < nFormHeight / 2 Then frm.Height = nFormHeight / 2

If frm.Width < nFormWidth / 2 Then frm.Width = nFormWidth / 2
nCaptionSize = 400
dRatioY = 1# * (nFormHeight - nCaptionSize) / (frm.Height - nCaptionSize)
dRatioX = 1# * nFormWidth / frm.Width
On Error Resume Next ' for comboboxes, timeres and other nonsizible controls

For I = 0 To nNumOfControls
If TypeOf frm.Controls(I) Is Line Then
frm.Controls(I).Y1 = Int(nTop(I) / dRatioY)
frm.Controls(I).X1 = Int(nLeft(I) / dRatioX)
frm.Controls(I).Y2 = Int(nHeight(I) / dRatioY)
frm.Controls(I).X2 = Int(nWidth(I) / dRatioX)
frm.Controls(I).Top = Int(nTop(I) / dRatioY)
frm.Controls(I).Left = Int(nLeft(I) / dRatioX)
frm.Controls(I).Height = Int(nHeight(I) / dRatioY)
frm.Controls(I).Width = Int(nWidth(I) / dRatioX)
frm.Controls(I).FontSize = Int(nFontSize(I) / dRatioX) + Int(nFontSize(I) / dRatioX) Mod 2
frm.Controls(I).RightMargin = Int(nRightMargin(I) / dRatioY)
End If

frm.AutoRedraw = nSaveRedraw

End Sub


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend