2012年5月10日 星期四

C# Form內的物件要如何等比放大

參考引用
--
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. this.Tag = this.Height + "|" + this.Width;
  4. foreach (Control o in this.Controls)
  5. {
  6. o.Tag = o.Top + "|" + o.Left + "|" + o.Height + "|" + o.Width;
  7. }
  8. }
  9.  
  10. private void Form1_Resize(object sender, EventArgs e)
  11. {
  12. foreach (Control o in this.Controls)
  13. {
  14. o.Width =(int)(double.Parse(o.Tag.ToString().Split('|')[3]) * (this.Width / double.Parse(this.Tag.ToString().Split('|')[1])));
  15. o.Height =(int)(double.Parse(o.Tag.ToString().Split('|')[2]) * (this.Height / double.Parse(this.Tag.ToString().Split('|')[0])));
  16. o.Left =(int)(double.Parse(o.Tag.ToString().Split('|')[1]) * (this.Width / double.Parse(this.Tag.ToString().Split('|')[1])));
  17. o.Top =(int)(double.Parse(o.Tag.ToString().Split('|')[0]) * (this.Height / double.Parse(this.Tag.ToString().Split('|')[0])));
  18. }
  19. }

沒有留言:

張貼留言