本文整理汇总了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);
}
}
}