How does one properly read values of custom control properties set via design time?
Currently, rows and columns are set in the properties list of the control (vs.net as ide), however both properties return 0 when read from the constructor of the control. I suspect the constructor is executing before the properties are assigned during start of application.
What is the correct way of doing this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace HexagonalLevelEditor.HexLogic{
class HexGrid : System.Windows.Forms.Panel {
public HexGrid() {
for(int c = 0; c < this.Columns; ++c) {
for(int r = 0; r < this.Rows; ++r) {
HexCell h = new HexCell();
h.Width = 200;
h.Height = 200;
h.Location = new System.Drawing.Point(c*200, r*200);
this.Controls.Add(h);
}
}
}
private void InitializeComponent() {
this.SuspendLayout();
this.ResumeLayout(false);
}
private int m_rows;
[Browsable(true), DescriptionAttribute("Hexagonal grid row count."), Bindable(true)]
public int Rows {
get {
return m_rows;
}
set {
m_rows = value;
}
}
private int m_columns;
[Browsable(true), DescriptionAttribute("Hexagonal grid column count."), Bindable(true)]
public int Columns {
get{
return m_columns;
}
set {
m_columns = value;
}
}
}
}