By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,929 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,929 IT Pros & Developers. It's quick & easy.

System.Drawing.Drawing2D examples

P: n/a
Hi,

I'm looking for examples of the different brush and fill styles that can
be made using System.Drawing.Drawing2D. I haven't actually used this
class before, so any example code accompanying visual style examples
would be an ideal thing to help me learn.

Does anyone know of a website that has such examples?

Cheers,

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
Jan 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Dylan,

Here's an example:

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class TestForm : Form
{
public TestForm()
{
DoubleBuffered = true;
ResizeRedraw = true;
BackColor = Color.White;
}

protected override void OnPaint(PaintEventArgs e)
{
int height = ClientRectangle.Height / 3;
int width = ClientRectangle.Width;
int y = 0;

Rectangle hatchArea = new Rectangle(0, y, width, height);
y += height;
Rectangle gradientArea = new Rectangle(0, y, width, height);
y += height;
Rectangle pathArea = new Rectangle(0, y, width, height);

using (HatchBrush hatchBrush = new HatchBrush(
HatchStyle.Cross, Color.Red, Color.Blue))
{
e.Graphics.FillRectangle(hatchBrush, hatchArea);
}

using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
gradientArea, Color.Green, Color.White,
LinearGradientMode.ForwardDiagonal))
{
e.Graphics.FillRectangle(gradientBrush, gradientArea);
}

using (GraphicsPath path = new GraphicsPath())
{
path.AddBezier(0, y, width, y, width, y + height, 0, y + height);

using (PathGradientBrush pathBrush = new PathGradientBrush(path))
{
pathBrush.CenterColor = Color.HotPink;
pathBrush.CenterPoint = new PointF(width / 4, y + height / 2);
pathBrush.SurroundColors = new Color[] {
Color.Yellow,
Color.Lavender,
Color.Ivory,
Color.Indigo
};

e.Graphics.FillRectangle(pathBrush, pathArea);
}
}
}
}
--
Dave Sexton
http://davesexton.com/blog

"Dylan Parry" <us****@dylanparry.comwrote in message
news:51*************@mid.individual.net...
Hi,

I'm looking for examples of the different brush and fill styles that can
be made using System.Drawing.Drawing2D. I haven't actually used this
class before, so any example code accompanying visual style examples
would be an ideal thing to help me learn.

Does anyone know of a website that has such examples?

Cheers,

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.

Jan 16 '07 #2

P: n/a
Dave Sexton wrote:
Here's an example:
[...]

Cheers for that. The mere fact that I understood what was going on has
improved my mood by miles :)

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
Jan 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.