473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

panel control

How can I change the border color of a panel in C#.net I had changed the borderstyle to FixedSingle but no option for changing the border color
Sep 29 '11 #1
1 3925
arie
64
There is actually no property that can set border color in c#. The best you can do is to make your own CustomPanel class that inherits from Panel, and then override its OnPaint method, and simply draw a rectangle there.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Drawing;
  6.  
  7. namespace WindowsFormsApplication1
  8. {
  9.     class CustomPanel : Panel
  10.     {
  11.         private Color _borderColor = Color.Transparent;
  12.         public Color BorderColor
  13.         {
  14.             get { return _borderColor; }
  15.             set { _borderColor = value; }
  16.         }
  17.  
  18.         // default constructor; panel without a border
  19.         public CustomPanel()
  20.             : base()
  21.         {
  22.             this.SetStyle(ControlStyles.UserPaint, true);
  23.  
  24.         }
  25.  
  26.         // panel with a border
  27.         public CustomPanel(Color borderColor)
  28.             : base()
  29.         {
  30.             _borderColor = borderColor;
  31.             this.SetStyle(ControlStyles.UserPaint, true);
  32.         }
  33.  
  34.         protected override void OnPaint(PaintEventArgs e)
  35.         {
  36.             base.OnPaint(e);
  37.             e.Graphics.DrawRectangle(
  38.                 new Pen(
  39.                     new SolidBrush(_borderColor), 2),
  40.                     e.ClipRectangle);
  41.         }
  42.     }
  43. }
  44.  
and the BorderStyle should be None here or it'll look strange.
Sep 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Niraj via DotNetMonster.com | last post by:
i had put a panel in form and text box,label and numericupdown control in it. Now i had use to send the form as me to some function byref then again from that particular function i use to send the...
1
by: Tia Carr | last post by:
When I try to place a child control on top of a panel control, the mouse pointer remains as a pointer instead of changing to a cross. I tried both the ShowGrid on/off, doesn't make a difference.....
5
by: Robert Phillips | last post by:
I have a Panel control containing a few TextBox controls. The Panel is originally enabled, I enter data into the TextBox controls. When I submit, the Panel is disabled during the PostBack and the...
2
by: Joe Au | last post by:
I first add a grid layout panel control to a web form, then put a data grid inside the panel. When I run the web form, the data grid is filled up but it throws outside the panel control. The panel...
2
by: Raghu Raman | last post by:
Hi, am a biginner in .net designing.Does the panel control is enough to act as a container .Because if , i design my controls in textboxes rows& cols , i heared that the aclignment won't change...
4
by: Guadala Harry | last post by:
AFAIK, the Panel control renders as a <SPAN> in the rendered HTML. Is there an alternative to Panel that renders NOTHING? Here is what I'm doing: I need to place a bunch of HTML in an ASCX -...
11
by: BoloBaby | last post by:
OK, check this out... I have a form with a panel control and button on it (outside the panel control). I have two event handlers - one handles the click event of the button on the form. The...
1
by: clintonG | last post by:
I'm having a problem maintaining state with a Panel control in a MasterPage and I need help thinking through this process. The basic structure of the HTML in the Master looks like this... ...
1
by: Steven Garrad | last post by:
Hi All, I have a pictureBox control inside of a panel control. The pictureBox is larger than the panel control and I have the panel control set true for AutoScroll so the panel displays scrolling...
0
by: canteloup | last post by:
Hi, I need to find a way to determinate where a control is on a windows form or panel control. I have a panel contro setted with autoscroll = true and when I move a control contained by it, I need to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.