Skip to content

Instantly share code, notes, and snippets.

@minhphuc429
Last active July 21, 2017 09:35
Show Gist options
  • Save minhphuc429/fbd590eb235fc3866554 to your computer and use it in GitHub Desktop.
Save minhphuc429/fbd590eb235fc3866554 to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment