I have a project vending machine. C#/ WPF
But i can only click once on the button it needs to be clicked on till the value is the same as the cost
Example if the drink cost 2€
I can only click once on the button 1€
The 2€ button is not a problem cauze this value is the same and proceeds to the next step.
an image of the project http://img338.imageshack.us/img338/5613/softdrinkvend.jpg
Loading
Kirtan PatelPosted Dec 6, 2009, 8:18 AM
private void button1_Click(object sender, RoutedEventArgs e)
{
if (Convert.ToInt32(label1.Content) < Convert.ToInt32((button1.Content)))
{
// Do Somthing
}
else
{
//Disable the Button
button1.IsEnabled = false;
}
}
Kirtan PatelPosted Dec 6, 2009, 1:25 PM
Perfect Code for your Coin Application
--------------------------------------------
public partial class Window1 : Window
{
int total = 0;
public Window1()
{
InitializeComponent();
}
// 1 Euro Button code
private void button1_Click(object sender, RoutedEventArgs e)
{
if (total < Convert.ToInt32(lblPrice.Content))
{
total += 1;
label1.Content = total.ToString();
}
else
{
button1.IsEnabled = false;
}
}
// 2 Euro Button
private void button2_Click(object sender, RoutedEventArgs e)
{
if (total < Convert.ToInt32(lblPrice.Content))
{
total += 2;
label1.Content = total.ToString();
}
else
{
button2.IsEnabled = false;
}
}
// Code for 5 Euro Button
private void button3_Click(object sender, RoutedEventArgs e)
{
if (total < Convert.ToInt32(lblPrice.Content))
{
total += 5;
label1.Content = total.ToString();
}
else
{
button3.IsEnabled = false;
}
}
Fred StilmsPosted Dec 6, 2009, 10:31 AM
i did it a bit differnet but now its a click to late if the label4>= label5 you can still click one more time before it disables
doesnt raise the value 'do.
private void button10_Click(object sender, RoutedEventArgs e)
{
{
if (Convert.ToInt32(label4.Content) >= Convert.ToInt32((button6.Content)))
{
result += 5;
label5.Content = result;
}
else
{
button6.IsEnabled = false;
label6.Content = "Buy";
button12.IsEnabled = true;
}