DataGridView.DrawingRowNumbers
This commit is contained in:
@@ -86,6 +86,7 @@
|
|||||||
<Compile Include="Controls\BinLayoutView.cs">
|
<Compile Include="Controls\BinLayoutView.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Forms\DataGridViewExtensions.cs" />
|
||||||
<Compile Include="Forms\MainForm.cs">
|
<Compile Include="Forms\MainForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace CutList.Forms
|
||||||
|
{
|
||||||
|
public static class DataGridViewExtensions
|
||||||
|
{
|
||||||
|
static readonly StringFormat CenterVerticallyFormat = new StringFormat
|
||||||
|
{
|
||||||
|
Alignment = StringAlignment.Far,
|
||||||
|
LineAlignment = StringAlignment.Center
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void DrawingRowNumbers(this DataGridView dataGridView)
|
||||||
|
{
|
||||||
|
dataGridView.RowPostPaint += (sender, e) =>
|
||||||
|
{
|
||||||
|
var rowNumber = (e.RowIndex + 1).ToString();
|
||||||
|
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, dataGridView.RowHeadersWidth - 4, e.RowBounds.Height);
|
||||||
|
|
||||||
|
e.Graphics.DrawString(
|
||||||
|
rowNumber,
|
||||||
|
dataGridView.Font,
|
||||||
|
Brushes.Blue,
|
||||||
|
headerBounds,
|
||||||
|
CenterVerticallyFormat);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,9 @@ namespace CutList.Forms
|
|||||||
items = new BindingList<Item>();
|
items = new BindingList<Item>();
|
||||||
bins = new BindingList<BinInputItem>();
|
bins = new BindingList<BinInputItem>();
|
||||||
|
|
||||||
|
dataGridView1.DrawingRowNumbers();
|
||||||
|
dataGridView2.DrawingRowNumbers();
|
||||||
|
|
||||||
itemBindingSource.DataSource = items;
|
itemBindingSource.DataSource = items;
|
||||||
itemBindingSource.ListChanged += ItemBindingSource_ListChanged;
|
itemBindingSource.ListChanged += ItemBindingSource_ListChanged;
|
||||||
|
|
||||||
|
|||||||
@@ -18,23 +18,7 @@ namespace CutList.Forms
|
|||||||
public ResultsForm()
|
public ResultsForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
dataGridView1.DrawingRowNumbers();
|
||||||
dataGridView1.RowPostPaint += DataGridView1_RowPostPaint;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
|
||||||
{
|
|
||||||
var grid = sender as DataGridView;
|
|
||||||
var rowIdx = (e.RowIndex + 1).ToString();
|
|
||||||
|
|
||||||
var centerFormat = new StringFormat()
|
|
||||||
{
|
|
||||||
Alignment = StringAlignment.Far,
|
|
||||||
LineAlignment = StringAlignment.Center
|
|
||||||
};
|
|
||||||
|
|
||||||
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth - 4, e.RowBounds.Height);
|
|
||||||
e.Graphics.DrawString(rowIdx, this.Font, Brushes.Blue, headerBounds, centerFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
|
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user