本文整理汇总了C#中System.Windows.Forms.DataGridView.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.CreateGraphics方法的具体用法?C# DataGridView.CreateGraphics怎么用?C# DataGridView.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.CreateGraphics方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckBoxColumnHeaderHandler
/// ------------------------------------------------------------------------------------
public CheckBoxColumnHeaderHandler(DataGridViewColumn col)
{
Debug.Assert(col != null);
Debug.Assert(col is DataGridViewCheckBoxColumn);
Debug.Assert(col.DataGridView != null);
_col = col;
_owningGrid = col.DataGridView;
_owningGrid.HandleDestroyed += HandleHandleDestroyed;
_owningGrid.CellPainting += HandleHeaderCellPainting;
_owningGrid.CellMouseMove += HandleHeaderCellMouseMove;
_owningGrid.CellMouseClick += HandleHeaderCellMouseClick;
_owningGrid.CellContentClick += HandleDataCellCellContentClick;
_owningGrid.Scroll += HandleGridScroll;
_owningGrid.RowsAdded += HandleGridRowsAdded;
_owningGrid.RowsRemoved += HandleGridRowsRemoved;
if (!BetterGrid.CanPaintVisualStyle())
_szCheckBox = new Size(13, 13);
else
{
var element = VisualStyleElement.Button.CheckBox.CheckedNormal;
var renderer = new VisualStyleRenderer(element);
using (var g = _owningGrid.CreateGraphics())
_szCheckBox = renderer.GetPartSize(g, ThemeSizeType.True);
}
}
示例2: CheckBoxColumnHeaderHandler
/// ------------------------------------------------------------------------------------
/// <summary>
/// Constructor.
/// </summary>
/// ------------------------------------------------------------------------------------
public CheckBoxColumnHeaderHandler(DataGridViewColumn col)
{
Debug.Assert(col != null);
Debug.Assert(col is DataGridViewCheckBoxColumn);
Debug.Assert(col.DataGridView != null);
m_col = col;
m_grid = col.DataGridView;
m_grid.HandleDestroyed += HandleHandleDestroyed;
m_grid.CellPainting += HandleHeaderCellPainting;
m_grid.CellMouseMove += HandleHeaderCellMouseMove;
m_grid.ColumnHeaderMouseClick += HandleHeaderCellMouseClick;
m_grid.CellContentClick += HandleDataCellCellContentClick;
m_grid.Scroll += HandleGridScroll;
m_grid.RowsAdded += HandleGridRowsAdded;
m_grid.RowsRemoved += HandleGridRowsRemoved;
if (!Application.RenderWithVisualStyles)
{
m_szCheckBox = new Size(13, 13);
}
else
{
var element = VisualStyleElement.Button.CheckBox.CheckedNormal;
var renderer = new VisualStyleRenderer(element);
using (var g = m_grid.CreateGraphics())
m_szCheckBox = renderer.GetPartSize(g, ThemeSizeType.True);
}
m_stringFormat = new StringFormat(StringFormat.GenericTypographic);
m_stringFormat.Alignment = StringAlignment.Center;
m_stringFormat.LineAlignment = StringAlignment.Center;
m_stringFormat.Trimming = StringTrimming.EllipsisCharacter;
m_stringFormat.FormatFlags |= StringFormatFlags.NoWrap;
}
示例3: getMaxWidth
public static int getMaxWidth(List<string> strings, DataGridView dataGridView)
{
Graphics g = dataGridView.CreateGraphics();
float maxWidth = 0.0f;
foreach (string s in strings)
{
float width = g.MeasureString(s, dataGridView.Font).Width;
if (width > maxWidth)
maxWidth = width;
}
g.Dispose();
return (int)Math.Ceiling(maxWidth);
}
示例4: ConvertDg2Bmp
public static void ConvertDg2Bmp(
DataGridView dg,
string sFilePath)
{
dg.Refresh();
dg.Select();
Graphics g = dg.CreateGraphics();
var ibitMap = new Bitmap
(
dg.ClientSize.Width,
dg.ClientSize.Height,
g);
Graphics iBitMapGr = Graphics.FromImage(ibitMap);
IntPtr iBitMapHdc = iBitMapGr.GetHdc();
IntPtr meHdc = g.GetHdc();
BitBlt
(
iBitMapHdc,
0,
0,
dg.ClientSize.Width,
dg.ClientSize.Height,
meHdc,
0,
0,
Src);
g.ReleaseHdc(meHdc);
iBitMapGr.ReleaseHdc(iBitMapHdc);
if (sFilePath == "")
{
return;
}
ibitMap.Save
(
sFilePath,
ImageFormat.Bmp);
}
示例5: getGridTextWidth
public static float getGridTextWidth(DataGridView dgw, string text)
{
Graphics g = dgw.CreateGraphics();
// rezultat je smanjen za 5% zato sto kada u gridu namestim velicinu kolone prema najduzem tekstu, velicina
// teksta koju daje metod MeasureString je nesto veca od velicine kolone.
float width = g.MeasureString(text, dgw.Font).Width * 0.95f;
g.Dispose();
return width;
}