Jump to content

Problem with GUI

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Alex_j

Alex_j

    Newbie

  • Members
  • PipPip
  • 29 posts
Hi, I'm wanting to pass a value from one method into another then to change the variable. I have:

public int getPosition()

        {

            return position += value;

        }


        public void resetPosition()

        {

            

            if (getPosition()>20)


            {

                position = 0;

state++


                

            }

        }


        public void btnRoll_Click(object sender, EventArgs e)

        {

            value = diceRoll.Throw();


            lblValue.Text = Convert.ToString(value);

            lblPosition.Text = Convert.ToString(getPosition());

            lblstate.Text = Convert.ToString(state);


        }

So basically I want it so when the value is equal to or greater than 20, to set the position to 0 and increment the state variable. then output them into a label.

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Will this work?(I haven't tested it
public int getPosition()
        {
            return position += value;
        }

        public void resetPosition()
        {
            int pos = getPosition();
            if (pos>20)

            {
                position = 0;
state++

                
            }
        }

        public void btnRoll_Click(object sender, EventArgs e)
        {
            value = diceRoll.Throw();
            int strPos = getPosition();
            lblValue.Text = Convert.ToString(value);
            lblPosition.Text = Convert.ToString(strPos);
            lblstate.Text = Convert.ToString(state);

        }
Or are you have some other problem?
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Alex_j

Alex_j

    Newbie

  • Members
  • PipPip
  • 29 posts
Nope, that's still not working, it's not changing the position value back to 0 or incrementing the state

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Of course not you never call the reset method try this:
public int getPosition()
        {
            return position += value;
        }

        public void resetPosition()
        {
            int pos = getPosition();
            if (pos>20)

            {
                position = 0;
state++

                
            }
        }

        public void btnRoll_Click(object sender, EventArgs e)
        {
            [COLOR=Red]resetPosition();[/COLOR]
            value = diceRoll.Throw();
            int strPos = getPosition();
            lblValue.Text = Convert.ToString(value);
            lblPosition.Text = Convert.ToString(strPos);
            lblstate.Text = Convert.ToString(state);

        }

A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
Alex_j

Alex_j

    Newbie

  • Members
  • PipPip
  • 29 posts
Works great Thanks a lot. Another question I have a form sort of like a main menu which takes the users name how can I take that value and pass it into my second form?

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

Quote

Works great Thanks a lot.
No prob. :)

Quote

Another question I have a form sort of like a main menu which takes the users name how can I take that value and pass it into my second form?
OK you can do this:
//Form 1
 public static string UserName = ""; //Put this with your other vaiables at the top.

//This goes in the button click to goto form2 in form1
 UserName = textBox1.Text;
            Form2 form = new Form2();
            form.ShowDialog();

//Form2
label1.Text = Form1.UserName;// add this in form2_load or where ever needed
That should do it. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#7
yoda174

yoda174

    Newbie

  • Members
  • PipPip
  • 25 posts
Lot of Thanx for the #7 post!:) I had been searching the mode of communication beetwen form's for long. Now i know how to make it,and works me fine:w00t:.

THANX

#8
kanta

kanta

    Newbie

  • Members
  • Pip
  • 1 posts
many many thanks to thegamemaker.
i was scratcing my head over it for quite some time.

_______________________
Car Racing Games
Practice Management Software