public class CtlStandardPlace : System.Windows.Forms.UserControl
{
private SimuObject m_place;
public SimuObject Place
{
get
{
return m_place;
}
set
{
m_place = value;
}
}
public CtlStandardPlace()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
/* m_place = new SimuStandardPlace();
m_place.X = 1;
m_place.Y = 1;
m_place.Dx = 10;
m_place.Dy = 10;
*/
}
public CtlStandardPlace(SimuObject place)
{
m_place = (SimuStandardPlace)place;
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not
///
private void InitializeComponent() {
this.Name = "CtlStandardPlace";
this.Size = new System.Drawing.Size(10, 10);
}
#endregion
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaintBackground(e);
BrushFactory bf = new BrushFactory();
SolidBrush brush;
if(m_place != null)
{
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);
Rectangle rect = new Rectangle(m_place.X,m_place.Y,m_place.Dx,m_place.Dy);
System.Diagnostics.Debug.WriteLine(rect.ToString());
e.Graphics.DrawRectangle(pen, rect);
brush = bf.CreateBrush(m_place) as SolidBrush;
System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString() + brush.ToString() + brush.Color.ToString());
if(brush == null)
return;
e.Graphics.FillRectangle(brush, rect.Left+1,rect.Top+1,rect.Right-1,rect.Bottom-1);
e.Graphics.DrawString(this.ToString(), this.Font,
brush, rect.Width + 3,
(rect.Height - this.Font.Height) / 2);
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
BrushFactory bf = new BrushFactory();
SolidBrush brush;
if(m_place != null)
{
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);
Rectangle rect = new Rectangle(m_place.X,m_place.Y,m_place.Dx,m_place.Dy);
System.Diagnostics.Debug.WriteLine(rect.ToString());
e.Graphics.DrawRectangle(pen, rect);
brush = bf.CreateBrush(m_place) as SolidBrush;
System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString() + brush.ToString() + brush.Color.ToString());
if(brush == null)
return;
e.Graphics.FillRectangle(brush, rect.Left+1,rect.Top+1,rect.Right-1,rect.Bottom-1);
}
}
}
and a simple testing programm:
Code:
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
SimuEntryPlace dummy1 = new SimuEntryPlace();
dummy1.X = 1;
dummy1.Y = 1;
dummy1.Dx = 10;
dummy1.Dy = 10;
SimuBuilderControls.CtlStandardPlace place;
place = new SimuBuilderControls.CtlStandardPlace();
place.Place = dummy1;
this.Controls.Add(place);
SimuStandardPlace dummy2 = new SimuStandardPlace();
dummy2.X = 11;
dummy2.Y = 1;
dummy2.Dx = 10;
dummy2.Dy = 10;
place = new SimuBuilderControls.CtlStandardPlace();
place.Place = dummy2;
this.Controls.Add(place);
this.Invalidate();
}
If i run that programm the first dummy-place is shown but the second is missing. It seems that I made something wrong, but I have no idea what it could be.
Sorry for late reply, but I was on a buisness trip.
In the attachment there is my project. It is a #develop-project but it should also be easy to create a VS.NET-project from the files. Perhaps some sees what I was oversee.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.