本文整理汇总了C#中System.Windows.Forms.DataGridView.PointToClient方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.PointToClient方法的具体用法?C# DataGridView.PointToClient怎么用?C# DataGridView.PointToClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.PointToClient方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: DataGridViewSelection
public DataGridViewSelection(DataGridView grid)
{
_rows = grid.SelectedRows.OfType<DataGridViewRow>();
if (!_rows.Any())
{
_rows = grid.SelectedCells.OfType<DataGridViewCell>().Select(c => c.OwningRow).Distinct();
var cols = grid.SelectedCells.OfType<DataGridViewCell>().Select(c => c.OwningColumn).Distinct().ToArray();
if (cols.Length == 1)
_columnPropertyName = cols[0].DataPropertyName;
}
if (!_rows.Any() && grid.CurrentCell != null)
{
_rows = Enumerable.Repeat(grid.CurrentCell.OwningRow, 1);
_columnPropertyName = grid.CurrentCell.OwningColumn.DataPropertyName;
}
else
{
_rows = Enumerable.Empty<DataGridViewRow>();
_columnPropertyName = null;
}
var client = grid.PointToClient(Cursor.Position);
var hit = grid.HitTest(client.X, client.Y);
if (!_rows.Any(r => r.Index == hit.RowIndex))
{
if (hit.RowIndex >= 0)
{
_rows = Enumerable.Repeat(grid.Rows[hit.RowIndex], 1);
_columnPropertyName = grid.Columns[hit.ColumnIndex].DataPropertyName;
}
else
{
_rows = Enumerable.Empty<DataGridViewRow>();
_columnPropertyName = null;
}
}
}
示例3: DecideDropDestinationRowIndex
/// <summary>
/// ドロップ先の行の決定
/// </summary>
/// <param name="grid"></param>
/// <param name="e"></param>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="next"></param>
/// <returns></returns>
private bool DecideDropDestinationRowIndex(
DataGridView grid, DragEventArgs e,
out int from, out int to, out bool next)
{
from = (int)e.Data.GetData(typeof(int));
// 元の行が追加用の行であれば、常に false
if (grid.NewRowIndex != -1 && grid.NewRowIndex == from)
{
to = 0; next = false;
return false;
}
Point clientPoint = grid.PointToClient(new Point(e.X, e.Y));
// 上下のみに着目するため、横方向は無視する
clientPoint.X = 1;
DataGridView.HitTestInfo hit =
grid.HitTest(clientPoint.X, clientPoint.Y);
to = hit.RowIndex;
if (to == -1)
{
int top = grid.ColumnHeadersVisible ? grid.ColumnHeadersHeight : 0;
top += 1; // ...
if (top > clientPoint.Y)
// ヘッダへのドロップ時は表示中の先頭行とする
to = grid.FirstDisplayedCell.RowIndex;
else
// 最終行へ
to = grid.Rows.Count - 1;
}
// 追加用の行は無視
if (to == grid.NewRowIndex) to--;
next = (to > from);
return (from != to);
}