Solved

GDI - Draw On TOP Of Controls

Posted on 2004-08-20
4
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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