Solved

Panel: no dotted-line border in design time?

Posted on 2002-06-27
4
1,200 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:bartie
4 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7113134
This is default for any component you create. AFAIk you cannot change that.

CJ
0
 

Author Comment

by:bartie
ID: 7113602
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.Design;
using System.ComponentModel;

namespace TestDesigner
{
[Designer(typeof(BorderPanel.BorderPanelDesigner))]
public class BorderPanel : System.Windows.Forms.Panel
{
 internal class BordererPanelDesigner:ParentControlDesigner
 {
 protected override void OnPaintAdornments
                                      (PaintEventArgs pe)
 {
 System.Windows.Forms.Panel panel;
 panel = (System.Windows.Forms.Panel)this.Component;
 if (panel.BorderStyle == BorderStyle.None)
   this.DrawDesignTimeBorder(pe.Graphics, 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,clientRectangle);
 pen.Dispose();
 }
}

//TODO: the implementation of the class BorderPanel itself.

}        
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7152100
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: http://www.experts-exchange.com/jsp/qAskQuestion.jsp?ta=commspt
-- Dan
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 100 total points
ID: 7154139
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different Delete Messages 7 37
In C#, how would you convert a byte array to its integer value equivalent? 12 38
Error on link 14 38
Help with C#, MVC, razor. 6 23
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now