|
-
Apr 11th, 2005, 05:24 PM
#1
Thread Starter
New Member
Painting Over Controls
Does anyone know of a way to paint a rectangle similar to the type thats drawn when you reposition a tool window in windows.
My problem is that you need to know which graphics context to draw it on, and what do you do if it spans multiple hdc's?
thanks
-
Sep 7th, 2005, 10:24 AM
#2
Junior Member
Re: Painting Over Controls
I'm reactivating this thread because i have the same problem.
I have some controls on a form. And i want to paint some lines *over* the controls.
If i use this.CreateGraphics, everything is drawn behind those controls. How can it be resolved?
-
Sep 7th, 2005, 02:57 PM
#3
Re: Painting Over Controls
okay both of you need to bow down in front of me (jk hehe )
I feel l33t. What you need to do is to create your graphics object using the API I'm using.
this.Handle refers to the window handle of the form. You give the window handle to the GetWindowDC and it returns a device context that can be used to draw over the window. Using CreateGraphics() would do the same as calling the GetDC() api with the window handle
Code:
// you need this namespace to use dllImport
// using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr dc = GetWindowDC (this.Handle);
Graphics gr = Graphics.FromHdc (dc);
gr.DrawLine (Pens.Red, new Point(0,0), new Point (this.Right, this.Bottom));
gr.Dispose();
}
the actual code's inside a button click.
So basically create your graphics object like that and the rest is that same
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 7th, 2005, 03:02 PM
#4
Re: Painting Over Controls
umm there is a ReleaseDC api also. I'm no API expert (have very minimal experience actually ) but I "think" that using gr.Dispose() releases it.
you might want to double check on that
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 11th, 2005, 04:18 AM
#5
Fanatic Member
Re: Painting Over Controls
yes It does release it even I think after testing that code...
But,Mr.Polite,This also only draws a line over the form...and not over the screen in windows ..
So,Is there any API that can help drawing a line over the whole screen?
Godwin
Help someone else with what someone helped you! 
-
Sep 11th, 2005, 06:02 PM
#6
Re: Painting Over Controls
yeah the GetDC api called with a 0 param
ie (haven't tested this, but it should work)
Code:
using System.Runtime.Interopservices...
[DllImport("user32")]
public static extern IntPtr GetDC(IntPtr hwnd)
// retrieve the desktop handle
IntPtr desktopDC = GetDC(IntPtr.Zero);
then use the DC the same as you used it above
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 12th, 2005, 01:37 AM
#7
-
Sep 12th, 2005, 01:47 AM
#8
Re: Painting Over Controls
hehehehe
you're welcome 
if you really care about doing it properly, you might wanna drop a post in the api forum and ask them if calling GetDC(0) is the proper way of retreiving the dektop handle, and also you might want to use ReleaseDC when you're done with your drawing....
won't matter much if you're just messing around though hehehe
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 12th, 2005, 01:48 AM
#9
-
Sep 12th, 2005, 01:49 AM
#10
-
Sep 12th, 2005, 01:54 AM
#11
Re: Painting Over Controls
 Originally Posted by uniquegodwin
It gives me System.OutofMemory exception after a few minutes and my computer becomes slow too 
lol wow

try calling GetDC once and then saving the value.... use the saved value in your paint event. That might make things smoother also
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 12th, 2005, 01:55 AM
#12
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|