Solved

GDI - Draw On TOP Of Controls

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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