本文整理汇总了C#中System.Windows.Forms.DataGridView.GetCellDisplayRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.GetCellDisplayRectangle方法的具体用法?C# DataGridView.GetCellDisplayRectangle怎么用?C# DataGridView.GetCellDisplayRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.GetCellDisplayRectangle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnterDateTimeCell
// Показывает на экране элемент для ввода даты и времени
public static void EnterDateTimeCell(DataGridView dataGridView, DataGridViewCellEventArgs e, DateTimePickerFormat dateTimePickerFormat)
{
if (dataGridView.Columns[e.ColumnIndex].ValueType == typeof(DateTime))
{
CreateDateTimePicker();
currentDataGridView = dataGridView;
dtpEventDatePicker.Tag = e;
//dtpEventDatePicker.TextChanged += new EventHandler(dtpEventDatePicker_TextChanged);
if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value is DateTime)
dtpEventDatePicker.Value = (DateTime)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
else
dtpEventDatePicker.Value = DateTime.Today;
dtpEventDatePicker.Format = dateTimePickerFormat;
if (dtpEventDatePicker.Format == DateTimePickerFormat.Time)
dtpEventDatePicker.ShowUpDown = true;
else
dtpEventDatePicker.ShowUpDown = false;
dtpEventDatePicker.Parent = dataGridView;
dtpEventDatePicker.Bounds = dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
dtpEventDatePicker.Visible = !dataGridView.ReadOnly;
}
}
示例2: setVisibility
public DialogResult setVisibility(DataGridView EditedDataGridView)
{
try
{
System.Drawing.Rectangle CellRectangle1 = EditedDataGridView.GetCellDisplayRectangle(2, 2, true);
this.Location = EditedDataGridView.PointToClient(new Point(EditedDataGridView.Left + 2 * EditedDataGridView.RowHeadersWidth, EditedDataGridView.Top + 2 * EditedDataGridView.ColumnHeadersHeight));
foreach (DataGridViewColumn CurrentColumn in EditedDataGridView.Columns)
{
dgvColumns.Rows.Add(CurrentColumn.Name,
CurrentColumn.HeaderText,
CurrentColumn.DisplayIndex.ToString(),
CurrentColumn.Visible,
CurrentColumn.AutoSizeMode.ToString(),
CurrentColumn.Width.ToString(),
CurrentColumn.FillWeight.ToString(),
CurrentColumn.MinimumWidth.ToString());
}
this.ShowDialog(EditedDataGridView);
if(this.DialogResult == System.Windows.Forms.DialogResult.OK)
{
Int32 ColumnIndex=0;
foreach (DataGridViewColumn CurrentColumn in EditedDataGridView.Columns)
{
CurrentColumn.DisplayIndex = Int32.Parse(dgvColumns.Rows[ColumnIndex].Cells["colDisplayIndex"].Value.ToString());
CurrentColumn.Visible = (Boolean)dgvColumns.Rows[ColumnIndex].Cells["colVisible"].Value;
CurrentColumn.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), (String)dgvColumns.Rows[ColumnIndex].Cells["colAutoSizeMode"].Value);
if(CurrentColumn.AutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)
CurrentColumn.FillWeight = Single.Parse(dgvColumns.Rows[ColumnIndex].Cells["colFillWeight"].Value.ToString().Replace(",", "."),System.Globalization.NumberStyles.AllowDecimalPoint,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
else
CurrentColumn.Width = Int32.Parse(dgvColumns.Rows[ColumnIndex].Cells["colWidth"].Value.ToString());
CurrentColumn.MinimumWidth = Int32.Parse(dgvColumns.Rows[ColumnIndex].Cells["colMinimumWidth"].Value.ToString());
ColumnIndex++;
}
}
return DialogResult;
}
catch (Exception ex)
{
throw new Exception("Error while editing column visibility", ex);
}
}
示例3: AddFullSelect
/// <summary>
/// DataGridView添加全选
/// </summary>
/// <param name="dgv">DataGridView控件ID</param>
/// <param name="columnIndex">全选所在列序号</param>
public void AddFullSelect(DataGridView dgv, int columnIndex)
{
if (dgv.Rows.Count < 1)
{
return;
}
CheckBox ckBox = new CheckBox();
Rectangle rect = dgv.GetCellDisplayRectangle(1, -1, true);
ckBox.Size = new Size(dgv.Columns[1].Width - 12, 12); //大小
Point point = new Point(rect.X + 10, rect.Y + 3);//位置
ckBox.Location = point;
ckBox.CheckedChanged += delegate(object sender, EventArgs e)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
dgv.Rows[i].Cells[columnIndex].Value = ((CheckBox)sender).Checked;
}
dgv.EndEdit();
};
dgv.Controls.Add(ckBox);
}
示例4: drawGridOnPdfdocument
private void drawGridOnPdfdocument(DataGridView displayGrid, XGraphics gfx, int displayXOffset, int displayYOffset)
{
XColor back = XColors.Transparent;
back.A = 0.1;
XSolidBrush BorderBrush = new XSolidBrush(back);
XPen pen = new XPen(XColors.Gray, 1);
//Side Panels
double height = displayGrid.Height + 5;
double width = displayGrid.Width + 7;
gfx.DrawRoundedRectangle(pen, BorderBrush, displayGrid.Location.X - 8, displayGrid.Location.Y - 20 + displayYOffset, width, height, 10, 10);
gfx.DrawRoundedRectangle(pen, BorderBrush, displayGrid.Location.X - 5, displayGrid.Location.Y + 365, 1058, 28, 5, 5);
XFont headerfont = new XFont("Aerial", 13, XFontStyle.Bold);
XTextFormatter tf = new XTextFormatter(gfx);
XPen newPen = new XPen(Color.Black);
XColor fillColor = XColors.DarkOrange;
XBrush brush = new XSolidBrush(fillColor);
fillColor.A = 0.8;
int headerOffset = 0;
foreach (DataGridViewColumn colmn in displayGrid.Columns)
{
if (colmn.Visible)
{
Rectangle header_rect = displayGrid.GetCellDisplayRectangle(colmn.Index, -1, false);
XRect pdf_rect = new XRect(header_rect.X + displayXOffset, header_rect.Y + displayYOffset, header_rect.Width, header_rect.Height);
headerOffset = header_rect.Height;
gfx.DrawRectangle(newPen, pdf_rect);
tf.Alignment = XParagraphAlignment.Center;
tf.DrawString(colmn.HeaderText, headerfont, XBrushes.Black, pdf_rect, XStringFormats.TopLeft);
}
}
XFont font = new XFont("Aerial", 13, XFontStyle.Bold);
foreach (DataGridViewRow dgRow in displayGrid.Rows)
foreach (DataGridViewColumn dgCol in displayGrid.Columns)
{
if (dgCol.Visible)
{
Rectangle rect = displayGrid.GetCellDisplayRectangle(dgCol.Index, dgRow.Index, true);
XRect pdf_rect = new XRect(rect.X + displayXOffset, rect.Y + displayYOffset, rect.Width, rect.Height);
gfx.DrawRectangle(newPen, pdf_rect);
tf.Alignment = XParagraphAlignment.Center;
string displayText = getCellFormatedValue(displayGrid.Rows[dgRow.Index].Cells[dgCol.Index]);
tf.DrawString(displayText, headerfont, XBrushes.Black, pdf_rect, XStringFormats.TopLeft);
}
}
}
示例5: UI_MergeColumns
private void UI_MergeColumns(DataGridView grid, int col, uint num, Graphics g)
{
for(int i=0; i < num; i++)
{
if (col + i >= grid.Columns.Count) break;
DataGridViewCell hc = grid.Columns[col + i].HeaderCell;
Rectangle hcRct = grid.GetCellDisplayRectangle(hc.ColumnIndex, -1, true);
Rectangle left = new Rectangle(hcRct.Left, hcRct.Top + 2, 1, hcRct.Height - 4);
Rectangle right = new Rectangle(hcRct.Left+hcRct.Width-1, hcRct.Top + 2, 1, hcRct.Height - 4);
using (var brush = new SolidBrush(grid.Columns[col + i].HeaderCell.Style.BackColor))
{
if (i != 0)
g.FillRectangle(brush, left);
if (i != num - 1)
g.FillRectangle(brush, right);
}
}
}
示例6: dgv_CellClick1
void dgv_CellClick1(object sender, DataGridViewCellEventArgs e,string[] ColumnsName)
{
dgv = (DataGridView)sender;
if (ColumnsName.Contains(dgv.Columns[e.ColumnIndex].Name))
{
foreach (Control c in dgv.Controls)
dgv.Controls.Remove(c);
//Initialized a new DateTimePicker Control
oDateTimePicker = new DateTimePicker();
//Adding DateTimePicker control into DataGridView
dgv.Controls.Add(oDateTimePicker);
// Setting the format (i.e. 2014-10-10)
oDateTimePicker.Format = DateTimePickerFormat.Short;
// It returns the retangular area that represents the Display area for a cell
Rectangle oRectangle = dgv.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
//Setting area for DateTimePicker Control
oDateTimePicker.Size = new Size(oRectangle.Width, oRectangle.Height);
// Setting Location
oDateTimePicker.Location = new Point(oRectangle.X, oRectangle.Y);
if (dgv.CurrentCell.Value != DBNull.Value && dgv.CurrentCell.Value != null)
oDateTimePicker.Value = Convert.ToDateTime(dgv.CurrentCell.Value);
// An event attached to dateTimePicker Control which is fired when DateTimeControl is closed
oDateTimePicker.CloseUp += new EventHandler(oDateTimePicker_CloseUp);
// An event attached to dateTimePicker Control which is fired when any date is selected
oDateTimePicker.TextChanged += new EventHandler(dateTimePicker_OnTextChange);
// Now make it visible
oDateTimePicker.Visible = true;
}
else
{
HiddenDateTimePicker();
}
}
示例7: ShowCellInfoIfPossible
private void ShowCellInfoIfPossible(DataGridView view, int rowIndex, int columnIndex, int popupDuration = 0)
{
if(rowIndex >= 0 && columnIndex >= 0)
{
//RowIndex=>LogLinePairIndex, ColumnIndex-2=>DataFieldIndex (due to Line#, MsgName)
if(LogLinePairList[rowIndex].TranslatedLogLine.Count >= columnIndex
&& 0 < (columnIndex-1))
{
DataField dataField = (DataField)(LogLinePairList[rowIndex].TranslatedLogLine[columnIndex-1]);
String content = dataField.FieldName;
Rectangle viewRect = view.GetCellDisplayRectangle(columnIndex, rowIndex, true);
Point viewLocation = view.Location;
Debug.Log("ToolTip: " + content + " at viewRect=" + viewRect);
ShowInfoPopup(viewRect.Left, viewRect.Top, content, popupDuration);
}
}
}
示例8: ShowSearch
public void ShowSearch(DataGridView parentGrid, int _ColumnIndex, int _RowIndex,Popup _popup)
{
_DgView = parentGrid;
_CurrentColumnIndex = _ColumnIndex;
Rectangle Rect = _DgView.GetCellDisplayRectangle(_ColumnIndex, _RowIndex, false);
Rectangle RectToDiplay = new Rectangle(Rect.X, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
_popup.Show(_DgView, RectToDiplay);
}
示例9: ShowSearch
//public void ShowSearch(DataGridView parentGrid, int _ColumnIndex, int _RowIndex,Popup _popup)
//{
// _DgView = parentGrid;
// _CurrentColumnIndex = _ColumnIndex;
// Rectangle Rect = _DgView.GetCellDisplayRectangle(_ColumnIndex, _RowIndex,false );
// Rectangle RectToDiplay = new Rectangle(Rect.X, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
// //if (RectToDiplay.X < 0)
// // RectToDiplay.X = 0;
// //if (RectToDiplay.Y < 0)
// // RectToDiplay.Y = 0;
// _popup.Show(_DgView, RectToDiplay);
//}
public void ShowSearch(DataGridView parentGrid, int _ColumnIndex, int _RowIndex, Popup _popup,bool OpenOnRight)
{
_DgView = parentGrid;
_CurrentColumnIndex = _ColumnIndex;
Rectangle Rect = _DgView.GetCellDisplayRectangle(_ColumnIndex, _RowIndex, false);
//if (OpenOnRight)
//{
// Rectangle RectToDiplay = new Rectangle(Rect.Right - this.ClientRectangle.Width, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
// _popup.Show(_DgView, RectToDiplay);
//}
//else
//{
Rectangle RectToDiplay = new Rectangle(Rect.X, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
_popup.Show(_DgView, RectToDiplay);
//}
}