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. Fill 50% of a drawing with a color

Fill 50% of a drawing with a color

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

    Hi. Can someone show me how to fill 50% of the below drawing with a solid color. From buttom to top. Thanks Regards r9 The drawing: private System.Drawing.Graphics graphicsObj = null; private System.Drawing.Pen penBlackWidth1 = new System.Drawing.Pen(System.Drawing.Color.Black,1); private Point[] curvePoints = null; private SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray); private Point point1; private Point point2; private Point point3; private Point point4; private SolidBrush blackBrush = new SolidBrush(Color.Black); ................................................... try { graphicsObj = e.Graphics; graphicsObj.DrawLine(penBlackWidth1, 45, 20, 175, 20); graphicsObj.DrawLine(penBlackWidth1, 45, 20, 45, 120); graphicsObj.DrawLine(penBlackWidth1, 175, 20, 175, 120); graphicsObj.DrawLine(penBlackWidth1, 45,120,90,160); graphicsObj.DrawLine(penBlackWidth1, 175, 120, 135, 160); graphicsObj.DrawLine(penBlackWidth1, 90, 160, 135, 160); graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335); graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335); graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335); graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335); graphicsObj.DrawLine(penBlackWidth1, 473, 345, 483, 345); graphicsObj.DrawLine(penBlackWidth1, 473, 345, 478, 335); graphicsObj.DrawLine(penBlackWidth1, 483, 345, 478, 335); graphicsObj.DrawLine(penBlackWidth1, 587, 345, 597, 345); graphicsObj.DrawLine(penBlackWidth1, 587, 345, 592, 335); graphicsObj.DrawLine(penBlackWidth1, 597, 345, 592, 335); point1 = new Point(592,335); point2 = new Point(597,345); point3 = new Point(587,345); point4 = new Point(592,335); curvePoints = new Point[] { point1,point2, point3, point4 }; graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate); point1 = new Point(478,335); point2 = new Point(483,345); point3 = new Point(473,345); point4 = new Point(478,335); curvePoints = new Point[] { point1,point2, point3, point4 }; graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate); } catch (Exception ex) { MessageBox.Show(ex.Message); }

    H J 2 Replies Last reply
    0
    • R r9

      Hi. Can someone show me how to fill 50% of the below drawing with a solid color. From buttom to top. Thanks Regards r9 The drawing: private System.Drawing.Graphics graphicsObj = null; private System.Drawing.Pen penBlackWidth1 = new System.Drawing.Pen(System.Drawing.Color.Black,1); private Point[] curvePoints = null; private SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray); private Point point1; private Point point2; private Point point3; private Point point4; private SolidBrush blackBrush = new SolidBrush(Color.Black); ................................................... try { graphicsObj = e.Graphics; graphicsObj.DrawLine(penBlackWidth1, 45, 20, 175, 20); graphicsObj.DrawLine(penBlackWidth1, 45, 20, 45, 120); graphicsObj.DrawLine(penBlackWidth1, 175, 20, 175, 120); graphicsObj.DrawLine(penBlackWidth1, 45,120,90,160); graphicsObj.DrawLine(penBlackWidth1, 175, 120, 135, 160); graphicsObj.DrawLine(penBlackWidth1, 90, 160, 135, 160); graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335); graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335); graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335); graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335); graphicsObj.DrawLine(penBlackWidth1, 473, 345, 483, 345); graphicsObj.DrawLine(penBlackWidth1, 473, 345, 478, 335); graphicsObj.DrawLine(penBlackWidth1, 483, 345, 478, 335); graphicsObj.DrawLine(penBlackWidth1, 587, 345, 597, 345); graphicsObj.DrawLine(penBlackWidth1, 587, 345, 592, 335); graphicsObj.DrawLine(penBlackWidth1, 597, 345, 592, 335); point1 = new Point(592,335); point2 = new Point(597,345); point3 = new Point(587,345); point4 = new Point(592,335); curvePoints = new Point[] { point1,point2, point3, point4 }; graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate); point1 = new Point(478,335); point2 = new Point(483,345); point3 = new Point(473,345); point4 = new Point(478,335); curvePoints = new Point[] { point1,point2, point3, point4 }; graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate); } catch (Exception ex) { MessageBox.Show(ex.Message); }

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Here's a though - look in your mathematics book. If you want exactly 50%, then find the algorithm given specified polygram. This is a forum for C#, not math.

      Microsoft MVP, Visual C# My Articles

      R 1 Reply Last reply
      0
      • H Heath Stewart

        Here's a though - look in your mathematics book. If you want exactly 50%, then find the algorithm given specified polygram. This is a forum for C#, not math.

        Microsoft MVP, Visual C# My Articles

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

        Hi Heath Stewart The algorithm is not the problem. But how do I fill the figure? (the C# GDI+ code is my problem) Regards C#

        H 1 Reply Last reply
        0
        • R r9

          Hi Heath Stewart The algorithm is not the problem. But how do I fill the figure? (the C# GDI+ code is my problem) Regards C#

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Looking at the Graphics class, the logical choices are FillPolygon, FillPath, or FillRegion. Full class documentation - it's a great thing to read.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          • R r9

            Hi. Can someone show me how to fill 50% of the below drawing with a solid color. From buttom to top. Thanks Regards r9 The drawing: private System.Drawing.Graphics graphicsObj = null; private System.Drawing.Pen penBlackWidth1 = new System.Drawing.Pen(System.Drawing.Color.Black,1); private Point[] curvePoints = null; private SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray); private Point point1; private Point point2; private Point point3; private Point point4; private SolidBrush blackBrush = new SolidBrush(Color.Black); ................................................... try { graphicsObj = e.Graphics; graphicsObj.DrawLine(penBlackWidth1, 45, 20, 175, 20); graphicsObj.DrawLine(penBlackWidth1, 45, 20, 45, 120); graphicsObj.DrawLine(penBlackWidth1, 175, 20, 175, 120); graphicsObj.DrawLine(penBlackWidth1, 45,120,90,160); graphicsObj.DrawLine(penBlackWidth1, 175, 120, 135, 160); graphicsObj.DrawLine(penBlackWidth1, 90, 160, 135, 160); graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335); graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335); graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335); graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335); graphicsObj.DrawLine(penBlackWidth1, 473, 345, 483, 345); graphicsObj.DrawLine(penBlackWidth1, 473, 345, 478, 335); graphicsObj.DrawLine(penBlackWidth1, 483, 345, 478, 335); graphicsObj.DrawLine(penBlackWidth1, 587, 345, 597, 345); graphicsObj.DrawLine(penBlackWidth1, 587, 345, 592, 335); graphicsObj.DrawLine(penBlackWidth1, 597, 345, 592, 335); point1 = new Point(592,335); point2 = new Point(597,345); point3 = new Point(587,345); point4 = new Point(592,335); curvePoints = new Point[] { point1,point2, point3, point4 }; graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate); point1 = new Point(478,335); point2 = new Point(483,345); point3 = new Point(473,345); point4 = new Point(478,335); curvePoints = new Point[] { point1,point2, point3, point4 }; graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate); } catch (Exception ex) { MessageBox.Show(ex.Message); }

            J Offline
            J Offline
            je_gonzalez
            wrote on last edited by
            #5

            This code creates a control (based on the Panel) with a new property named "Colors". Setting the property yo an array of colors will display the colors. (example: multiColorPanel1.Colors = new Color[] { Color.Red, Color.White, Color.Blue}; end of example) using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; namespace Project1 { /// /// Summary description for MultiColorPanel. /// public class MultiColorPanel : System.Windows.Forms.Panel { private Color[] colors = null; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public MultiColorPanel() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // TODO: Add any initialization after the InitializeComponent call } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { components = new System.ComponentModel.Container(); } #endregion public Color[] Colors { get { return colors; } set { colors = value; this.Invalidate(); } } protected override void OnPaintBackground(PaintEventArgs pevent) { if ((colors != null) && (colors.Length > 0)) { Graphics area = pevent.Graphics; int height = this.Height / colors.Length; for (int index = 0; index < colors.Length; index++) { Rectangle rect = new Rectangle(0, height * index, this.Width, this.Height); Brush brush = new SolidBrush(colors[index]); pevent.Graphics.FillRectangle(brush, rect); } } else { base.OnPaintBackground (pevent); } } } }

            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