Jump to content

C# Buttons

- - - - -

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

#1
Darkco

Darkco

    Newbie

  • Members
  • PipPip
  • 13 posts
Heya,

So im working currently on a blackjack application.
My application have 5 buttons:

Start
Hit me (Give new card to player)
Stand (Stop giving new cards and let computer play)
Reset
Exit

Now the I have a problem with the first 2 buttons:

I want the start button to be clicked only once (otherwise you can click as many times as you want to get good cards) how do you set a click limit on the button.

The next problem with the HitMe button:

Im using pictureboxes for the cards which got different names of course.
So the first time you click the picturebox name must be Player_Card3 second time Player_Card4 and so on...

Here a little part of my code you might need to help me :rolleyes:



Random start = new Random(); //RANDOM NUMBER

Bitmap myStartCard;


 private void Hit_btn_Click(object sender, EventArgs e)

{//START HITMEBUTTON

            

int x = start.Next(0, 13);

if (x == 0)

{

myStartCard = new Bitmap(ace);

}


[U][B]Player_Card1.Image = myStartCard;[/B][/U]

           

}//END HITMEBUTTON


So as you can see the bold underlined line needs to change its digit every time you click the hitme button

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Two ideas come to mind:
1) use the IsEnabled property to disable the button when you don't want it to be pushed.
2) use a boolean variable to keep track of whether it is legal to "Start" at this time.

Button Properties (System.Windows.Controls)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Darkco

Darkco

    Newbie

  • Members
  • PipPip
  • 13 posts
Hey thanks WP made me come up with this little code:
{ // BUTTON START

{
My code
}
start.btn.Enabled = false;
} // BUTTON END 

Which worked like a charm so thanks for ur help ^^

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
No problem. I do the same thing a lot with some of my programs to avoid restarts in mid-process.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts

Darkco said:

Hey thanks WP made me come up with this little code:

{ // BUTTON START


{

My code

}

start.btn.Enabled = false;

} // BUTTON END 

Which worked like a charm so thanks for ur help ^^

Just don't forget to Re enable it when they're allowed to restart.

#6
Darkco

Darkco

    Newbie

  • Members
  • PipPip
  • 13 posts
Yup I did the opposite of it in the reset button so it will enable itself when it resets.

Still trying to figure out the Hit Me button though...
Seems like it wont allow me to use a variable and a function call in 1 line. for example myString + myInt; works fine but when I try myNewCard = myString + myInt;
myNewCard.Image = Player_Card2

Wont work because it is a string :(

Iv included a little screenshot.

PS: for the first 2 cards I use Player_Card1.Image = myStartCard; which work like a charm but as you can see this only works for picture box Player_Card1

Attached Files


Edited by Darkco, 30 December 2009 - 01:02 PM.


#7
Darkco

Darkco

    Newbie

  • Members
  • PipPip
  • 13 posts
Well I just fixed the HitMe button problem :thumbup1:
Just made a int variable and in the click block it counts every time +1.
And then a simple if statement which looks to what image box it need to be sended. Im sure there is a better way and im always intressed learning it so if you got a idea how to do it better just write a reply ^^