本文整理汇总了C#中System.Windows.Forms.DataGrid.GetCellBounds方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.GetCellBounds方法的具体用法?C# DataGrid.GetCellBounds怎么用?C# DataGrid.GetCellBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGrid
的用法示例。
在下文中一共展示了DataGrid.GetCellBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Grid
public Grid(DataGrid TheGrid)
{
try
{
//get the Data in the grid
DataTable TableGrid = null;
if (TheGrid.DataSource.GetType()==typeof(DataView))
{
DataView ViewGrid = (DataView)TheGrid.DataSource;
TableGrid = ViewGrid.Table;
}
else
{
TableGrid = (DataTable)TheGrid.DataSource;
}
//set number of rows
rows = TableGrid.DefaultView.Count;
//set number of columns
//first check if the grid has tablestyle and columnstyle
//check for table styles
if (TheGrid.TableStyles.Count==0)
{
//create table style and column style
CreateColumnStyles(TheGrid,TableGrid);
}
else
{
//create column styles if there are none
if (TheGrid.TableStyles[TableGrid.TableName].GridColumnStyles.Count==0)
CreateColumnStyles(TheGrid,TableGrid);
}
//set number of columns
columns = TheGrid.TableStyles[TableGrid.TableName].GridColumnStyles.Count;
Cells = new Cell[Rows,Columns];
//Copy Cells
for (int i=0;i<Rows;i++)
{
for (int j=0;j<Columns;j++)
{
Cells[i,j] = new Cell(i,j,TheGrid.Font,TheGrid.TableStyles[TableGrid.TableName].GridColumnStyles[j].Alignment,TheGrid.GetCellBounds(i,j),TheGrid[i,j].ToString());
}
Height +=Cells[i,0].Height;
}
//init number of columns to headers
Headers = new Header[Columns];
SetHeaders(TheGrid,TableGrid);
//define grid colors
SetColors(TheGrid);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例2: 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();
}
}