当前位置: 首页>>代码示例>>C#>>正文


C# DataGridViewTextBoxColumn.GetPreferredWidth方法代码示例

本文整理汇总了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();
 }
开发者ID:Glurmo,项目名称:LiveSplit,代码行数:25,代码来源:RunEditorDialog.cs

示例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();
 }
开发者ID:Glurmo,项目名称:LiveSplit,代码行数:42,代码来源:RunEditorDialog.cs

示例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);
         }
     }
 }
开发者ID:stchan,项目名称:CloneFinder,代码行数:51,代码来源:MainWindow.cs


注:本文中的System.Windows.Forms.DataGridViewTextBoxColumn.GetPreferredWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。