屏幕分辨率自适应算法

  1. private void Resolution (Control. ControlCollection Con )
  2. {
  3. //遍历控件
  4. System. Drawing. Rectangle rc = System. Windows. Forms. Screen. PrimaryScreen. WorkingArea;
  5. for ( int i = 0; i < Con. Count; i ++ )
  6. {
  7. Con [i ]. Anchor = ( ( System. Windows. Forms. AnchorStyles ) ( System. Windows. Forms. AnchorStyles. Top | System. Windows. Forms. AnchorStyles. Left ) );
  8. if (Con [i ]. Dock == DockStyle. Fill )
  9. {
  10. Con [i ]. Font = new System. Drawing. Font ( "Microsoft Sans Serif", Con [i ]. Font. Size * rc. Width / 1024 ,Con [i ]. Font. Style, System. Drawing. GraphicsUnit. Point, ( ( byte ) ( 0 ) ) );
  11. }
  12. Con [i ]. Width = Con [i ]. Width * rc. Width / 1024; //现有屏幕比例和标准比例换算,标准为1024*768,
  13. Con [i ]. Height = Con [i ]. Height * rc. Height / 738; //738为除去工具条后的标准Height.
  14. Con [i ]. Left = Con [i ]. Left * rc. Width / 1024;
  15. Con [i ]. Top = Con [i ]. Top * rc. Height / 738;
  16. if (Con [i ]. Controls. Count > 0 )
  17. {
  18. Resolution (Con [i ]. Controls ); //递归
  19. }
  20.  
  21. }
  22. }

你可能感兴趣的:(分辨率)