C#private修饰符在此项目上不可用

时间:2017-11-06 19:04:21

标签: c#

我一直在最后一部分收到错误消息,其中private void ExitBtn以及CovertTxtBox说“修饰符私有对此项目无效”。

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ConvertBtn_Click(object sender, EventArgs e)
        {
            string the1;
            string the2;
            int num = int.Parse(ConvertTxtBox.Text);
            int Number1;

            if (FromListBox.SelectedIndex != -1)
            {
                the1 = FromListBox.SelectedItem.ToString();

                if (ToListBox.SelectedIndex != -1)
                {
                    the2 = ToListBox.SelectedItem.ToString();

                    if (the1 == the2)
                    {
                        OutputLbl.Text = num.ToString();
                    }
                    else if (the1 == "Inches" && the2 == "Feet")
                    {
                        Number1 = num / 12;
                        OutputLbl.Text = Number1.ToString();
                    }
                    else if (the1 == "Inches" && the2 == "Yards")
                    {
                        Number1 = num / 36;
                        OutputLbl.Text = Number1.ToString();
                    }
                    else if (the1 == "Feet" && the2 == "Inches")
                    {
                        Number1 = num * 12;
                        OutputLbl.Text = Number1.ToString();
                    }
                    else if (the1 == "Feet" && the2 == "Yards")
                    {
                        Number1 = num / 3;
                        OutputLbl.Text = Number1.ToString();
                    }
                    else if (the1 == "Yards" && the2 == "Inches")
                    {
                        Number1 = num * 36;
                        OutputLbl.Text = Number1.ToString();
                    }
                    else if (the1 == "Yards" && the2 == "Feet")
                    {
                        Number1 = num * 3;
                        OutputLbl.Text = Number1.ToString();
                    }
                }
                else
                {
                    MessageBox.Show("Select a measurment from the 'to' list");
                }
            }
            private void ExitBtn_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            private void ConvertTxtBox_TextChanged(object sender, EventArgs e)
            {
            }
        }        
    }
}

1 个答案:

答案 0 :(得分:1)

您正试图在ConvertBtn_Click方法中声明这些方法。如果您剪切它们并将其粘贴到该方法的结束块之后,它应该可以正常工作:

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
   {
        public Form1()
        {
            InitializeComponent();
        }

        private void ConvertBtn_Click(object sender, EventArgs e)
        {
            // code here
        }

        private void ExitBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ConvertTxtBox_TextChanged(object sender, EventArgs e)
        {
        }
    }
}