先说问题,程序每次运行,要调用最后那3个函数的时候就会出错,错误实例:
求教怎么解决?
这是Winform的全部代码:using System;
using System.Windows.Forms;namespace 自定义最大小化和关闭按钮
{
    public partial class frm_Main : Form
    {
        public frm_Main()
        {
            InitializeComponent();
        }        private void frm_Main_Load(object sender, EventArgs e)
        {
            this.Width = Properties.Resources.登录界面标题.Width;
            this.Height = Properties.Resources.登录界面标题.Height + Properties.Resources.登录界面下面.Height;            panel_Title.BackgroundImage = Properties.Resources.登录界面标题;
            panel_All.BackgroundImage = Properties.Resources.登录界面下面;            pictureBox_Min.Image = null;//清空PictureBox控件
            pictureBox_Min.Image = Properties.Resources.最小化按钮;
            pictureBox_Max.Image = null;
            pictureBox_Max.Image = Properties.Resources.最大化按钮;
            pictureBox_Close.Image = null;
            pictureBox_Close.Image = Properties.Resources.关闭按钮;
        }        //自定义方法ImageSwitch主要是在鼠标移入和移出控件时对图片进行切换
        #region 控制图片的切换状态        public static PictureBox Tem_PictB = new PictureBox();//创建PictureBox控件
        /// <summary>
        /// 控制图片的切换状态
        /// </summary>
        /// <param name="sender">要改变图片的对象</param>
        /// <param name="n">控件标识</param>
        /// <param name="ns">鼠标移入移出标识</param>
        public void ImageSwitch(object sender, int n, int ns)
        {
            Tem_PictB = (PictureBox)sender;//获取当前控件
            switch (n)
            {
                case 0://最小化按钮时
                    {
                        Tem_PictB.Image = null;//清空当前图片
                        if (ns == 0)//鼠标移入
                            Tem_PictB.Image = Properties.Resources.最小化变色;
                        if(ns == 1)//鼠标移出
                            Tem_PictB.Image = Properties.Resources.最小化按钮;
                        break;
                    }
                case 1://最大化按钮时
                    {
                        Tem_PictB.Image = null;//清空当前图片
                        if (ns == 0)//鼠标移入
                            Tem_PictB.Image = Properties.Resources.最大化变色;
                        if (ns == 1)//鼠标移出
                            Tem_PictB.Image = Properties.Resources.最大化按钮;
                        break;
                    }
                case 2://关闭按钮时
                    {
                        Tem_PictB.Image = null;//清空当前图片
                        if (ns == 0)
                            Tem_PictB.Image = Properties.Resources.关闭变色;
                        if (ns == 1)
                            Tem_PictB.Image = Properties.Resources.关闭按钮;
                        break;
                    }
            }
        #endregion
        }        #region 设置窗体的最大化、最小化和关闭按钮的单击事件
        public void FrmClickMeans(Form frm_Tem, int n)
        {
            switch (n)
            {
                case 0://窗体最小化
                    frm_Tem.WindowState = FormWindowState.Minimized;
                    break;                case 1://窗体最大化和还原
                    if (frm_Tem.WindowState == FormWindowState.Maximized)
                        frm_Tem.WindowState = FormWindowState.Normal;
                    else
                        frm_Tem.WindowState = FormWindowState.Maximized;
                    break;                case 2://关闭窗体
                    frm_Tem.Close();
                    break;
            }
        }
        #endregion        private void pictureBox_Close_Click(object sender, EventArgs e)
        {
            FrmClickMeans(this, Convert.ToInt16(((PictureBox)sender).Tag.ToString()));
        }        private void pictureBox_Close_MouseEnter(object sender, EventArgs e)
        {
            try { ImageSwitch(sender, Convert.ToInt16(((PictureBox)sender).Tag.ToString()), 0); }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
            
        }        private void pictureBox_Close_MouseLeave(object sender, EventArgs e)
        {
            try { ImageSwitch(sender, Convert.ToInt16(((PictureBox)sender).Tag.ToString()), 1); }
            catch { }
            
        }    }
}winformexception对象