HighTechTalks DotNet Forums  

How to draw to the screen not the form?

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss How to draw to the screen not the form? in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
cheapguy
 
Posts: n/a

Default How to draw to the screen not the form? - 10-25-2006 , 05:27 PM






I need some code (VB or C#) that will draw a series of rectangles
(unfilled) to the screen's area, not a form or window area. I am trying
to simulate a technique I have seen when a new window opens, a series
of ever-larger rectangles are drawn to give a dynamic confirmation that
the form is opening. The rectangles increase in size until they have
reached the size of the form being opened, then the form is finally
displayed and the rectangles are removed. I want to add this to an
application I am writing so that when a form is opened, this dynamic
feedback will be shown. In order to do this, I have to be able to draw
the rectangles to the screen, not the current form since the form that
is about to be opened can be well outside the boundaries of the parent
form. Does anyone know how to do this?


Reply With Quote
  #2  
Old   
Joergen Bech
 
Posts: n/a

Default Re: How to draw to the screen not the form? - 10-25-2006 , 08:06 PM







A clue to the solution would be GetDC(IntPtr.Zero) in order to obtain
a device context to the screen.. There is a sample
here, drawing a filled ellipse on the screen:
http://www.thescripts.com/forum/thread263740.html

For drawing the rectangles, you need to look at some of the usual
rubber-band code floating around, such as
http://www.codeproject.com/cs/media/...erBandApp1.asp
In other words, use the XORPEN flag to draw it, then draw it again
using XORPEN to remove it.

But more importantly: You shouldn't do it. You do not know (I suppose
you could find out) what theme is enabled on the user's desktop, e.g.
whether Vista Aero or some other animation effect is already enabled
for forms as standard, so you would be interferring with the system
possibly end up with something ugly, e.g. rectangles not properly
removed because the system was drawing to the same area as your
code. I suppose this would not be a problem if you drew the animation
before attempting to show the form, which I presume would be the case.

Even more importantly: Before you start working on something like
this, read this blog post:
http://blogs.msdn.com/greg_schechter...02/588934.aspx
esp. the section "Drawing To and Reading From the Screen -- Baaaad!"

/Joergen Bech



On 25 Oct 2006 14:27:16 -0700, "cheapguy" <bmwm3e36 (AT) bellsouth (DOT) net>
wrote:

Quote:
I need some code (VB or C#) that will draw a series of rectangles
(unfilled) to the screen's area, not a form or window area. I am trying
to simulate a technique I have seen when a new window opens, a series
of ever-larger rectangles are drawn to give a dynamic confirmation that
the form is opening. The rectangles increase in size until they have
reached the size of the form being opened, then the form is finally
displayed and the rectangles are removed. I want to add this to an
application I am writing so that when a form is opened, this dynamic
feedback will be shown. In order to do this, I have to be able to draw
the rectangles to the screen, not the current form since the form that
is about to be opened can be well outside the boundaries of the parent
form. Does anyone know how to do this?


Reply With Quote
  #3  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: How to draw to the screen not the form? - 10-26-2006 , 06:52 AM



Just use ControlPaint.DrawReversiblexxx. That draws directly on the desktop
and can draw outside of windows etc.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"cheapguy" <bmwm3e36 (AT) bellsouth (DOT) net> wrote

Quote:
I need some code (VB or C#) that will draw a series of rectangles
(unfilled) to the screen's area, not a form or window area. I am trying
to simulate a technique I have seen when a new window opens, a series
of ever-larger rectangles are drawn to give a dynamic confirmation that
the form is opening. The rectangles increase in size until they have
reached the size of the form being opened, then the form is finally
displayed and the rectangles are removed. I want to add this to an
application I am writing so that when a form is opened, this dynamic
feedback will be shown. In order to do this, I have to be able to draw
the rectangles to the screen, not the current form since the form that
is about to be opened can be well outside the boundaries of the parent
form. Does anyone know how to do this?




Reply With Quote
  #4  
Old   
Joergen Bech
 
Posts: n/a

Default Re: How to draw to the screen not the form? - 10-26-2006 , 07:41 AM




Yes, that function does the same (although one is limited
to two styles then).

But the thing is: It still obtains/releases a handle to the
desktop DC under the covers. I understood from the article
I linked to in my previous post
(http://blogs.msdn.com/greg_schechter...02/588934.aspx)
that you should avoid writing to/reading from the screen (at
least for something as realtime as this, though a screen capture
program would be ok)?

I have a component where I currently draw some selection
rectangles directly on the screen (which is similar in nature to
what the original poster is attempting). Trouble is: When I run
this on Vista with Aero enabled, dragging those rectangles around
happen at a few frames a second, whereas it runs smooth
on XP (or Vista with the standard, non-Aero theme).

Wouldn't the original poster have the same problem if using
ControlPaint.DrawReversible...?

I have considered solving my own problem this way:

1. On MouseDown, grab a snapshot containing the portion of the screen
my interface occupies. Only one desktop GetDC required.

2. Put this snapshot on an overlay and display this on top of my
interface.

3. On MouseMove, draw my rectangles on the overlay.

4. On MouseUp, remove the overlay.

This would make the rectangles part of my application and would
not constantly force Vista in and out of DirectX10.

I am not convinced that ControlPaint.DrawReversible...
is as appropriate today as it has been in the past. Also remember that
this method *only* draws on the desktop. If you need to draw such
rectangles on other device contexts, you have to implement it
yourself.

Any thoughts?

/Joergen Bech



On Thu, 26 Oct 2006 12:52:19 +0200, "Bob Powell [MVP]"
<bob (AT) _spamkiller_ (DOT) bobpowell.net> wrote:

Quote:
Just use ControlPaint.DrawReversiblexxx. That draws directly on the desktop
and can draw outside of windows etc.


Reply With Quote
  #5  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: How to draw to the screen not the form? - 10-26-2006 , 04:33 PM



Hmm, I hadn't considered the Vista implications.

Maybe it'd be best to look at the Windows version and use the method best
suited to the technology. On XP ControlPaint is fine.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAM> wrote

Quote:
Yes, that function does the same (although one is limited
to two styles then).

But the thing is: It still obtains/releases a handle to the
desktop DC under the covers. I understood from the article
I linked to in my previous post
(http://blogs.msdn.com/greg_schechter...02/588934.aspx)
that you should avoid writing to/reading from the screen (at
least for something as realtime as this, though a screen capture
program would be ok)?

I have a component where I currently draw some selection
rectangles directly on the screen (which is similar in nature to
what the original poster is attempting). Trouble is: When I run
this on Vista with Aero enabled, dragging those rectangles around
happen at a few frames a second, whereas it runs smooth
on XP (or Vista with the standard, non-Aero theme).

Wouldn't the original poster have the same problem if using
ControlPaint.DrawReversible...?

I have considered solving my own problem this way:

1. On MouseDown, grab a snapshot containing the portion of the screen
my interface occupies. Only one desktop GetDC required.

2. Put this snapshot on an overlay and display this on top of my
interface.

3. On MouseMove, draw my rectangles on the overlay.

4. On MouseUp, remove the overlay.

This would make the rectangles part of my application and would
not constantly force Vista in and out of DirectX10.

I am not convinced that ControlPaint.DrawReversible...
is as appropriate today as it has been in the past. Also remember that
this method *only* draws on the desktop. If you need to draw such
rectangles on other device contexts, you have to implement it
yourself.

Any thoughts?

/Joergen Bech



On Thu, 26 Oct 2006 12:52:19 +0200, "Bob Powell [MVP]"
bob (AT) _spamkiller_ (DOT) bobpowell.net> wrote:

Just use ControlPaint.DrawReversiblexxx. That draws directly on the
desktop
and can draw outside of windows etc.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.