zoukankan      html  css  js  c++  java
  • c# winform窗口自适应各种分辨率类

     1 近期做项目时,遇到开发的winform在自己电脑上可以正常显示,共享到其他电脑就事儿不能显示了:
     2 
     3 1.当两个电脑分辨率相同时,无法显示完全,请检查form的autoscalemode属性是否为none,并设为none
     4 
     5 2.分辨率不同时,可直接在form的构造函数中调用初始化函数之后, 加上一句AutoReSizeForm. SetFormSize(this);(对于自定义控件usercontrol也适用)
     6 
     7 public class AutoReSizeForm
     8 
     9     {
    10          static float SH
    11          {
    12              get
    13              {
    14                  return (float)Screen.PrimaryScreen.Bounds.Height / Properties.Settings.Default.Y;
    15              }
    16          }
    17          static float SW
    18          {
    19              get
    20              {
    21                  return (float)Screen.PrimaryScreen.Bounds.Width / Properties.Settings.Default.X;
    22              }
    23          }
    24 
    25  
    26 
    27 
    28          public static void SetFormSize(Control fm)
    29          {
    30              fm.Location = new Point((int)(fm.Location.X * SW), (int)(fm.Location.Y * SH));
    31              fm.Size = new Size((int)(fm.Size.Width * SW), (int)(fm.Size.Height * SH));
    32              fm.Font = new Font(fm.Font.Name, fm.Font.Size * SH,fm.Font.Style,fm.Font.Unit,fm.Font.GdiCharSet,fm.Font.GdiVerticalFont);
    33              if (fm.Controls.Count!=0)
    34              {
    35                  SetControlSize(fm);
    36              }
    37          }
    38 
    39 
    40          private static void SetControlSize(Control InitC)
    41          {
    42              foreach (Control c in InitC.Controls)
    43              {
    44                  c.Location = new Point((int)(c.Location.X * SW), (int)(c.Location.Y * SH));
    45                  c.Size = new Size((int)(c.Size.Width * SW), (int)(c.Size.Height * SH));
    46                  c.Font = new Font(c.Font.Name, c.Font.Size * SH, c.Font.Style, c.Font.Unit, c.Font.GdiCharSet, c.Font.GdiVerticalFont);
    47                  if (c.Controls.Count != 0)
    48                  {
    49                      SetControlSize(c);
    50                  }
    51              }
    52          }
    53      }
  • 相关阅读:
    dynamic debug动态打印
    leetcode:Pascal's Triangle II (杨辉三角形,空间限制)【面试算法题】
    HDU 1671 Phone List 二叉树水题 数组建树法
    栈和队列
    一张图理解O(1)算法
    uva 10608
    C# 写的工作任务 Job 定时调度框架 WebWork (Quartz.NET) Web版的Windows服务
    PHP伪造referer突破防盗链
    php 文件上传一例简单代码
    PHP 图片文件上传代码
  • 原文地址:https://www.cnblogs.com/rinack/p/3109850.html
Copyright © 2011-2022 走看看