Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

GDI - Draw On TOP Of Controls

Hi .. Everything I want to do is to draw a thin Line around the border of a control (when it is activated).

I can draw something with:
                  System.Drawing.Rectangle clientRect = this.ActiveControl.ClientRectangle;
                  System.Drawing.Pen dP = new System.Drawing.Pen(Color.Red,15);
                  System.Drawing.Graphics gdiSurface = this.ActiveControl.CreateGraphics();
                  gdiSurface.DrawRectangle(dP, clientRect);

but it will always paint where I do not want it to :)

is there a possibility to paint on top of the controls .. say .. around the border of a textbox
0
somnatic
Asked:
somnatic
  • 2
  • 2
1 Solution
 
AdrianJMartinCommented:
the border is drawn on the control's surface if you want to draw arround that then you need to draw on the controls container......
0
 
somnaticAuthor Commented:
then say I want to redraw a border in another color ...
how would I do that ?
0
 
AdrianJMartinCommented:
Ahh the border is actually part of the the control....

Add a handler to the buttons paint event, something like:-

private void button2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
      Rectangle r = new Rectangle( new Point(0,0) , new Size( button2.Width -1, button2.Height -1 ) );
      Graphics g = e.Graphics;
      g.DrawRectangle( Pens.Red , r );  // Don't call Dispose on g -- you didn't create it!!!!!

}

you may need to alter the width of the pen to hide the existing border, or alter the FlatStyle property.......
0
 
somnaticAuthor Commented:
yep .. that did the trick :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now