Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Drawing to custom control surface help please

Drawing to custom control surface help please

Scheduled Pinned Locked Moved Mobile
graphicshelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daxfrost
    wrote on last edited by
    #1

    Hi anyone! I am trying to draw to my custom control with VS2005 with compact framework 2.0. My control and a second class which references its Graphics object are seperate but in the same file... i create my second class and attempt to draw small images on the control using its graphics object reference at later stages of the app running. I get an ObjectDisposedException, but I understand what this means, but is there anywway I can reference the controls drawing object just before i process the drawing code? or any other work around for that matter! thankyou in advance for this!

    M 1 Reply Last reply
    0
    • D daxfrost

      Hi anyone! I am trying to draw to my custom control with VS2005 with compact framework 2.0. My control and a second class which references its Graphics object are seperate but in the same file... i create my second class and attempt to draw small images on the control using its graphics object reference at later stages of the app running. I get an ObjectDisposedException, but I understand what this means, but is there anywway I can reference the controls drawing object just before i process the drawing code? or any other work around for that matter! thankyou in advance for this!

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Best practice is to do all your drawing in the OnPaint method or in a handler for the Paint event. You can cause a callback into OnPaint by calling the Invalidate method, to tell Windows what part of the control needs to be repainted. If you want to perform some immediate painting, rather than waiting for the Paint event to fire (which is deferred, in the Windows messaging model, to allow input to be processed at a higher priority than painting operations) follow this pattern:

      using ( Graphics g = ctl.CreateGraphics() )
      {
      // do drawing here
      }

      The documentation for CreateGraphics specifically says, "The Graphics is only valid for the duration of the current window's message." You are not allowed to save it and reuse it. The technical reason behind this is that Device Contexts - the Windows data structure behind the Graphics object - are expensive, and the system only keeps a small pool of them available. If you were to retain them, the pool would quickly run out and no-one would be able to draw anything. So the Framework automatically gives it back at the end of processing every window message. You still need to remember everything that you've drawn anyway and be prepared to redraw it in OnPaint. Windows does not save your screen layout when something is drawn on top of it (the start menu, a notification bubble, another application), you have to repaint it when the obscuring object is removed. The best resource for understanding Windows' drawing and events model is Charles Petzold's book "Programming Windows, Fifth Edition". Yes, it hasn't been updated in 10 years. It targets desktop Windows. It uses the C programming language. The fundamentals are the same between the desktop and CE, and they haven't changed since Win32 was introduced with NT 3.1 in 1993. If you do turn your hand to the desktop, note that Windows Vista with Aero now does save your drawing because you're not actually drawing to the screen, you're drawing to an off-screen bitmap which the graphics card combines with all the other windows' bitmaps to produce the screen output. You should still do all your drawing in OnPaint so that the drawing can be synchronized properly.

      DoEvents: Generating unexpected recursion since 1991

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups