C#帮助,我是C#的初学者,需要一些编程方面的帮助

时间:2015-07-30 05:20:56

标签: c# image button combobox

我已经多次尝试过但我失败了。有2艘大型游艇可供出租,但当用户选择第一艘大型游艇时,按钮(图片)将变为黑色,并且会有一个组合框列出那里的“Big Yacht 1 Booked”。然而,当我继续点击bigyachtbutton是“bigyacht1”时,“Big Yacht 1 Booked”文本不断发送垃圾邮件,我需要为bigyacht2做同样的事情。只需单击Return按钮即可返回(从组合框中删除)。请在这里需要一些帮助!!!!我需要为我的游艇租赁提供退货系统,但我不确定我的编码是否正确。[![下图是我为游艇租赁系统所做的编程。选择游艇后,图像将变为黑色,带图像的按钮本身只能工作一次。我希望它与其他游艇按钮一样工作] [1]] [1]请帮助

private void bigyacht1_Click(object sender, EventArgs e)
{
    if (bigyacht1.CanSelect)
    {
        bigyacht1.BackgroundImage = Properties.Resources.big_yacht_BLACK;
        bigyachtcomboBox.Items.Add(bigyachtcomboBox.Text = "Big Yacht 1 Booked");

    }
    else
    {
        bigyachtreturnButton.Select();
        bigyachtcomboBox.Text = "";
        bigyacht1.BackgroundImage = Properties.Resources.aluminum_mega_yacht_semi_displacement_hull_21287_6323513;

    }
    bigyacht1.BackgroundImage = Properties.Resources.aluminum_mega_yacht_semi_displacement_hull_21287_6323513;


}

private void bigyachtreturnButton_Click(object sender, EventArgs e)
{
    bigyachtcomboBox.SelectedIndex = -1;

}

1 个答案:

答案 0 :(得分:0)

您可以在第一次单击按钮时设置bool标志,并在再次执行此部分代码之前检查该标志:

类变量:

private bool yacht1booked = false;
点击方法中的

if (bigyacht1.CanSelect)
{
    if (!yacht1booked)
    {
        bigyacht1.BackgroundImage = Properties.Resources.big_yacht_BLACK;
        bigyachtcomboBox.Items.Add(bigyachtcomboBox.Text = "Big Yacht 1 Booked");
        yacht1booked = true;
    }
}