Click here to Skip to main content
15,669,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay so this is my code:
<pre>void GenerateChalkStripes()

            /* If i comment this section out like this
			using (Graphics gfx = Graphics.FromImage(bmp))
			using (SolidBrush brush = new SolidBrush(colors[0]))
				gfx.FillRectangle(brush, 0, 0, 400, 400);
/*It works. It generates the stripes as I want it to, but with a background in the color "Control" (the default for WinForms). I want it to draw this background, and then add the stripes over the background... BUT when I try this by removing this comment, it simply does the background and ignores the stripes. Why? How is it not possible to layer pixels? Do I to like print it out to the pictureBox1, then create a new bitmap variable from the pictureBox1 or something? Or have I simply forgotten to like close the brush tool or something stupid?*/

			Bitmap bmp = new Bitmap(400, 400);
			Random r = new Random();
			int numOfStripes = r.Next(4, 16);
			int stripeThickness = r.Next(1, 16);
			int cutoutThickness = r.Next(1, 8);
			int numOfCutouts = r.Next(20, 80);

			int thicknessPerThickBar = (400 /*- (numOfStripes * stripeThickness)*/) / numOfStripes;

			using (Graphics gfx = Graphics.FromImage(bmp))
			using (SolidBrush brush = new SolidBrush(colors[1]))
				for (int i = 0; i < numOfStripes; i++)
					int startX = thicknessPerThickBar * i;
					gfx.FillRectangle(brush, startX, 0, stripeThickness, 400);

			pictureBox1.Image = bmp;

What I have tried:

I have tried moving around the problematic section.
Updated 30-Dec-21 7:34am

1 solution

Figured it out, it doesn't change color. I just need to find how to change color of the brush.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900