Click here to Skip to main content
15,919,613 members
Home / Discussions / C#
   

C#

 
GeneralRe: Resources Pin
James T. Johnson16-Aug-02 1:53
James T. Johnson16-Aug-02 1:53 
GeneralRe: Resources Pin
Nnamdi Onyeyiri16-Aug-02 2:52
Nnamdi Onyeyiri16-Aug-02 2:52 
GeneralRe: Resources Pin
leppie16-Aug-02 1:55
leppie16-Aug-02 1:55 
GeneralRe: Resources Pin
James T. Johnson16-Aug-02 2:14
James T. Johnson16-Aug-02 2:14 
GeneralRe: Resources Pin
leppie16-Aug-02 2:33
leppie16-Aug-02 2:33 
GeneralPainting Order Pin
albean15-Aug-02 20:41
albean15-Aug-02 20:41 
GeneralRe: Painting Order Pin
leppie16-Aug-02 3:09
leppie16-Aug-02 3:09 
GeneralRe: Painting Order Pin
albean16-Aug-02 5:12
albean16-Aug-02 5:12 
Hi leppie,

Actually passing IntPtr.Zero (i.e. null) to GetDC will return a handle to the screen. This is a fine solution (as suggested in a thread below by Li-kai Liu and AK) and this is what I am doing.

However, when I do this in the Form Paint event the Screen is painted fine, then the controls get painted and it erases what is drawn. So I’m left with my original Question:
Is there someplace that I can do my painting AFTER the controls have been painted?

Try this code out to see for yourself. Start a new project, place a button on the form. Then add the Form1_Paint event and place this code in that event:

Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
IntPtr hdc = GetDC(IntPtr.Zero); // get hdc for the screen
Graphics g = Graphics.FromHdc(hdc);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y - 7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
//This should COVER the button but the control is redrawn over it
g.FillRegion(hatchBrush, region);

/////////////////////////////////////
//Place this code outside the paint event:
/////////////////////////////////////
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
GeneralRe: Painting Order Pin
Nick Parker16-Aug-02 6:27
protectorNick Parker16-Aug-02 6:27 
GeneralRe: Painting Order Pin
albean16-Aug-02 6:40
albean16-Aug-02 6:40 
GeneralRe: Painting Order Pin
Nick Parker16-Aug-02 6:47
protectorNick Parker16-Aug-02 6:47 
GeneralRe: Painting Order Pin
albean16-Aug-02 7:16
albean16-Aug-02 7:16 
GeneralRe: Painting Order Pin
Russell Morris16-Aug-02 7:52
Russell Morris16-Aug-02 7:52 
GeneralDistributed App Pin
Eka15-Aug-02 19:42
Eka15-Aug-02 19:42 
GeneralRe: Distributed App Pin
Nnamdi Onyeyiri16-Aug-02 0:51
Nnamdi Onyeyiri16-Aug-02 0:51 
GeneralRe: Distributed App Pin
James T. Johnson16-Aug-02 1:42
James T. Johnson16-Aug-02 1:42 
QuestionOnPaint() What am I missing? Pin
albean15-Aug-02 17:49
albean15-Aug-02 17:49 
AnswerRe: OnPaint() What am I missing? Pin
Ray Cassick15-Aug-02 17:58
Ray Cassick15-Aug-02 17:58 
AnswerRe: OnPaint() What am I missing? Pin
Nish Nishant15-Aug-02 19:09
sitebuilderNish Nishant15-Aug-02 19:09 
GeneralRe: OnPaint() What am I missing? Pin
albean15-Aug-02 19:30
albean15-Aug-02 19:30 
GeneralRe: OnPaint() What am I missing? Pin
Nish Nishant15-Aug-02 22:32
sitebuilderNish Nishant15-Aug-02 22:32 
AnswerRe: OnPaint() What am I missing? Pin
James T. Johnson16-Aug-02 0:52
James T. Johnson16-Aug-02 0:52 
QuestionHow to add a new record and get an autonumber field value Pin
Luis Alonso Ramos15-Aug-02 17:31
Luis Alonso Ramos15-Aug-02 17:31 
AnswerRe: How to add a new record and get an autonumber field value Pin
albean15-Aug-02 18:46
albean15-Aug-02 18:46 
GeneralRe: How to add a new record and get an autonumber field value Pin
Luis Alonso Ramos15-Aug-02 22:28
Luis Alonso Ramos15-Aug-02 22:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.