提问人:Mo Mo 提问时间:5/31/2023 最后编辑:Mo Mo 更新时间:5/31/2023 访问量:22
我想增强我的控制器调整器代码
i want to enhance my controllers resizer code
问:
这不是问题,更多的是增强。 我写这篇文章是为了控制 Windows 窗体上的自动调整大小控制器
但是当最大化时,高度间隙比旧高度和新高度之间的比率更小
//width and height control functions
//at using make sure exists or add:
//using System.Data;
// put in form load
//setinitialsize();
// put in form resize();
// newsize();
DataTable initialsize = new DataTable();
private void setinitialsize()
{
initialsize.Columns.Add("height");
initialsize.Columns.Add("width");
initialsize.Columns.Add("top");
initialsize.Columns.Add("left");
//initialsize.Columns.Add("control");
DataRow initialrow = initialsize.NewRow();
initialrow[0] = (int)this.Height;
initialrow[1] = (int)this.Width;
initialrow[2] = 0;
initialrow[3] = 0;
//initialrow[4] = this.Name;
initialsize.Rows.Add(initialrow);
foreach (Control c in this.Controls)
{
DataRow initialrow2 = initialsize.NewRow();
initialrow2[0] = (int)c.Height;
initialrow2[1] = (int)c.Width;
initialrow2[2] = (int)c.Top; ;
initialrow2[3] = (int)c.Left; ;
//initialrow2[4] = c.Name;
initialsize.Rows.Add(initialrow2);
}
}
private void newsize()
{
int n = 1;
float heightrate = (this.Height / float.Parse(initialsize.Rows[0][0].ToString()));
float widthrate = (this.Width / float.Parse(initialsize.Rows[0][1].ToString()));
foreach (Control c in this.Controls)
{
int cHeight = (int)(heightrate * int.Parse(initialsize.Rows[n][0].ToString()));
if ((cHeight <= this.Height) && (cHeight > 0)) { c.Height = cHeight; }
int cWidth = (int)(widthrate * int.Parse(initialsize.Rows[n][1].ToString()));
if ((cWidth <= this.Width) && (cWidth > 0)) { c.Width = cWidth; }
int cTop = (int)(heightrate * int.Parse(initialsize.Rows[n][2].ToString()));
if ((cTop >= 0) && ((cTop + cHeight) < this.Height)) { c.Top = cTop; }
int cLeft = (int)(widthrate * int.Parse(initialsize.Rows[n][3].ToString()));
if ((cLeft >= 0) && ((cLeft + cWidth) < this.Width)) { c.Left = cLeft; }
n++;
}
}
如何增强此功能以顺利调整大小并避免可能发生任何未发现的问题?
答: 暂无答案
评论