Results 1 to 12 of 12

Thread: Painting Over Controls

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    14

    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
    Thanks For Your Help!

  2. #2
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    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?

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  5. #5
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    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!

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  7. #7
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Painting Over Controls

    Yikes,This is crazyyyy..
    Awesomeee..Amazinggg..woww
    I am just drawing around on my desktop and everywhere on the screen..
    This is just crazy Mr Polite..
    You're wayy too cool.
    Thanks
    Godwin

    Help someone else with what someone helped you!

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  9. #9
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Painting Over Controls

    It gives me System.OutofMemory exception after a few minutes and my computer becomes slow too
    Godwin

    Help someone else with what someone helped you!

  10. #10
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Painting Over Controls

    Oh yes Mr Polite,Ill do that
    Godwin

    Help someone else with what someone helped you!

  11. #11
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Painting Over Controls

    Quote 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!!

  12. #12
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Painting Over Controls

    oh,Roger that...
    Ill do it now
    Godwin

    Help someone else with what someone helped you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width