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. General Programming
  3. C#
  4. C# CreateGraphics()

C# CreateGraphics()

Scheduled Pinned Locked Moved C#
csharpgraphicsquestion
6 Posts 4 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.
  • M Offline
    M Offline
    Moon Boy
    wrote on last edited by
    #1

    Well, to draw on a panel, i use: Graphics pg = panel.CreateGraphics(); pg.FillEllipse( new SolidBrush( Color.Black ), e.X, e.Y,2,2); Its draw, but, when i minimize the form, the panel is clear! What can i do to not clear the draw? Thanks.

    C J 2 Replies Last reply
    0
    • M Moon Boy

      Well, to draw on a panel, i use: Graphics pg = panel.CreateGraphics(); pg.FillEllipse( new SolidBrush( Color.Black ), e.X, e.Y,2,2); Its draw, but, when i minimize the form, the panel is clear! What can i do to not clear the draw? Thanks.

      C Offline
      C Offline
      Charlie Williams
      wrote on last edited by
      #2

      Anytime a window is moved off screen, minimized, or is obstructed from view (by another window) it needs to be repainted then next time it is shown. In order for your graphics to survive this process, the drawing code needs to be called in response to the Paint event of the control in question (or in an override of OnPaint for a derived control). Also, when you move the code you posted to the Paint event handler, use the Graphics object supplied in the PaintEventHandler parameter instead of calling CreateGraphics. Charlie if(!curlies){ return; }

      1 Reply Last reply
      0
      • M Moon Boy

        Well, to draw on a panel, i use: Graphics pg = panel.CreateGraphics(); pg.FillEllipse( new SolidBrush( Color.Black ), e.X, e.Y,2,2); Its draw, but, when i minimize the form, the panel is clear! What can i do to not clear the draw? Thanks.

        J Offline
        J Offline
        Jay Shankar
        wrote on last edited by
        #3

        You need to modify your code as below:

        private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
        //create graphics object from PaintEvent Argument,
        //(this also reduces the flickkering)
        Graphics pg = e.Graphics;
        pg.DrawEllipse(new Pen(Color.Black ), 0, 0,
        this.panel1.Width,this.panel1.Height);
        pg.FillEllipse( new SolidBrush( Color.Red ), 0, 0,
        this.panel1.Width, this.panel1.Height);

        }

        M 1 Reply Last reply
        0
        • J Jay Shankar

          You need to modify your code as below:

          private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
          {
          //create graphics object from PaintEvent Argument,
          //(this also reduces the flickkering)
          Graphics pg = e.Graphics;
          pg.DrawEllipse(new Pen(Color.Black ), 0, 0,
          this.panel1.Width,this.panel1.Height);
          pg.FillEllipse( new SolidBrush( Color.Red ), 0, 0,
          this.panel1.Width, this.panel1.Height);

          }

          M Offline
          M Offline
          Moon Boy
          wrote on last edited by
          #4

          In this way, how i ll get the mouse position to draw? :((

          L J 2 Replies Last reply
          0
          • M Moon Boy

            In this way, how i ll get the mouse position to draw? :((

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            Moon Boy wrote: In this way, how i ll get the mouse position to draw? Thats windows job! Not yours.... top secret xacc-ide 0.0.1

            1 Reply Last reply
            0
            • M Moon Boy

              In this way, how i ll get the mouse position to draw? :((

              J Offline
              J Offline
              Jay Shankar
              wrote on last edited by
              #6

              Hi MoonBoy, You want me to write the entire code and logic, then below is it:

              int mouseX =0, mouseY =0;

              private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
              {
              //create graphics object from PaintEvent Argument,
              //other wise there can be flickkering
              Graphics pg = e.Graphics;
              pg.DrawEllipse(new Pen(Color.Black ), mouseX, mouseY, 50,50);
              pg.FillEllipse( new SolidBrush( Color.Red ),mouseX, mouseY, 50, 50);

              }

              private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
              {
              this.mouseX = e.X;
              this.mouseY = e.Y;
              this.panel1.Invalidate();
              }

              Do revert back whether it could solve your purpose or not? Regards, Jay.

              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