Windows forms c#

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
mattykins
Posts: 203
Joined: Sun Jan 15, 2012 10:15 pm

Windows forms c#

Post by mattykins »

Sorry I'm making so many support topics lateley I'm just running into a lot of problems

So basically I have a picturebox thats the players image. And I have a class that contains there X and Y values which looks like this:

Code: Select all

class PlayerXY
    {
        static private int x = 50;
        static private int y = 50;

        static public int X
        {
            get { return x; }
            set { x = value; }
        }

        static public int Y
        {
            get { return y; }
            set { y = value; }
        }

        
    }
And then I set the location of the player Picture box to

Code: Select all

Player.Location = new Point(PlayerXY.X, PlayerXY.Y);
This was all an attempt to make it so I could edit PlayerXY.X or Y from a playerMovement class.

For example when the player pressed W It would call playerMovement.Up, which looks like

Code: Select all

static public void Up()
        {
            PlayerXY.Y += 50;
            Player.Location = new Point(PlayerXY.X, PlayerXY.Y);
        }
However this gives me an error saying that "Dungeon_Raid.Player does not contain a definition for Location"

I'm pretty sure this is something with windows forms but idk.

Sorry if this is a huge post but I didn't want to under-inform you guys :)

Oh also this is for the RogueLike game that i'm making.

Thanks!
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Windows forms c#

Post by Jackolantern »

I have never had a reason to move around an object in that way in Windows Forms, but to anyone who remembers, didn't Halls make a small .NET game called ASCII Wars that had movement in a Forms project? However, when I search "ASCII Wars", all that comes up is a web project, so I am thinking maybe he called the .NET desktop app something else.

EDIT: Found it! The link to this thread is here. However, I don't know if that link is just an executable or the source code is included. If it isn't included, I bet Halls still has it and would be fine with sharing it with you! He had characters moving around in what I believe was a Forms project.
The indelible lord of tl;dr
User avatar
mattykins
Posts: 203
Joined: Sun Jan 15, 2012 10:15 pm

Re: Windows forms c#

Post by mattykins »

I saw that topic and made a recent post asking him a question. it was called ASCII fun. Also could you please look at the support topic that I had below this one, i'm still confused about it :)
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Windows forms c#

Post by Xaleph »

Im going to bet it has something to do with misusing some words or omitting a type. In your Player object you omitted to define the Location as a Point object or Location is reserved by .NET.

Code: Select all

class Player {

    public Point Location = null;
  
    // the rest

}
I cannot think of something else to be honest. Then again, its late. Did you declare Location at the Player class or is Location/Point a reserved keyword? Try looking in to that.
User avatar
mattykins
Posts: 203
Joined: Sun Jan 15, 2012 10:15 pm

Re: Windows forms c#

Post by mattykins »

In windows forms almost everything has a .Location. For example if I wanted to change the location of a button to 100, 100 when I click it I would use

Code: Select all

Button.Location = new Point(100, 100);
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Windows forms c#

Post by Xaleph »

Then does Location accept a Point object? Should it not be a Location object? Or is a Point object an inheriting class of the parent Location class? Maybe you should declare your "location" as a point object, or better yet, use the real name for these things. A point ( X and Y ) is nothing but a Vector. Use that as a name.

Vector2 position = new Vector(X, Y);
Post Reply

Return to “Beginner Help and Support”