本文整理匯總了C#中System.Windows.Forms.DataGridViewTextBoxColumn.GetPreferredWidth方法的典型用法代碼示例。如果您正苦於以下問題:C# DataGridViewTextBoxColumn.GetPreferredWidth方法的具體用法?C# DataGridViewTextBoxColumn.GetPreferredWidth怎麽用?C# DataGridViewTextBoxColumn.GetPreferredWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.DataGridViewTextBoxColumn
的用法示例。
在下文中一共展示了DataGridViewTextBoxColumn.GetPreferredWidth方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AddComparisonColumn
private void AddComparisonColumn(string name)
{
var column = new DataGridViewTextBoxColumn();
column.Name = name;
column.Width = Math.Max(100, column.GetPreferredWidth(DataGridViewAutoSizeColumnMode.ColumnHeader, true));
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
column.SortMode = DataGridViewColumnSortMode.NotSortable;
var rightClickMenu = new ContextMenuStrip();
var renameItem = new ToolStripMenuItem("Rename");
renameItem.Click += (s, e) =>
{
RenameComparison(column);
};
var removeItem = new ToolStripMenuItem("Remove");
removeItem.Click += (s, e) =>
{
RemoveComparison(column);
};
rightClickMenu.Items.Add(renameItem);
rightClickMenu.Items.Add(removeItem);
column.HeaderCell.ContextMenuStrip = rightClickMenu;
runGrid.Columns.Add(column);
RaiseRunEdited();
}
示例2: RenameComparison
private void RenameComparison(DataGridViewTextBoxColumn column)
{
var name = column.Name;
var newName = name;
var dialogResult = InputBox.Show("Rename Comparison", "Comparison Name:", ref newName);
if (dialogResult == DialogResult.OK)
{
if (!Run.Comparisons.Contains(newName))
{
if (!newName.StartsWith("[Race]"))
{
column.Name = newName;
column.Width = Math.Max(100, column.GetPreferredWidth(DataGridViewAutoSizeColumnMode.ColumnHeader, true));
if (CurrentState.CurrentComparison == name)
CurrentState.CurrentComparison = newName;
Run.CustomComparisons[Run.CustomComparisons.IndexOf(name)] = newName;
foreach (var segment in Run)
{
segment.Comparisons[newName] = segment.Comparisons[name];
segment.Comparisons.Remove(name);
}
var args = new RenameEventArgs();
args.OldName = name;
args.NewName = newName;
ComparisonRenamed(this, args);
}
else
{
var result = MessageBox.Show(this, "A Comparison name cannot start with [Race].", "Invalid Comparison Name", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result == DialogResult.Retry)
RenameComparison(column);
}
}
else if (newName != name)
{
var result = MessageBox.Show(this, "A Comparison with this name already exists.", "Comparison Already Exists", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result == DialogResult.Retry)
RenameComparison(column);
}
}
RaiseRunEdited();
}
示例3: InitializeDataGridView
private void InitializeDataGridView(DataGridView gridView)
{
gridView.Columns.Clear();
gridView.AutoGenerateColumns = false;
gridView.AllowUserToResizeColumns = true;
Font gridFont = new Font(gridView.Parent.Font.FontFamily, (float)(gridView.Parent.Font.SizeInPoints * .75D));
gridView.Font = gridFont;
for (int loop = 0; loop < (int)gridColumnSavedWidth.EndLoop; loop++)
{
DataGridViewTextBoxColumn newColumn = new DataGridViewTextBoxColumn();
switch (loop)
{
case ((int)gridColumnSavedWidth.FilePath):
newColumn.DataPropertyName = "FilePath";
newColumn.HeaderText = "Path";
break;
case ((int)gridColumnSavedWidth.Name):
newColumn.DataPropertyName = "Name";
newColumn.HeaderText = "Filename";
break;
case ((int)gridColumnSavedWidth.Length):
newColumn.DataPropertyName = "Length";
newColumn.HeaderText = "Length";
newColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
break;
case ((int)gridColumnSavedWidth.LastModified):
newColumn.DataPropertyName = "LastModified";
newColumn.HeaderText = "Last Modified";
break;
case ((int)gridColumnSavedWidth.FileHash):
newColumn.DataPropertyName = "FileHash";
newColumn.HeaderText = "Hash Value";
break;
default:
newColumn = null;
break;
}
if (newColumn != null)
{
newColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
newColumn.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
newColumn.Resizable = DataGridViewTriState.True;
newColumn.SortMode = DataGridViewColumnSortMode.Automatic;
gridView.Columns.Add(newColumn);
// Can't change the size until it's added to the grid because
// we can't compute the preferred width until it's in the grid
if ((int)Properties.Settings.Default[propertySuffix + newColumn.DataPropertyName] > 0) newColumn.Width = (int)Properties.Settings.Default[propertySuffix + newColumn.DataPropertyName];
else newColumn.Width = newColumn.GetPreferredWidth(DataGridViewAutoSizeColumnMode.ColumnHeader, true);
}
}
}