Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
changeset 64:e04bea5b7b3d WarFoundry_v0.1beta3_Winforms
Fixes #157: Stats show object class name when selected
* Do the column style properly and re-implement the parent's abstract methods from scratch rather than from the "textbox" version (as per MSDN page: http://msdn.microsoft.com/en-us/library/ms996453.aspx#datagridcolumnstyle2_topic5)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 22 Sep 2009 19:24:00 +0000 |
parents | 4db2c1086a85 |
children | c4181adba7df |
files | UI/StatColumnStyle.cs |
diffstat | 1 files changed, 58 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/UI/StatColumnStyle.cs Mon Sep 21 19:31:24 2009 +0000 +++ b/UI/StatColumnStyle.cs Tue Sep 22 19:24:00 2009 +0000 @@ -10,27 +10,80 @@ namespace IBBoard.WarFoundry.GUI.WinForms.UI { - class StatColumnStyle : DataGridTextBoxColumn + class StatColumnStyle : DataGridColumnStyle { protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight) { Object obj = GetColumnValueAtRow(source, rowNum); Rectangle rect = bounds; g.FillRectangle(backBrush, rect); - rect.Offset(0, 2); - rect.Height -= 2; if (obj is Stat) { Stat stat = (Stat) obj; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = (stat.ParentSlotName == "Name" ? StringAlignment.Near : StringAlignment.Center); - g.DrawString(stat.SlotValueString, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect, stringFormat); + g.DrawString(stat.SlotValueString, GetFont(), foreBrush, rect, stringFormat); } else { - g.DrawString(NullText, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect); + g.DrawString(NullText, GetFont(), foreBrush, rect); } } + + private Font GetFont() + { + return DataGridTableStyle.DataGrid.Font; + } + + protected override void Abort(int rowNum) + { + // Do nothing - we don't allow editing + } + + protected override bool Commit(CurrencyManager dataSource, int rowNum) + { + // Do nothing - we don't allow editing - but pretend we did + return true; + } + + protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible) + { + // Do nothing - we don't allow editing + } + + protected override int GetMinimumHeight() + { + return GetFont().Height; + } + + protected override int GetPreferredHeight(Graphics g, object value) + { + return GetFont().Height; + } + + protected override Size GetPreferredSize(Graphics g, object value) + { + Size size = new Size(); + + if (value is Stat) + { + SizeF stringSize = g.MeasureString(((Stat) value).SlotValueString, GetFont()); + size.Height = (int) Math.Ceiling(stringSize.Height); + size.Width = (int) Math.Ceiling(stringSize.Width); + } + + return size; + } + + protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) + { + Paint(g, bounds, source, rowNum, false); + } + + protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) + { + Paint(g, bounds, source, rowNum, SystemBrushes.Window, SystemBrushes.WindowText, alignToRight); + } } }