|
-
Sep 9th, 2005, 11:40 PM
#1
Thread Starter
Fanatic Member
A small error...
Hello...
Im trying out this GDI+ a bit..just a beginner,so forgive me if I sound like a dummy...
VB Code:
System.Drawing.Drawing2D.LinearGradientBrush gradbr = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.Blue,Color.Red);
What is the error on that line?
My compiler shows me this..
Code:
C:\Documents and Settings\Godwin\My Documents\Visual Studio Projects\testingsharp\Form1.cs(87): No overload for method 'LinearGradientBrush' takes '3' arguments
I have entered all the parameters in there i think..so,what is wrong there?
Godwin
Help someone else with what someone helped you! 
-
Sep 10th, 2005, 12:02 AM
#2
Thread Starter
Fanatic Member
Re: A small error...
Oh Thank God no one saw this thread..
so silly of me..I didnt enter all the parameters..i think theyre called arguments in c# 
Code:
System.Drawing.Drawing2D.LinearGradientBrush gradbr = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.Red,Color.White,10,true);
ok,btw,I made something wierd...which makes the form flicker asif displaycard went crazy...heheh
Code:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Graphics g;
g=e.Graphics;
System.Drawing.Rectangle rec=new Rectangle(0,0,this.Width,this.Height);
Invalidate();
System.Drawing.Drawing2D.LinearGradientBrush gradbr = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.Red,Color.White,10,true);
g.FillRectangle(gradbr,rec);
}
Godwin
Help someone else with what someone helped you! 
-
Sep 10th, 2005, 12:18 AM
#3
Re: A small error...
oooh
remove the "invalidate()" line from the paint event!
invalidate makes the form redraw itself. Each time the form wants to redraw itself, the paint event is called. So basically what you're doing is you are drawing on the form , and then again you are asking the form to clear everything and call the paint event again and again and again ....
You should dispose your gradient brush also (gradbr.dispose(). A much better idea however is to create your brush outside of the paint event (ie, use it as a private variable inside the class and assign it in form_load, this way you won't have to create a new brush each time the form is repainted).
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 10th, 2005, 12:39 AM
#4
Thread Starter
Fanatic Member
Re: A small error...
Hi Mr.Polite..
If I remove the Invalidate(),It doesnt show me that flickering graphics.
This is what I did now..Im doing some crazy code...just messing around but,you know,sometimes,this is soo cool.
Im not sure how to declare public variables in c#....In vb,we could just say Public s as string...Public f1 as new form..Im not sure of the samething in c#,so,for now,I just used the dispose() as you told me to 
Code:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Graphics g;
g=e.Graphics;
System.Drawing.Rectangle rec=new Rectangle(0,0,this.Width,this.Height);
g.Clear(Color.Yellow);
System.Drawing.Drawing2D.LinearGradientBrush gradbr = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.Red,Color.White,10,true);
g.FillRectangle(gradbr,rec);
Invalidate();
g.Clear(Color.Green);
g.Clear(Color.Blue);
gradbr.Dispose();
}
Godwin
Help someone else with what someone helped you! 
-
Sep 10th, 2005, 12:46 AM
#5
Re: A small error...
lol
I still say remove it
even if you're messing around
if you want to create an "animation" sort of thing, then maybe use a timer control and invalidate the form in there, then draw the content
when I said public varaible I didn't really mean public... I meant a class-level variable
you could declare it on the top part of the form (after this line public class Form1 : System.Windows.Forms.Form
{
basically you can declare it anywhere inside the class, but people usually declare class variables on top.
ie:
Code:
using System.Drawing.Drawing2D; // so you wouldnt have to type the whole thing again to create a brush
public class Form1 : System.Windows.Forms.Form
{
private LinearGradientBrush gradBr = ...;
//.....
}
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 10th, 2005, 12:53 AM
#6
Thread Starter
Fanatic Member
-
Sep 10th, 2005, 12:56 AM
#7
Thread Starter
Fanatic Member
Re: A small error...
Mr.Polite,I wonder how I can just set this same program as a screensaver..I can just rename it to .scr and simply put it?
I saw the sample given for screensave in 101 samples,but,I didnt understand how they actually put the form as a screensaver...
Godwin
Help someone else with what someone helped you! 
-
Sep 10th, 2005, 01:14 AM
#8
Thread Starter
Fanatic Member
Re: A small error...
Mr.Polite,I tried what you told me...
Code:
public class Form1 : System.Windows.Forms.Form
{
private System.Drawing.Rectangle rec=new Rectangle(0,0,this.Width,this.Height);
public LinearGradientBrush gradbr = new LinearGradientBrush(rec,Color.Red,Color.Blue,10,true);
/// <summary>
/// Required designer variable.
/// </summary>
but,then,this what VS is showing me 
Code:
C:\Documents and Settings\Godwin\My Documents\Visual Studio Projects\testingsharp\Form1.cs(16): Keyword this is not available in the current context
Code:
C:\Documents and Settings\Godwin\My Documents\Visual Studio Projects\testingsharp\Form1.cs(17): A field initializer cannot reference the nonstatic field, method, or property 'testingsharp.Form1.rec'
(
Godwin
Help someone else with what someone helped you! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|