I have a form with several controls. I would like to paint *over* several
controls (mainly GroupBoxes and Labels). But, Everywhere I try to perform
painting, I end up "behind" the controls. I need a device context for the
entire form, that I can render to *after* all the controls have been
painted.
Suggestions?
Thanks
DanB 4 13118
You can get a Graphics object for each of the controls seperately by calling CreateGraphics() on each of them.
You can hide the controls by calling Hide() and just paint normally.
Unfortunately, I don't think there is a way to obtain a device context that will draw over a child control, however, there is a
class style that can be used to set the control's device context to that of the parent's. Form and Control do not set this flag so
you'd have to implement your own container using NativeWindow. Probably not worth the effort.
Maybe, you can try to prevent the controls from refreshing by overriding the WndProc method and preventing any paint messages from
being sent to the child controls. I'm not sure if this can be done, but it might not help since Windows will probably "remember"
the last bitmap used for each control and overwrite your form's context anyway.
If simply hiding the controls isn't good enough (if you need to do alpha blending or overwrite non-client area, etc. and keep the
controls visible) then I would suggest you create "smart" implementations of the controls on the form so that they can render as
appropriate for their clipping region.
GL
--
Dave Sexton dave@www..jwaonline..com
-----------------------------------------------------------------------
"Dan Baker" <dbmail> wrote in message news:OM**************@TK2MSFTNGP15.phx.gbl... I have a form with several controls. I would like to paint *over* several controls (mainly GroupBoxes and Labels). But, Everywhere I try to perform painting, I end up "behind" the controls. I need a device context for the entire form, that I can render to *after* all the controls have been painted.
Suggestions? Thanks DanB
This is completely erroneous and will cause nothing but pain.
You must NEVER paint on a control after obtaining it's Graphics object using
CreateGraphics. See the GDI+ FAQ #1 most asked question for details.
You can use interop to obtain the desktop window and draw directly on that.
This will enable pixels to be forced onto any control but can cause a few
problems for clean refreshes.
The best method is to use a seperate layered window control with per-pixel
alpha to create a semi-transparent window that sits on top of all others on
the form.
--
Bob Powell [MVP]
Visual C#, System.Drawing
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.
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl... You can get a Graphics object for each of the controls seperately by calling CreateGraphics() on each of them. You can hide the controls by calling Hide() and just paint normally.
Unfortunately, I don't think there is a way to obtain a device context that will draw over a child control, however, there is a class style that can be used to set the control's device context to that of the parent's. Form and Control do not set this flag so you'd have to implement your own container using NativeWindow. Probably not worth the effort.
Maybe, you can try to prevent the controls from refreshing by overriding the WndProc method and preventing any paint messages from being sent to the child controls. I'm not sure if this can be done, but it might not help since Windows will probably "remember" the last bitmap used for each control and overwrite your form's context anyway.
If simply hiding the controls isn't good enough (if you need to do alpha blending or overwrite non-client area, etc. and keep the controls visible) then I would suggest you create "smart" implementations of the controls on the form so that they can render as appropriate for their clipping region.
GL
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Dan Baker" <dbmail> wrote in message news:OM**************@TK2MSFTNGP15.phx.gbl...I have a form with several controls. I would like to paint *over* several controls (mainly GroupBoxes and Labels). But, Everywhere I try to perform painting, I end up "behind" the controls. I need a device context for the entire form, that I can render to *after* all the controls have been painted.
Suggestions? Thanks DanB
Your solution sounds good. I'm trying to animate over the controls (like a
bouncing arrow, pointing into a list of items). All controls are static, and
don't have any user-interaction, so the refresh shouldn't be a problem.
I've done this before in MFC without problems.
I would like to perform the animation in a timer routine. Is there any way
of getting a Graphics object in the timer routine that will allow me to
paint on this semi-transparent window you are describing?
DanB
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl... This is completely erroneous and will cause nothing but pain.
You must NEVER paint on a control after obtaining it's Graphics object using CreateGraphics. See the GDI+ FAQ #1 most asked question for details.
You can use interop to obtain the desktop window and draw directly on that. This will enable pixels to be forced onto any control but can cause a few problems for clean refreshes.
The best method is to use a seperate layered window control with per-pixel alpha to create a semi-transparent window that sits on top of all others on the form.
-- Bob Powell [MVP] Visual C#, System.Drawing
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.
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:eg**************@TK2MSFTNGP09.phx.gbl... You can get a Graphics object for each of the controls seperately by calling CreateGraphics() on each of them. You can hide the controls by calling Hide() and just paint normally.
Unfortunately, I don't think there is a way to obtain a device context that will draw over a child control, however, there is a class style that can be used to set the control's device context to that of the parent's. Form and Control do not set this flag so you'd have to implement your own container using NativeWindow. Probably not worth the effort.
Maybe, you can try to prevent the controls from refreshing by overriding the WndProc method and preventing any paint messages from being sent to the child controls. I'm not sure if this can be done, but it might not help since Windows will probably "remember" the last bitmap used for each control and overwrite your form's context anyway.
If simply hiding the controls isn't good enough (if you need to do alpha blending or overwrite non-client area, etc. and keep the controls visible) then I would suggest you create "smart" implementations of the controls on the form so that they can render as appropriate for their clipping region.
GL
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Dan Baker" <dbmail> wrote in message news:OM**************@TK2MSFTNGP15.phx.gbl...I have a form with several controls. I would like to paint *over* several controls (mainly GroupBoxes and Labels). But, Everywhere I try to perform painting, I end up "behind" the controls. I need a device context for the entire form, that I can render to *after* all the controls have been painted.
Suggestions? Thanks DanB
I think Bob's suggesting that you create an overlaid window, that's transparent, and covers your entire form area.
You'd have to hook-up the events so that any changes to the underlying Form's location/bounds is reflected on the overlaying window.
If you use an overlaying Form you can use Windows API calls (or the CreateGraphics() method that Bob doesn't like) to obtain the
device context and draw at any time (including in a timer routine), or you can create a custom window implementation by deriving
from NativeWindow. Using the latter solution forces you to write most of the code using Interop.
Here's the reference I use for GDI coding: http://msdn.microsoft.com/library/de...vcons_8x45.asp
GL
--
Dave Sexton dave@www..jwaonline..com
-----------------------------------------------------------------------
"Dan Baker" <dbmail> wrote in message news:u6**************@TK2MSFTNGP10.phx.gbl... Your solution sounds good. I'm trying to animate over the controls (like a bouncing arrow, pointing into a list of items). All controls are static, and don't have any user-interaction, so the refresh shouldn't be a problem. I've done this before in MFC without problems.
I would like to perform the animation in a timer routine. Is there any way of getting a Graphics object in the timer routine that will allow me to paint on this semi-transparent window you are describing?
DanB
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:e4**************@TK2MSFTNGP12.phx.gbl... This is completely erroneous and will cause nothing but pain.
You must NEVER paint on a control after obtaining it's Graphics object using CreateGraphics. See the GDI+ FAQ #1 most asked question for details.
You can use interop to obtain the desktop window and draw directly on that. This will enable pixels to be forced onto any control but can cause a few problems for clean refreshes.
The best method is to use a seperate layered window control with per-pixel alpha to create a semi-transparent window that sits on top of all others on the form.
-- Bob Powell [MVP] Visual C#, System.Drawing
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.
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:eg**************@TK2MSFTNGP09.phx.gbl... You can get a Graphics object for each of the controls seperately by calling CreateGraphics() on each of them. You can hide the controls by calling Hide() and just paint normally.
Unfortunately, I don't think there is a way to obtain a device context that will draw over a child control, however, there is a class style that can be used to set the control's device context to that of the parent's. Form and Control do not set this flag so you'd have to implement your own container using NativeWindow. Probably not worth the effort.
Maybe, you can try to prevent the controls from refreshing by overriding the WndProc method and preventing any paint messages from being sent to the child controls. I'm not sure if this can be done, but it might not help since Windows will probably "remember" the last bitmap used for each control and overwrite your form's context anyway.
If simply hiding the controls isn't good enough (if you need to do alpha blending or overwrite non-client area, etc. and keep the controls visible) then I would suggest you create "smart" implementations of the controls on the form so that they can render as appropriate for their clipping region.
GL
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Dan Baker" <dbmail> wrote in message news:OM**************@TK2MSFTNGP15.phx.gbl... I have a form with several controls. I would like to paint *over* several controls (mainly GroupBoxes and Labels). But, Everywhere I try to perform painting, I end up "behind" the controls. I need a device context for the entire form, that I can render to *after* all the controls have been painted.
Suggestions? Thanks DanB
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Jhin |
last post by:
I have this very basic Custom Control:
public class TestPanel : Panel
{
public TestPanel() : base()
{
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque |...
|
by: Ron Vecchi |
last post by:
I have a custyom control that has a property which wraps a collection. When
I add controls to the collection the OnPaint method of these newly added
controls never get fired.
But if I take the...
|
by: |
last post by:
Please, help.
I created my contol, ButtonX, which subclasses System.Forms.Windows.Button
class. I am doing my own paiting, by overriding OnPaint and
OnPaintBackground (without calling base...
|
by: Richard |
last post by:
I have a requirement to put a GDI style circle or rectangle border around
the selected row of a datagrid/ It will overlap into the row above and below
the selected row. Doing this in a the OnPaint...
|
by: BB |
last post by:
Hello all,
I am trying to override OnPaint in a custom textbox
control (so I can drawstring a caption, etc.). In the
code below, I get the "painting the form" message as
expected, but not the...
|
by: dominique |
last post by:
Hi,
In windows forms (vb.net), i use my own controls subclassed from base
controls and i override the Onxxx methods.
for example:
Public Class MyBouton
Inherits System.Windows.Forms.Button...
|
by: Jon Slaughter |
last post by:
I'm trying to wrap all the basic controls(Button, scrollbar, etc..) to allow
for skinning. The problem is that many of the controls seem so different in
the way they work. For example, right now...
|
by: grayaii |
last post by:
Hi,
I have a simple form that handles all its paint functionality like so:
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
And the entry point to this...
|
by: sean |
last post by:
I'm trying to create "rubber-band" rectangles by overriding the
OnPaint method to place rectangles on top of all graphic controls, but
when I call Me.Invalidate() (when the user moves the mouse),...
|
by: GaryTexmo |
last post by:
In my last insight, http://bytes.com/topic/c-sharp/insights/909141-object-scaling-varying-resolutions, I talked about scaling objects to a form's size so that it would always draw with the correct...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |