M
Marcel Overweel
Hi,
I'm trying to build a custom control derived from the UserControl class.
I've got the basics working and have been trying to get the name of the
control to show up on the form while in design-mode.
I expected that this.Name would give me the name as defined in the designer.
Instead, it shows the name of the class.
If I put two MapViewer instances on the form and set the name property
to 'Map1' and 'Map2', both maps show 'drawingSurface' in the left corner
of the control. (see the 'this.Name' in the source below)
Can any of you point me in the right direction?
And can you advise me on a good book dedicated to custom control
designing?
Thanks in advance!
Marcel
namespace MapViewer
{
public partial class drawingSurface : UserControl
{
public drawingSurface()
{
InitializeComponent();
}
override protected void OnPaintBackground(PaintEventArgs pevent)
{
// Do nothing!
}
private void drawingSurface_Paint(object sender, PaintEventArgs e)
{
if (this.DesignMode)
{
e.Graphics.Clear(SystemColors.Control);
e.Graphics.DrawRectangle(
Pens.Black,
this.ClientRectangle.Left, this.ClientRectangle.Top,
this.ClientRectangle.Right-1,
this.ClientRectangle.Bottom-1);
e.Graphics.DrawString(this.Name, this.Font, Brushes.Black,
new PointF(0, 0));
}
}
}
}
I'm trying to build a custom control derived from the UserControl class.
I've got the basics working and have been trying to get the name of the
control to show up on the form while in design-mode.
I expected that this.Name would give me the name as defined in the designer.
Instead, it shows the name of the class.
If I put two MapViewer instances on the form and set the name property
to 'Map1' and 'Map2', both maps show 'drawingSurface' in the left corner
of the control. (see the 'this.Name' in the source below)
Can any of you point me in the right direction?
And can you advise me on a good book dedicated to custom control
designing?
Thanks in advance!
Marcel
namespace MapViewer
{
public partial class drawingSurface : UserControl
{
public drawingSurface()
{
InitializeComponent();
}
override protected void OnPaintBackground(PaintEventArgs pevent)
{
// Do nothing!
}
private void drawingSurface_Paint(object sender, PaintEventArgs e)
{
if (this.DesignMode)
{
e.Graphics.Clear(SystemColors.Control);
e.Graphics.DrawRectangle(
Pens.Black,
this.ClientRectangle.Left, this.ClientRectangle.Top,
this.ClientRectangle.Right-1,
this.ClientRectangle.Bottom-1);
e.Graphics.DrawString(this.Name, this.Font, Brushes.Black,
new PointF(0, 0));
}
}
}
}