diff --git a/LibationWinForms/DataGridViewImageButtonCell.cs b/LibationWinForms/DataGridViewImageButtonCell.cs new file mode 100644 index 00000000..f4f25afd --- /dev/null +++ b/LibationWinForms/DataGridViewImageButtonCell.cs @@ -0,0 +1,18 @@ +using System.Drawing; +using System.Windows.Forms; + +namespace LibationWinForms +{ + public class DataGridViewImageButtonCell : DataGridViewButtonCell + { + protected void DrawButtonImage(Graphics graphics, Image image, Rectangle cellBounds) + { + var w = image.Width; + var h = image.Height; + var x = cellBounds.Left + (cellBounds.Width - w) / 2; + var y = cellBounds.Top + (cellBounds.Height - h) / 2; + + graphics.DrawImage(image, new Rectangle(x, y, w, h)); + } + } +} diff --git a/LibationWinForms/DataGridViewImageButtonColumn.cs b/LibationWinForms/DataGridViewImageButtonColumn.cs deleted file mode 100644 index e607a069..00000000 --- a/LibationWinForms/DataGridViewImageButtonColumn.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Drawing; -using System.Windows.Forms; - -namespace LibationWinForms -{ - public abstract class DataGridViewImageButtonColumn : DataGridViewButtonColumn - { - private DataGridViewImageButtonCell _cellTemplate; - public override DataGridViewCell CellTemplate - { - get => GetCellTemplate(); - set - { - if (value is DataGridViewImageButtonCell cellTemplate) - _cellTemplate = cellTemplate; - } - } - - protected abstract DataGridViewImageButtonCell NewCell(); - - private DataGridViewImageButtonCell GetCellTemplate() - { - if (_cellTemplate is null) - return NewCell(); - else - return _cellTemplate; - } - - public override object Clone() - { - var clone = (DataGridViewImageButtonColumn)base.Clone(); - clone._cellTemplate = _cellTemplate; - - return clone; - } - } - - public class DataGridViewImageButtonCell : DataGridViewButtonCell - { - protected void DrawButtonImage(Graphics graphics, Image image, Rectangle cellBounds) - { - var w = image.Width; - var h = image.Height; - var x = cellBounds.Left + (cellBounds.Width - w) / 2; - var y = cellBounds.Top + (cellBounds.Height - h) / 2; - - graphics.DrawImage(image, new Rectangle(x, y, w, h)); - } - } -} diff --git a/LibationWinForms/EditTagsDataGridViewImageButtonColumn.cs b/LibationWinForms/EditTagsDataGridViewImageButtonColumn.cs index e736b938..d76cc04a 100644 --- a/LibationWinForms/EditTagsDataGridViewImageButtonColumn.cs +++ b/LibationWinForms/EditTagsDataGridViewImageButtonColumn.cs @@ -3,10 +3,12 @@ using System.Windows.Forms; namespace LibationWinForms { - public class EditTagsDataGridViewImageButtonColumn : DataGridViewImageButtonColumn + public class EditTagsDataGridViewImageButtonColumn : DataGridViewButtonColumn { - protected override DataGridViewImageButtonCell NewCell() - => new EditTagsDataGridViewImageButtonCell(); + public EditTagsDataGridViewImageButtonColumn() + { + CellTemplate = new EditTagsDataGridViewImageButtonCell(); + } } internal class EditTagsDataGridViewImageButtonCell : DataGridViewImageButtonCell diff --git a/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs b/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs index 4802fa96..6427677c 100644 --- a/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs +++ b/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs @@ -6,10 +6,12 @@ using System.Linq; namespace LibationWinForms { - public class LiberateDataGridViewImageButtonColumn : DataGridViewImageButtonColumn + public class LiberateDataGridViewImageButtonColumn : DataGridViewButtonColumn { - protected override DataGridViewImageButtonCell NewCell() - => new LiberateDataGridViewImageButtonCell(); + public LiberateDataGridViewImageButtonColumn() + { + CellTemplate = new LiberateDataGridViewImageButtonCell(); + } } internal class LiberateDataGridViewImageButtonCell : DataGridViewImageButtonCell