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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. GDI+ FillPolygon

GDI+ FillPolygon

Scheduled Pinned Locked Moved C#
graphicswinformstutorialquestion
7 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.
  • R Offline
    R Offline
    r9
    wrote on last edited by
    #1

    Can anyone show me how to fill this figure with a blue color? System.Drawing.Graphics formGraphics = null; System.Drawing.Pen myPen; formGraphics = pictureBox7.CreateGraphics(); myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1); formGraphics.DrawLine(myPen, 4, 4, 50, 4); formGraphics.DrawLine(myPen, 4, 4, 4, 100); formGraphics.DrawLine(myPen, 50, 4, 50, 100); formGraphics.DrawLine(myPen, 4, 100, 27, 120); formGraphics.DrawLine(myPen, 50, 100, 27, 120); Maybe with the FillPolygon method.

    V 1 Reply Last reply
    0
    • R r9

      Can anyone show me how to fill this figure with a blue color? System.Drawing.Graphics formGraphics = null; System.Drawing.Pen myPen; formGraphics = pictureBox7.CreateGraphics(); myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1); formGraphics.DrawLine(myPen, 4, 4, 50, 4); formGraphics.DrawLine(myPen, 4, 4, 4, 100); formGraphics.DrawLine(myPen, 50, 4, 50, 100); formGraphics.DrawLine(myPen, 4, 100, 27, 120); formGraphics.DrawLine(myPen, 50, 100, 27, 120); Maybe with the FillPolygon method.

      V Offline
      V Offline
      Valeria Bogdevich
      wrote on last edited by
      #2

      Point[] points = { new Point(4, 4), new Point(50, 4), new Point(50, 100), new Point(27, 120), new Point(4, 100), new Point(4, 4)}; SolidBrush brush = new SolidBrush(Color.Blue); e.Graphics.FillPolygon(brush, points, FillMode.Alternate); e.Graphics.DrawLines(myPen, points);

      R 1 Reply Last reply
      0
      • V Valeria Bogdevich

        Point[] points = { new Point(4, 4), new Point(50, 4), new Point(50, 100), new Point(27, 120), new Point(4, 100), new Point(4, 4)}; SolidBrush brush = new SolidBrush(Color.Blue); e.Graphics.FillPolygon(brush, points, FillMode.Alternate); e.Graphics.DrawLines(myPen, points);

        R Offline
        R Offline
        r9
        wrote on last edited by
        #3

        WiB: Thanks. It works perfekt. How do you know in which order to put the Points?? Eks: Point[] points = { new Point(4, 4), new Point(50, 4), new Point(50, 100), new Point(27, 120), new Point(4, 4), new Point(4, 100)}; Won't fill the figure correkt.

        V 1 Reply Last reply
        0
        • R r9

          WiB: Thanks. It works perfekt. How do you know in which order to put the Points?? Eks: Point[] points = { new Point(4, 4), new Point(50, 4), new Point(50, 100), new Point(27, 120), new Point(4, 4), new Point(4, 100)}; Won't fill the figure correkt.

          V Offline
          V Offline
          Valeria Bogdevich
          wrote on last edited by
          #4

          Because there is a rule: You put points in the same order like it would be if you draw figure by hand without break: you start from first point in array, draw line until second, after draw line from second point to third and so on to the last point. And normally I start and finish points array with the same point, but it's not allways necessary.

          R 1 Reply Last reply
          0
          • V Valeria Bogdevich

            Because there is a rule: You put points in the same order like it would be if you draw figure by hand without break: you start from first point in array, draw line until second, after draw line from second point to third and so on to the last point. And normally I start and finish points array with the same point, but it's not allways necessary.

            R Offline
            R Offline
            r9
            wrote on last edited by
            #5

            Thanks again

            R 1 Reply Last reply
            0
            • R r9

              Thanks again

              R Offline
              R Offline
              r9
              wrote on last edited by
              #6

              WiB: Is it possible to make the mouse cursor = Cursors.Hand if the the user point the mouse inside my figure ? formGraphics.DrawLine(myPen, 4, 4, 50, 4); formGraphics.DrawLine(myPen, 4, 4, 4, 100); formGraphics.DrawLine(myPen, 50, 4, 50, 100); formGraphics.DrawLine(myPen, 4, 100, 27, 120); formGraphics.DrawLine(myPen, 50, 100, 27, 120);

              V 1 Reply Last reply
              0
              • R r9

                WiB: Is it possible to make the mouse cursor = Cursors.Hand if the the user point the mouse inside my figure ? formGraphics.DrawLine(myPen, 4, 4, 50, 4); formGraphics.DrawLine(myPen, 4, 4, 4, 100); formGraphics.DrawLine(myPen, 50, 4, 50, 100); formGraphics.DrawLine(myPen, 4, 100, 27, 120); formGraphics.DrawLine(myPen, 50, 100, 27, 120);

                V Offline
                V Offline
                Valeria Bogdevich
                wrote on last edited by
                #7

                1). In OnPaint: Point[] points = { new Point(4, 4), new Point(50, 4), new Point(50, 100), new Point(27, 120), new Point(4, 100), new Point(4, 4)}; GraphicsPath path = new GraphicsPath(); path.AddLines(points); Region reg = new Region(path); bounds = reg.GetBounds(e.Graphics); 2). Override OnMouseMove method as follow: protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { if (bounds.Contains(e.X, e.Y)) this.Cursor = Cursors.Hand; else this.Cursor = Cursors.Default; base.OnMouseEnter(e); } RectangleF bounds is global This is if you want to draw a shape on a form. If your shape is a control on the form, you should do it by another way. PS: Because variable bounds you inisialize only once, you should do it, for example, in constructor or you may keep it in OnPaint but make sure that you initialize it once (performance!).


                "...hasn't really been well accepted ... as the ratings tell us so far :)" - Nishant S

                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