Results 1 to 8 of 8

Thread: A small error...

  1. #1

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    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:
    1. 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!

  2. #2

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    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!

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  4. #4

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    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!

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  6. #6

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: A small error...

    Ah,got it
    Ok Mr.Polite,Ill try the same using a timer and tell you how it is ...Im beginning to like c# too as Im going ahead working on it...Its not all that bad
    Godwin

    Help someone else with what someone helped you!

  7. #7

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    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!

  8. #8

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    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
  •  



Click Here to Expand Forum to Full Width