-
[GDI+] demo
I've been doing a few graphics demo's in the VB.Net forum and since I'm moving over to C# it would be rude to neglect the C# forum :D
I'd welcome any comments you might have.
Just put a button on your form and hook it up to this sub then click it a few times...
Code:
private void button1_Click(object sender, EventArgs e)
{
Random _R = new Random();
//define a rectangle to base the gradient brush on
Rectangle r =new Rectangle(10, 10, 500, 500);
//create the brush
LinearGradientBrush lgb = new LinearGradientBrush(r, Color.Red, Color.Yellow, 45);
//create a pen from the brush
Pen coolPen = new Pen(lgb, _R.Next(15, 50));
//make the pen have a multiple-nib effect and add a few other effects
coolPen.CompoundArray = new Single[]{0.0f, 0.3f, 0.4f, 0.7f, 0.85f, 1.0f};
//these effects are activated on a random basis
if(_R.NextDouble() < 0.5) coolPen.LineJoin = LineJoin.Round;
if (_R.NextDouble() < 0.5) coolPen.StartCap = LineCap.Round;
if (_R.NextDouble() < 0.5) coolPen.EndCap = LineCap.ArrowAnchor;
//customise dash pattern
if (_R.NextDouble() < 0.2) coolPen.DashPattern = new Single[] {1f, 0.2f, 2f, 0.2f, 1f, 2f, 0.5f, 1f};
//define the bezier control points
Point[] pts = new Point[] { new Point(25,50),
new Point(400,50),
new Point(500,200),
new Point(380,230),
new Point(300,150),
new Point(120,300),
new Point(280,400) };
//get a reference to the form's graphics object
Graphics gr = this.CreateGraphics();
//clear the drawing area
gr.Clear(this.BackColor);
//antialias the drawing
gr.SmoothingMode = SmoothingMode.AntiAlias;
//draw the effect
gr.DrawBeziers(coolPen, pts);
gr.Dispose();
lgb.Dispose();
coolPen.Dispose();
}
I didn't put this in the codebank because I'm not expert enough in C# yet :) (havent used it in a year, just getting back into the swing of things).
-
Re: [GDI+] demo
you noob:)
you need to dispose your brushes and your graphics objects and you pens and your life
-
Re: [GDI+] demo
That's true, forgot all about that. Not noob for long mate. :D