Solved

GDI - Draw On TOP Of Controls

Posted on 2004-08-20
4
427 Views
Last Modified: 2008-02-01
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
Comment
Question by:somnatic
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:AdrianJMartin
ID: 11850728
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
 
LVL 4

Author Comment

by:somnatic
ID: 11850840
then say I want to redraw a border in another color ...
how would I do that ?
0
 
LVL 5

Accepted Solution

by:
AdrianJMartin earned 500 total points
ID: 11850961
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
 
LVL 4

Author Comment

by:somnatic
ID: 11850996
yep .. that did the trick :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

21 Experts available now in Live!

Get 1:1 Help Now