Dim ProportionsArray() As CtrlProportions
Private Sub Form1_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated
On Error Resume Next
Application.DoEvents()
ReDim ProportionsArray(0 To Controls.Count - 1)
For I As Integer = 0 To Controls.Count - 1
With ProportionsArray(I)
.HeightProportions = Controls(I).Height / Height
.WidthProportions = Controls(I).Width / Width
.TopProportions = Controls(I).Top / Height
.LeftProportions = Controls(I).Left / Width
End With
Next
End Sub
Private Structure CtrlProportions
Dim HeightProportions As Single
Dim WidthProportions As Single
Dim TopProportions As Single
Dim LeftProportions As Single
End Structure
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
On Error Resume Next
For I As Integer = 0 To Controls.Count - 1
Controls(I).Left = ProportionsArray(I).LeftProportions * Me.Width
Controls(I).Top = ProportionsArray(I).TopProportions * Me.Height
Controls(I).Width = ProportionsArray(I).WidthProportions * Me.Width
Controls(I).Height = ProportionsArray(I).HeightProportions * Me.Height
Next
End Sub
C#: http://pastebin.com/raw/krGQM5eu
public struct CtrlProportions
{
public float HeightProportions;
public float WidthProportions;
public float TopProportions;
public float LeftProportions;
}
CtrlProportions[] ProportionsArray;
private void Form1_Load(object sender, EventArgs e)
{
Application.DoEvents();
ProportionsArray = new CtrlProportions[Controls.Count];
for (int I = 0; I <= Controls.Count - 1; I++)
{
ProportionsArray[I].HeightProportions = (float) Controls[I].Height / this.Height;
ProportionsArray[I].WidthProportions = (float) Controls[I].Width / this.Width;
ProportionsArray[I].TopProportions = (float)Controls[I].Top / this.Height;
ProportionsArray[I].LeftProportions = (float) Controls[I].Left / this.Width;
}
}
private void Form1_Resize(object sender, System.EventArgs e)
{
for (int I = 0; I <= Controls.Count - 1; I++)
{
Controls[I].Left = (int)(ProportionsArray[I].LeftProportions * this.Width);
Controls[I].Top = (int) (ProportionsArray[I].TopProportions * this.Height);
Controls[I].Width = (int) (ProportionsArray[I].WidthProportions * this.Width);
Controls[I].Height = (int) (ProportionsArray[I].HeightProportions * this.Height);
}
}
0 comments:
Post a Comment