# HG changeset patch # User IBBoard # Date 1275076174 0 # Node ID 67b4b84f5674c9d4b9bdf2218714e4ac5822fd66 # Parent 24d0cfaa95da8888f3b4c6f022c49334101b051b Fixes #269: Handle multiple stat lines * Reduce the width of the tables to only show a vertical scrollbar * Make the width of the columns more proportional to how many there are diff -r 24d0cfaa95da -r 67b4b84f5674 FrmUnit.cs --- a/FrmUnit.cs Thu May 27 20:01:07 2010 +0000 +++ b/FrmUnit.cs Fri May 28 19:49:34 2010 +0000 @@ -27,8 +27,8 @@ public class FrmUnit : IBBoard.Windows.Forms.IBBForm { private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit)); - private static readonly int COLUMN_WIDTH = 40; private static readonly int BORDER_WIDTH = 1; + private static readonly int NAME_COL_WIDTH_MULTIPLIER = 3; private Unit unit; private Dictionary equipmentChoices = new Dictionary(); private Dictionary DataGridViews = new Dictionary(); @@ -145,30 +145,29 @@ log.DebugFormat("Create DataGridView for stats ID {0}", statsID); SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); StatSlot[] sysStatSlots = sysStats.StatSlots; - StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1]; + int statsCount = sysStatSlots.Length; + int statsWithNameCount = statsCount + 1; + StatSlot[] statsWithName = new StatSlot[statsWithNameCount]; statsWithName[0] = new StatSlot("Name"); sysStatSlots.CopyTo(statsWithName, 1); DataTable dt = new DataTable(); - int statsCount = statsWithName.Length; DataGridView statsGrid = CreateDataGridView(); statsGrid.DataSource = dt; + int columnWidth = statsGrid.Width / (statsCount + NAME_COL_WIDTH_MULTIPLIER); - for (int i = 0; i < statsCount; i++) + for (int i = 0; i < statsWithNameCount; i++) { StatSlot stat = statsWithName[i]; string slotName = stat.Name; dt.Columns.Add(CreateDataColumn(slotName)); - statsGrid.Columns[i].Width = COLUMN_WIDTH; + DataGridViewColumn col = statsGrid.Columns[i]; + col.Width = columnWidth; + col.CellTemplate = new StatsDataGridViewCell(); } DataGridViewColumn nameColumn = statsGrid.Columns[0]; nameColumn.Name = Translation.GetTranslation("UnitName", "Name"); - nameColumn.Width = statsGrid.ClientSize.Width - (sysStatSlots.Length * (COLUMN_WIDTH + BORDER_WIDTH)); - - for (int i = 0; i < statsCount; i++) - { - statsGrid.Columns[i].CellTemplate = new StatsDataGridViewCell(); - } + nameColumn.Width = statsGrid.Width - (statsCount * columnWidth); return statsGrid; } @@ -198,7 +197,7 @@ statsGrid.BackgroundColor = SystemColors.Control; statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded); statsPanel.Controls.Add(statsGrid); - statsGrid.Width = statsPanel.Width; + statsGrid.Width = statsPanel.Width - (int)Math.Round(SystemInformation.VerticalScrollBarWidth * 1.4); return statsGrid; }