Okay, so I haven't done any programming in years, and yesterday I decided to learn some stuff about C#. I tried to write a program to, just for starters, get a little circle to move around the screen.(Please keep in mind that I haven't taken any classes, I haven't read any books, so this code is probably super hideous. Don't judge me.)The Planet object is drawing every cycle, but it the actual circle is moving on screen. It's x and y positions are updating properly, and I have the actual numbers being drawn to the screen. In debugging I have checked, and the actual rectangle used to draw the circle is being updated along with the Planet object's changes. Still, the circle that I see on screen remains stationary. Any suggestions? Here's part of the code:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace tehgraphhhixzss{ public partial class planets : Form { private System.Windows.Forms.Timer timer1; public planets() { InitializeComponent(); this.SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); } public class Planet { double mass, radius, x, y, dx, dy = 0; public Planet(double m, double r, double xpos, double ypos, double deltax, double deltay) { mass = m; radius = r; x = xpos; y = ypos; dx = deltax; dy = deltay; } public void Draw(System.Drawing.Graphics graphicsContext) { System.Drawing.Rectangle planetRect = new System.Drawing.Rectangle( (int)(x - radius), (int)(y - radius), (int)(radius), (int)(radius)); graphicsContext.DrawEllipse(System.Drawing.Pens.Blue, planetRect); } public void Update() { x += dx; y += dy; } public double getX() { return x; } public double getY() { return y; } } int timesDrawn = 0; Planet testPlanet = new Planet(10, 10, 100, 100, .5, .5); protected override void OnPaint(PaintEventArgs e) { testPlanet.Draw(e.Graphics); timesDrawn++; } private void timer1_Tick(object sender, System.EventArgs e) { testPlanet.Update(); label1.Text = "x: " + testPlanet.getX() + " y: " + testPlanet.getY(); } private void Form1_Load(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { label1.Text = label1.Text + "!"; } }}
4/14/2008 12:26:22 PM
I can post the rest of the project if needed.
4/14/2008 12:28:15 PM
Okay, just realized that if I go to another window (LIEK TEHWOLFWEBS) and go back it redraws and does so in the correct position. I guess OnPaint() isn't getting called normally. teh hax.
4/14/2008 12:37:25 PM
okay, I figured it out.MISSION ACCOMPLISHED. THREAD.INVALIDATE();
4/14/2008 12:41:38 PM
Feel free to tell me what's stupid about the rest of the code, though.
4/14/2008 12:49:45 PM
didn't want ya to feel lonely[Edited on April 14, 2008 at 12:56 PM. Reason : ]
4/14/2008 12:56:32 PM
lol @ namespace tehgraphhhixzsshahaha
4/14/2008 4:32:40 PM
grab the xna kit and have some 3d fun with c# kiddo
4/14/2008 4:33:41 PM
Also:
Planet[] planetArray = new Planet[5]; planetArray[0] = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue);
4/15/2008 2:00:52 PM
looks like you have too many parameters for planet
4/15/2008 2:50:38 PM
Sorry, the constructor is now this:
public Planet(double m, double r, double xpos, double ypos, double deltax, double deltay, System.Drawing.Brush pColor){ mass = m; radius = r; x = xpos; y = ypos; dx = deltax; dy = deltay; planetColor = pColor;}
Planet testPlanet = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue); Planet planet2 = new Planet(20, 50, 300, 300, 2, 3, System.Drawing.Brushes.BlanchedAlmond);
4/15/2008 3:11:12 PM
Anybody??
4/15/2008 9:26:38 PM
srsly, can anybody help me?
4/16/2008 9:18:10 AM
say Planet[0] = testPlanet;what errors do you get?[Edited on April 16, 2008 at 8:05 PM. Reason : ]
4/16/2008 8:00:57 PM
^ already figured it out in message_topic.aspx?topic=522795
4/16/2008 9:47:13 PM
oh...nice. thanks for the update.
4/17/2008 8:11:24 PM
Thanks a lot to everybody who helped.
4/17/2008 9:15:52 PM
GTIV ain't got shit on me, son.
5/9/2008 6:26:44 PM
if red x is your goal...
5/9/2008 7:33:25 PM
Let's try this with a little less fail this time:BOW BEFORE MY PROWESS.
5/10/2008 9:53:25 PM
In case anybody wants to see the type of leet shit I'm getting into these days:http://www.mediafire.com/?4mlrzmcnytnHD SUPER MARIO BROS WITH A RABBIT AND BEES AND SHIT WHAT WHAT
7/6/2008 11:59:32 AM
pedobear adventures?
7/6/2008 12:18:16 PM
Basically.
7/6/2008 12:32:41 PM