Device contexts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Taylor

    #1

    Device contexts

    Hi
    Does anybody have any code examples of using C# to draw to a window using
    device contexts, more specifically, erasing the entire window by painting a
    background color in the OnPaint / OnDraw event? What about using a buffer
    device context to draw to, then BitBlt ing that to the screen?
    Thanks
    Ben


  • Ben Taylor

    #2
    Re: Device contexts

    Thanks, I have tried this before, but for the life of me I couldn't get it
    to work - I've never used C# before and it seems like a really good
    language, it's just that whenever I tried to use the Graphics object to
    paint a white rectangle the size of the entire form, it still showed what
    was previously there. I just wondered if anyone had some sample code I could
    model what I want to do on. Never mind.

    "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
    in message news:%23cgWCkTV DHA.656@tk2msft ngp13.phx.gbl.. .[color=blue]
    > Ben,
    >
    > There are managed representations for almost everything you mention
    > here.
    >
    > If you want to draw to a window, then when you override the OnPaint
    > method, you can use the Graphics instance passed in to draw on the device
    > context. If you have other functions which take a device context handle,
    > then you can call the GetHdc method to get a handle you can pass to
    > unmanaged code to do your drawing.
    >
    > If you want to double buffer your calls in OnPaint, then you can call
    > the SetStyle method, passing in the following values (or'ed together) on
    > your class:
    >
    > ControlStyles.U serPaint
    > ControlStyles.A llPaintingInWmP aint
    > ControlStyles.D oubleBuffer
    >
    > The control will then be responsible for creating the other device
    > context and BitBlt'ing it back to the original device context.
    >
    > Hope this helps.
    >
    >
    > --
    > - Nicholas Paldino [.NET/C# MVP]
    > - nicholas.paldin o@exisconsultin g.com
    >
    >
    > "Ben Taylor" <ben_taylor_g1@ yahoo.co.uk> wrote in message
    > news:u8hPFdTVDH A.2340@TK2MSFTN GP10.phx.gbl...[color=green]
    > > Hi
    > > Does anybody have any code examples of using C# to draw to a window[/color][/color]
    using[color=blue][color=green]
    > > device contexts, more specifically, erasing the entire window by[/color][/color]
    painting[color=blue]
    > a[color=green]
    > > background color in the OnPaint / OnDraw event? What about using a[/color][/color]
    buffer[color=blue][color=green]
    > > device context to draw to, then BitBlt ing that to the screen?
    > > Thanks
    > > Ben
    > >
    > >[/color]
    >
    >[/color]


    Comment

    Working...