Solved

GDI - Draw On TOP Of Controls

Posted on 2004-08-20
4
431 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

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

24 Experts available now in Live!

Get 1:1 Help Now