Color del borde de GroupBox

04/07/2010 - 21:54 por jdepaz | Informe spam
Hola lista,

Tengo el siguiente codigo para cambiar el color del borde de un
GroupBox:


public partial class GroupBox1:Form
{
public GroupBox1()
{
}

private void GroupBox1_Load(object sender, EventArgs e)
{
myGroupBox myGroupBox = new myGroupBox();
myGroupBox.Text = "CGroupBox1";
myGroupBox.BorderColor = Color.Red;
this.Controls.Add(myGroupBox);
}
}
public class myGroupBox : GroupBox
{
private Color borderColor;
public Color BorderColor
{
get { return this.borderColor; }
set { this.borderColor = value; }
}

public myGroupBox()
{
this.borderColor = Color.Black;
}
private Color backColor = Color.Transparent;

public Color ActualBackColor
{
get { return this.backColor; }
set { this.backColor = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
Size tSize = TextRenderer.MeasureText(this.Text,
this.Font);

Rectangle borderRect = e.ClipRectangle;
borderRect.Y += tSize.Height / 2;
borderRect.Height -= tSize.Height / 2;
GraphicsPath gPath = CreatePath(0, borderRect.Y,(float)
(this.Width - 1), borderRect.Height - 1, 5, true, true, true, true);


e.Graphics.FillPath(new SolidBrush(ActualBackColor),
gPath);
e.Graphics.DrawPath(new Pen(this.borderColor), gPath);
borderRect.X += 6;
borderRect.Y -= 7;
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), borderRect);
}

public GraphicsPath CreatePath(float x, float y, float width,
float height,
float radius, bool
RoundTopLeft, bool RoundTopRight, bool RoundBottomRight, bool
RoundBottomLeft)
{
float xw = x + width;
float yh = y + height;
float xwr = xw - radius;
float yhr = yh - radius;
float xr = x + radius;
float yr = y + radius;
float r2 = radius * 2;
float xwr2 = xw - r2;
float yhr2 = yh - r2;

GraphicsPath p = new GraphicsPath();
p.StartFigure();

//Top Left Corner

if (RoundTopLeft)
{
p.AddArc(x, y, r2, r2, 180, 90);
}
else
{
p.AddLine(x, yr, x, y);
p.AddLine(x, y, xr, y);

}

//Top Edge
p.AddLine(xr, y, xwr, y);

//Top Right Corner

if (RoundTopRight)
{
p.AddArc(xwr2, y, r2, r2, 270, 90);
}
else
{
p.AddLine(xwr, y, xw, y);
p.AddLine(xw, y, xw, yr);
}


//Right Edge
p.AddLine(xw, yr, xw, yhr);

//Bottom Right Corner

if (RoundBottomRight)
{
p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
}
else
{
p.AddLine(xw, yhr, xw, yh);
p.AddLine(xw, yh, xwr, yh);
}


//Bottom Edge
p.AddLine(xwr, yh, xr, yh);

//Bottom Left Corner

if (RoundBottomLeft)
{
p.AddArc(x, yhr2, r2, r2, 90, 90);
}
else
{
p.AddLine(xr, yh, x, yh);
p.AddLine(x, yh, x, yhr);
}

//Left Edge
p.AddLine(x, yhr, x, yr);

p.CloseFigure();
return p;
}
}



Ahora bien,
resulta que en el diseñador, al arrastrar el puntero se
muestra como la figura que adjunto, y también
en tiempo de diseño, al hacer click con el botón
derecho del mouse, se repinta como la otra figura.


http://img94.imageshack.us/img94/40...t023ha.jpg
http://img33.imageshack.us/img33/40...ot024t.jpg

Preguntas similare

Leer las respuestas

#1 Leandro Tuttini
11/07/2010 - 01:19 | Informe spam
te aconsejaria que la pregunta la realice en los foros de MSDN

http://social.msdn.microsoft.com/Fo...s-ES/vcses



imagino que la idea de hacerlo la has obtenido de un ejmeplo como este
http://social.msdn.microsoft.com/Fo...c3d2ca5788

se que el ejmeplo esta en vb.net, pero podrias traducirlo ayudado por
estas tools

Convert C# to VB.NET
http://www.developerfusion.com/tool...arp-to-vb/
Code Converter
http://converter.telerik.com/

por ahi si tomas el ejemplo implementandolo en el OnPaint de resultado

saludos
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida