[英]How to maintain aspect ratio of datagridview column width when win form resize
我有一個獲勝形式,只有一個網格。 Grid Dock屬性設置為fill 。 當我將網格與數據綁定時,我還會像這樣提及所有列寬。
dgList.DataSource = ds.Tables[0];
dgList.Columns[0].Width = 100;
dgList.Columns[1].Width = 100;
dgList.Columns[2].Width = 262;
dgList.Columns[3].Width = 530;
因此,我想知道何時調整表單大小,然后網格的高度和寬度也會成比例地增加。 因此,當網格的高度和寬度將發生變化時,我想按先前的列寬按比例增加或減少列。 那么如何實現它。 謝謝。
1) var gcd = GCD(A, B);
return string.Format("{0}:{1}", A / gcd, B / gcd)
And a very basic function for calculating the GCD, using the Euclidean algorithm:
static int GCD(int a, int b) {
return b == 0 ? a : GCD(b, a % b);
}
2)
public int GCD(int a, int b)
{
while (a != 0 && b != 0)
{
if (a > b)
a %= b;
else
b %= a;
}
if (a == 0)
return b;
else
return a;
}
// Using Konrad's code:
var gcd = GCD(A, B);
return string.Format("{0}:{1}", A / gcd, B / gcd)
3)
private int FindHCF(int m, int n)
{
int temp, reminder;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
while (true)
{
reminder = m % n;
if (reminder == 0)
return n;
else
m = n;
n = reminder;
}
}
So here is the rest of the code
int hcf = FindHcf(835, 625);
int factorW = 835 / hcf;
int factorH = 625 / hcf;
您可能正在尋找DataGridViewColumn.FillWeight屬性。
對於所有列,將AutoSizeMode
屬性設置為fill。 一旦完成,在調整大小形式時,列的寬度也會成比例地增加和減少。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.