Click here to Skip to main content
15,904,339 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using System.Web in C# Pin
28-May-03 5:24
suss28-May-03 5:24 
QuestionIs this possible? Pin
Manster28-May-03 3:48
Manster28-May-03 3:48 
AnswerRe: Is this possible? Pin
Nick Parker28-May-03 4:34
protectorNick Parker28-May-03 4:34 
GeneralIssues Consuming Webservice From WinForm App Pin
Ach1lles28-May-03 3:05
Ach1lles28-May-03 3:05 
GeneralCrystal Reports and .net Pin
Braulio Dez28-May-03 1:15
Braulio Dez28-May-03 1:15 
GeneralRe: Crystal Reports and .net Pin
Rocky Moore28-May-03 3:28
Rocky Moore28-May-03 3:28 
GeneralRe: Crystal Reports and .net Pin
Braulio Dez28-May-03 3:44
Braulio Dez28-May-03 3:44 
GeneralC# graphics help required urgent. Pin
Hayat28-May-03 0:48
Hayat28-May-03 0:48 
I have created a simple animation in c# in which a ellipse moves.I want to create more than one objects of that class contaning OnPaint() method.I have done my best to do that .But nothing work for me.I want that the should be more than one object of my gamecontrol class drawn simultanously on the form.

The code is right here.

using System;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace mygame

{

///

/// Summary description for Form1.

///


public class Form1 : System.Windows.Forms.Form

{

protected System.Windows.Forms.Timer timer1;

private System.ComponentModel.IContainer components;

private mygame.display gcontrol;

public int x,y;





public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//for double buffering



this.BackColor = Color.Black ;









//

// TODO: Add any constructor code after InitializeComponent call

//

}



///

/// Clean up any resources being used.

///


protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///


private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

this.timer1 = new System.Windows.Forms.Timer(this.components);

//

// timer1

//

this.timer1.Enabled = true;

this.timer1.Interval = 40;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Name = "Form1";

this.Text = "Form1";



}

#endregion





}

public class gamecontrol :Form1

{



public System.Windows.Forms.Timer Timer;

private bool widthgreater,heightgreater;

private System.Windows.Forms.Timer mytimer;



public gamecontrol()

{

}





public gamecontrol(int a,int b)

{

x=a;

y=b;

mytimer = this.timer1 ;

mytimer.Tick += new System.EventHandler (game_Tick);

this.Text = " Hello from constructro";



}

public void game_Tick(object sender, System.EventArgs e)

{

this.Refresh();

update();



this.Text = DateTime.Now.ToString();

}





protected override void OnPaint(PaintEventArgs pe)

{

Graphics g = pe.Graphics ;

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias ;

Pen pen = new Pen(Color.Blue,10);







g.FillEllipse(Brushes.BlueViolet,x,y,20,20);





base.OnPaint(pe);

}





public void update()

{



if(widthgreater)

{

x-=2;

if(x==0)

{

widthgreater=false;



}

}

else

{

x +=2;

if(x >= this.ClientRectangle.Width-20 )

{

widthgreater=true;

}



}

////////////////////////////////////////////////

///for y

if(heightgreater)

{

y -=2;

if(y<=0)

heightgreater=false;

}

else

{

y +=2;

if(y>=this.ClientRectangle.Height -20 )

heightgreater=true;



}



}





}

public class display

{

private mygame.gamecontrol ball;



public display()

{

ball = new gamecontrol(200,44);





}

///

/// The main entry point for the application.

///


[STAThread]

static void Main(string [] abc)

{



Application.Run(new gamecontrol(33,44));





}





}

}


Any help .
Thanks in advance.Blush | :O
GeneralRe: C# graphics help required urgent. Pin
Hayat30-May-03 0:23
Hayat30-May-03 0:23 
GeneralRe: C# graphics help required urgent. Pin
Hayat30-May-03 0:29
Hayat30-May-03 0:29 
GeneralUpdating data programmatically Pin
totig27-May-03 23:28
totig27-May-03 23:28 
GeneralRe: Updating data programmatically Pin
jtmtv1828-May-03 0:44
jtmtv1828-May-03 0:44 
GeneralRe: Updating data programmatically Pin
totig28-May-03 2:51
totig28-May-03 2:51 
GeneralRe: Updating data programmatically Pin
Rocky Moore28-May-03 3:38
Rocky Moore28-May-03 3:38 
GeneralRe: Updating data programmatically Pin
totig28-May-03 5:16
totig28-May-03 5:16 
GeneralRe: Updating data programmatically Pin
jtmtv1828-May-03 11:20
jtmtv1828-May-03 11:20 
GeneralXML Loading Problem Pin
Nick Parker27-May-03 17:10
protectorNick Parker27-May-03 17:10 
GeneralRe: XML Loading Problem Pin
J. Dunlap27-May-03 20:21
J. Dunlap27-May-03 20:21 
GeneralRe: XML Loading Problem Pin
Nick Parker28-May-03 1:43
protectorNick Parker28-May-03 1:43 
GeneralGrabbing Text Input with C# / .net Pin
dratti27-May-03 12:41
dratti27-May-03 12:41 
GeneralInstantiate .NET type within web page (like ActiveX) Pin
Michal Januszczyk27-May-03 10:15
sussMichal Januszczyk27-May-03 10:15 
GeneralRe: Instantiate .NET type within web page (like ActiveX) Pin
Vasudevan Deepak Kumar27-May-03 19:52
Vasudevan Deepak Kumar27-May-03 19:52 
GeneralRe: Instantiate .NET type within web page (like ActiveX) Pin
Ed K30-May-03 3:49
Ed K30-May-03 3:49 
GeneralGood Enum Question Pin
Ed K27-May-03 9:26
Ed K27-May-03 9:26 
GeneralRe: Good Enum Question Pin
Eric Gunnerson (msft)27-May-03 11:29
Eric Gunnerson (msft)27-May-03 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.