c#中如何封装一个方法?

我想封装一个方法简便一下代码,大概内容是鼠标移动到按钮会在Image中加上图片以,如果按钮是已经点击过的,鼠标移动过去不会发变改mIage状态。
private static bool picregisterFlag;
private static bool picuserAdministrationFlag;
private void pictureBox1_Click_1(object sender, EventArgs e)
( {
this.tabControl1.SelectedIndex = 0;

        picregisterFlag=true;**
       picuserAdministrationFlag = false;

        picregister.BackgroundImage = Resources.用户注册选中;
      picuserAdministration.BackgroundImage = Resources.用户管理;
对这部分进行封装一个方法)

    }
    private void pictureBox2_Click(object sender, EventArgs e)
    {
        this.tabControl1.SelectedIndex = 1;

        picregisterFlag = false;
        picuserAdministrationFlag = true;

        picregister.BackgroundImage = Resources.用户注册;
        picuserAdministration.BackgroundImage = Resources.用户管理选中;
    }

                    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        if (picregisterFlag == true) { picregister.Image = null; }
        else { picregister.Image = Resources.导航鼠标经过; }
    }

                    private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
    {
        if (picuserAdministrationFlag == true) { picuserAdministration.Image = null; }
        else { picuserAdministration.Image = Resources.导航鼠标经过; }
    }
查看全部
qq_38872713
qq_38872713
2018/11/26 09:05
  • c#
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复