bartie
asked on
Panel: no dotted-line border in design time?
Hello,
I'm trying to write a visual component (BorderPanel) that extends the System.Windows.Forms.Panel because I want to have more options for the BorderType property.
This works fine. However during design time, the designer for the System.Windows.Forms.Panel object always draws a dotted-line border around the panel (the reason is that a normal panel doesn't have a border and can not be distinguished on the form otherwise; the dotted line shows the designer where the panel is placed). Can anyone give me some example code how I must override the designer so it does NOT draw the dotted line (because my panel does already have a border).
Thanks,
Bart.
I'm trying to write a visual component (BorderPanel) that extends the System.Windows.Forms.Panel
This works fine. However during design time, the designer for the System.Windows.Forms.Panel
Thanks,
Bart.
ASKER
No, you really are able to change design time attributes. Meanwhile I found how to do it on www.syncfusion.com. My problem was that I didn't know I had to add a reference (Project -> Add Reference...) to System.Design.Dll. The following example draws a BLUE dotted border in case the panel border is not visible. Off course the code could be changed to not drawing a border. In the OnPaintAdornments you can e.g. also write code to draw some design time things which are not visible in runtime.
Thanks anyway.
using System.Windows.Forms;
using System.Windows.Forms.Desig n;
using System.ComponentModel;
namespace TestDesigner
{
[Designer(typeof(BorderPan el.BorderP anelDesign er))]
public class BorderPanel : System.Windows.Forms.Panel
{
internal class BordererPanelDesigner:Pare ntControlD esigner
{
protected override void OnPaintAdornments
(PaintEventArgs pe)
{
System.Windows.Forms.Panel panel;
panel = (System.Windows.Forms.Pane l)this.Com ponent;
if (panel.BorderStyle == BorderStyle.None)
this.DrawDesignTimeBorder( pe.Graphic s, panel);
base.OnPaintAdornments(pe) ;
}
public void DrawDesignTimeBorder
(Graphics g, Control control)
{
System.Drawing.Rectangle clientRectangle;
System.Drawing.Color bgColor, adjustedBgColor;
System.Drawing.Pen pen;
clientRectangle = control.ClientRectangle;
bgColor = control.BackColor;
if (((double) bgColor.GetBrightness()) >= 0.5)
adjustedBgColor = ControlPaint.Dark(control. BackColor) ;
else
adjustedBgColor = ControlPaint.Light(control .BackColor );
pen = new Pen(adjustedBgColor);
pen.DashStyle = DashStyle.Dash;
pen.Color=Color.Blue;
clientRectangle.Width = (clientRectangle.Width - 1);
clientRectangle.Height = (clientRectangle.Height - 1);
g.DrawRectangle(pen,client Rectangle) ;
pen.Dispose();
}
}
//TODO: the implementation of the class BorderPanel itself.
}
Thanks anyway.
using System.Windows.Forms;
using System.Windows.Forms.Desig
using System.ComponentModel;
namespace TestDesigner
{
[Designer(typeof(BorderPan
public class BorderPanel : System.Windows.Forms.Panel
{
internal class BordererPanelDesigner:Pare
{
protected override void OnPaintAdornments
(PaintEventArgs pe)
{
System.Windows.Forms.Panel
panel = (System.Windows.Forms.Pane
if (panel.BorderStyle == BorderStyle.None)
this.DrawDesignTimeBorder(
base.OnPaintAdornments(pe)
}
public void DrawDesignTimeBorder
(Graphics g, Control control)
{
System.Drawing.Rectangle clientRectangle;
System.Drawing.Color bgColor, adjustedBgColor;
System.Drawing.Pen pen;
clientRectangle = control.ClientRectangle;
bgColor = control.BackColor;
if (((double) bgColor.GetBrightness()) >= 0.5)
adjustedBgColor = ControlPaint.Dark(control.
else
adjustedBgColor = ControlPaint.Light(control
pen = new Pen(adjustedBgColor);
pen.DashStyle = DashStyle.Dash;
pen.Color=Color.Blue;
clientRectangle.Width = (clientRectangle.Width - 1);
clientRectangle.Height = (clientRectangle.Height - 1);
g.DrawRectangle(pen,client
pen.Dispose();
}
}
//TODO: the implementation of the class BorderPanel itself.
}
hi bartie,
This is useful information. Since you solved the problem yourself, I recommend that you ask Community Support to refund your points and to save this in the PAQ. To post a question to CS, click here: https://www.experts-exchange.com/jsp/qAskQuestion.jsp?ta=commspt
-- Dan
This is useful information. Since you solved the problem yourself, I recommend that you ask Community Support to refund your points and to save this in the PAQ. To post a question to CS, click here: https://www.experts-exchange.com/jsp/qAskQuestion.jsp?ta=commspt
-- Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CJ