• 大小: 0.25M
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2024-06-18
  • 语言: C#
  • 标签: wpf  wp  

资源简介


资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoScale.Library
{
    public class AutoSize
    {
        private SizeF _formSize;
        private List _dgvColumnsSize;
        private List _controlList;
        private List _controlFontSize;
        private bool _showRowHeader = false;
        private string _font = “Tahoma“;

        public AutoSize(Form form)
        {
            _dgvColumnsSize = new List();
            _controlList = new List();
            _controlFontSize = new List();

            SetInitialSize(form);
        }

        public void Resize(Form form)
        {
            if (form.ClientSize.Width > 0 || form.ClientSize.Height > 0)
            {
                double ratioWidth = Math.Round((double)form.ClientSize.Width / (double)_formSize.Width 2);
                double ratioHeight = Math.Round((double)form.ClientSize.Height / (double)_formSize.Height 2);
                var _controls = GetAllControls(form);
                int _pos = 0;

                foreach (Control control in _controls)
                {
                    if (control.Tag != null && control.Tag.ToString() == “justHeight“)
                    {
                        Size _controlSize = new Size((int)(_controlList[_pos].Width * 1)
                   (int)(_controlList[_pos].Height * ratioHeight));

                        Point _controlposition = new Point(
                            (int)(_controlList[_pos].X * 1)
                            (int)(_controlList[_pos].Y * 1));

                        control.Bounds = new Rectangle(_controlposition _controlSize);

                    }
                    else if (control.Tag != null && control.Tag.ToString() == “justWidth“)
                    {
                        Size _controlSize = new Size((int)(_controlList[_pos].Width * ratioHeight)
                   (int)(_controlList[_pos].Height * 1));

                        Point _controlposition = new Point(
                            (int)(_controlList[_pos].X * 1)
                            (int)(_controlList[_pos].Y * 1));

                        control.Bounds = new Rectangle(_controlposition _controlSize);

                    }
                    else
                    {
                        Size _controlSize = new Size((int)(_controlList[_pos].Width * ratioWidth)
                   (int)(_controlList[_pos].Height * ratioHeight));

                        Point _controlposition = new Point(
                            (int)(_controlList[_pos].X * ratioWidth)
                            (int)(_controlList[_pos].Y * ratioHeight));

                        control.Bounds = new Rectangle(_controlposition _controlSize);

                        if (control.GetType() == typeof(DataGridView))
                        {

评论

共有 条评论