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. draw

draw

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 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.
  • O Offline
    O Offline
    om_metab
    wrote on last edited by
    #1

    I have Question 1-how to applay undo/redo for draw panel 2-how to draw string on panel with keypress event 3-how to make image that i draw it in panel not dipeared even click another buttun to draw another ship

    F OriginalGriffO 2 Replies Last reply
    0
    • O om_metab

      I have Question 1-how to applay undo/redo for draw panel 2-how to draw string on panel with keypress event 3-how to make image that i draw it in panel not dipeared even click another buttun to draw another ship

      F Offline
      F Offline
      fjdiewornncalwe
      wrote on last edited by
      #2

      The answer can be found here, on the second link on the page.

      I wasn't, now I am, then I won't be anymore.

      1 Reply Last reply
      0
      • O om_metab

        I have Question 1-how to applay undo/redo for draw panel 2-how to draw string on panel with keypress event 3-how to make image that i draw it in panel not dipeared even click another buttun to draw another ship

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Please do not post the same question more than once: delete your other version before it gets a reply! I'm not going to answer your questions directly: I don't think you are quite ready to go that far, from your questions so far. Instead, some basics which should help you to do some of it, and will set you on the right path. At present, you are using CreateGraphics to get the Graphics object for drawing, probably in a timer event, or a loop. Am I right? Don't do that. Instead, handle the Panel.Paint event. (Click on the panel in the designer, select events in the Properties pane - the lightning bolt button - and double click the Paint event). In the handler routine, you have two parameters:

            void panel\_Paint(object sender, PaintEventArgs e)
                {
                }
        

        The sender is the panel that need to be painted, and e is the information you need to know about how to paint it. Convert the sender to a Panel, and get the Graphics object from e:

            void panel\_Paint(object sender, PaintEventArgs e)
                {
                Panel myPanel = sender as Panel;
                if (myPanel != null)
                    {
                    Graphics g = e.Graphics;
        
                    }
                }
        

        Don't worry about the conversion code: it just means you can use the same method for more than one Panel if you need to. You can now use g to draw on the Panel, and it will not disappear. So, that solves question 3! How do you draw text? Simple:

                    g.DrawString("Hello", new Font("Arial",16), Brushes.Black, new Point(0,0));
        

        How do you make the Panel draw when you want? Simple:

                myPanel.Invalidate();
        

        Call that when you have changed the information that you want to draw - the position of the text, for example. (Don't call it in the Paint handler, that won't work!) So that solves question 2! Question 1 is probably way too complex at the moment - which makes me think you have asked the wrong question! If it is still a problem, try asking in more detail about what you are trying to do.

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        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