Results 1 to 5 of 5

Thread: Drawing other controls

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662

    Drawing other controls

    I'm trying to code a designer for controls for my app (not an IDE designer). I'm going to be able to move the control around and size it using the mouse. I want to prevent mouse events on the control without disabling the control. The best way I can think of this is to hijack the drawing code and draw the control into my own control.

    I got it to work with the Button control: I call the OnPaint method. How? (Considering that it's protected...) I used reflection to find the "OnPaint" method signature and called it using the invoke method providing it the graphics object attached to a label control. The code to invoke the Button's paint event was in the Label's paint event.

    This worked surprisingly well for the button. Unfortunately, it didn't work so well for other controls, such as the Listbox.

    Using Lutz Roeder's .NET Reflector* (to decompile the listboxes drawing methods) I discovered that the Listbox does it's drawing from a method called by WndProc instead of OnPaint (like a rational control...)

    Is there a way anybody knows of to cause a control, in most sane circumstances, to paint to a Graphics object that is not its own?

    Do you know of a better way to obtain my long-term goal of preventing mouse events from reaching a visible and enabled control?

    I'm designing this with the intention that it work with anything that inherits Control.

    ---
    *Using Lutz Roeder's .NET Reflector decompiles .Net assemblies through reflection. Available free at http://www.aisto.com/roeder/dotnet/
    Last edited by agent; Nov 23rd, 2006 at 03:08 AM. Reason: Added URL for .NET Reflector

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