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


C# DataGrid.CreateGraphics方法代码示例

本文整理汇总了C#中System.Windows.Forms.DataGrid.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.CreateGraphics方法的具体用法?C# DataGrid.CreateGraphics怎么用?C# DataGrid.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DataGrid的用法示例。


在下文中一共展示了DataGrid.CreateGraphics方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DataGridComboBoxColumn

 /// <summary>
 /// The only creator ;)
 /// </summary>
 /// <param name="colName">The name of the column</param>
 /// <param name="dataSource">The datasource that contains the lookup table</param>
 /// <param name="displayMember">The member of the lookuptable to display</param>
 /// <param name="valueMember">The member of the lookuptable with the value</param>
 /// <param name="dataGrid">The datagrid parent of this column</param>
 public DataGridComboBoxColumn(string colName, DataTable dataSource, string displayMember, string valueMember, DataGrid dataGrid)
 {
     _comboBox = new ComboBox();
     _comboBox.Visible = false;
     _comboBox.DataSource = dataSource;
     _dataTable = dataSource;
     _comboBox.DisplayMember = displayMember;
     _displayMember = displayMember;
     _valueMember = valueMember;
     _comboBox.ValueMember = valueMember;
     _comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
     Graphics _graphicsContext = dataGrid.CreateGraphics();
     float _widest = 0;
     SizeF _stringSize = new SizeF(0, 0);
     foreach (DataRow dr in dataSource.Rows)
     {
         _stringSize = _graphicsContext.MeasureString(dr[displayMember].ToString(), dataGrid.Font);
         if (_stringSize.Width > _widest)
         {
             _widest = _stringSize.Width;
         }
     }
     _comboBox.DropDownWidth = (int)Math.Ceiling(_widest);
     this.Width = _comboBox.DropDownWidth + 25; // Add the space for the dropdown arrow
     this.MappingName = colName;
     this.HeaderText = colName;
     dataGrid.Controls.Add(_comboBox);
 }
开发者ID:hayrettinbebek,项目名称:e-cafe,代码行数:36,代码来源:CellStyles.cs

示例2: SizeColumnsToContent

        public void SizeColumnsToContent(DataGrid dataGrid)
        {
            Graphics Graphics = dataGrid.CreateGraphics();

            DataGridTableStyle tableStyle = new DataGridTableStyle();

                DataTable dataTable = (DataTable)dataGrid.DataSource;

                dataGrid.TableStyles.Clear();
                tableStyle.MappingName = dataTable.TableName;
                DataGridTextBoxColumn columnStyle;

                    DataColumn dataColumn = dataTable.Columns[0];
                    columnStyle = new DataGridTextBoxColumn();
                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;
                    columnStyle.Width = 30;
                    tableStyle.GridColumnStyles.Add(columnStyle);

                    dataColumn = dataTable.Columns[1];
                    columnStyle = new DataGridTextBoxColumn();
                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;
                    columnStyle.Width = 60;
                    tableStyle.GridColumnStyles.Add(columnStyle);

                    dataColumn = dataTable.Columns[2];
                    columnStyle = new DataGridTextBoxColumn();
                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;
                    columnStyle.Width = 60;
                    tableStyle.GridColumnStyles.Add(columnStyle);

                    dataColumn = dataTable.Columns[3];
                    columnStyle = new DataGridTextBoxColumn();
                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;
                    columnStyle.Width = 60;
                    tableStyle.GridColumnStyles.Add(columnStyle);

                    dataColumn = dataTable.Columns[4];
                    columnStyle = new DataGridTextBoxColumn();
                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;
                    columnStyle.Width = 60;
                    tableStyle.GridColumnStyles.Add(columnStyle);

                    dataColumn = dataTable.Columns[5];
                    columnStyle = new DataGridTextBoxColumn();
                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;
                    columnStyle.Width = 40;
                    tableStyle.GridColumnStyles.Add(columnStyle);

                dataGrid.TableStyles.Add(tableStyle);

                Graphics.Dispose();
        }
开发者ID:tatar1nro,项目名称:KKM_Trash,代码行数:58,代码来源:astuMain.cs

示例3: GetColumnWidth

        public static int GetColumnWidth(DataGrid grid, PropertyInfo proInfo, IList listSource, string headerText)
        {
            int maxWidth = 0;
            int headWidth = (int)grid.CreateGraphics().MeasureString(headerText, grid.HeaderFont).Width;
            if (headWidth > maxWidth)
                maxWidth = headWidth;
            foreach (object obj in listSource)
            {
                int width = 40;
                object v = proInfo.GetValue(obj, null);
                if (v != null)
                {
                    SizeF size = grid.CreateGraphics().MeasureString(v.ToString(), grid.Font);
                    width = (int)size.Width;
                }
                if (width > maxWidth)
                    maxWidth = width;

            }
            return maxWidth + 40;
        }
开发者ID:hkiaipc,项目名称:jsb,代码行数:21,代码来源:DataGridStyleHelper.cs

示例4: getLongestField

        private static int getLongestField(DataGrid grid, int iCol)
        {
            int num2 = 60;
            int count = ((ArrayList)grid.DataSource).Count;

            Graphics graphics = grid.CreateGraphics();
            int num5 = Convert.ToInt32(Math.Ceiling((double)graphics.MeasureString(" ", grid.Font).Width));
            int num = 0;
            if (0 < count)
            {
                do
                {
                    string text = grid[num, iCol].ToString();
                    int num3 = Convert.ToInt32(Math.Ceiling((double)graphics.MeasureString(text, grid.Font).Width));
                    if (num3 > num2)
                    {
                        num2 = num3;
                    }
                    num++;
                }
                while (num < count);
            }
            return (num5 + num2);
        }
开发者ID:testdoron,项目名称:ProScan,代码行数:24,代码来源:SensorMonitorForm.cs

示例5: CreateColumnStyles

        private void CreateColumnStyles(DataGrid TheGrid,DataTable TableGrid)
        {
            // Define new table style.
            DataGridTableStyle tableStyle = new DataGridTableStyle();

            Graphics g = TheGrid.CreateGraphics();

            try
            {

                // Clear any existing table styles.
                TheGrid.TableStyles.Clear();

                // Use mapping name that is defined in the data source.
                tableStyle.MappingName = TableGrid.TableName;

                // Now create the column styles within the table style.
                DataGridTextBoxColumn columnStyle;

                for (int iCurrCol = 0; iCurrCol < TableGrid.Columns.Count;
                    iCurrCol++)
                {
                    DataColumn dataColumn = TableGrid.Columns[iCurrCol];

                    columnStyle = new DataGridTextBoxColumn();

                    columnStyle.HeaderText = dataColumn.ColumnName;
                    columnStyle.MappingName = dataColumn.ColumnName;

                    columnStyle.TextBox.Width = TheGrid.GetCellBounds(0,iCurrCol).Width;

                    columnStyle.TextBox.Height = (int)g.MeasureString(columnStyle.HeaderText,TheGrid.HeaderFont).Height + 10;

                    // Add the new column style to the table style.
                    tableStyle.GridColumnStyles.Add(columnStyle);
                }

                // Add the new table style to the data grid.

                TheGrid.TableStyles.Add(tableStyle);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                g.Dispose();
            }
        }
开发者ID:USAID-DELIVER-PROJECT,项目名称:ethiopia-hcmis-facility,代码行数:50,代码来源:Grid.cs


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