資源簡介
代碼片段和文件信息
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))
????????????????????????{
評論
共有 條評論