RT

解决方案 »

  1.   

    先谢谢不过能说具体点么
    using System;
    using System.IO;
    using System.Windows.Forms;namespace WindowsApplication4
    {
        public partial class login : Form
        {
            public string path,usr,pw,FILE_NAME,folder="";
            public int i;
            public login()
            {
                InitializeComponent();
            }        private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {
                ipaddr.Enabled = true;
                usertext.Enabled = true;
                pwtext.Enabled = true;
            }        private void radioButton1_CheckedChanged(object sender, EventArgs e)
            {
                ipaddr.Enabled = false;
                usertext.Enabled = false;
                pwtext.Enabled = false;
                ipaddr.Text = "";
                usertext.Text = "";
                pwtext.Text = "";
            }        private void loginc_Click(object sender, EventArgs e)
            {
                if (radioButton1.Checked == true)
                {
                    i = 0;
                    path = "c:\\";
                    FILE_NAME = path + "temp.vbs";
                    create_vbs a = new create_vbs();
                    a.pw = pw;
                    a.path = path;
                    a.ij = i;
                    a.FILE_NAME = FILE_NAME;
                    a.folder = folder;
                    Visible = false;
                    a.Show();
                }
                else if (radioButton2.Checked == true)
                {
                    i = 1;
                    path = "\\\\"+ipaddr.Text;
                    usr = usertext.Text;
                    pw = pwtext.Text;
                    folder = "\\netlogon\\";
                    if (ipaddr.Text == "" || usertext.Text == "" || pwtext.Text == "")
                    {
                        MessageBox.Show("不能填入空值!");
                    }
                    else
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("net", " use " + path + " " + pw + " /user:" + usr);
                            FILE_NAME = path + "" + folder + "temp.vbs";
                            StreamWriter sr;
                            sr = File.CreateText(FILE_NAME);
                            sr.Close();
                            create_vbs b = new create_vbs();
                            b.pw = pw;
                            b.path = path;
                            b.ij = i;
                            b.FILE_NAME = FILE_NAME;
                            b.folder = folder;
                            Visible=false;
                            b.Show();
                        }
                                            catch (DirectoryNotFoundException)
                        {
                            MessageBox.Show("找不到文件夹"+folder);
                        }
                        catch (IOException)
                        {
                            MessageBox.Show("找不到网络路径" + path+"或用户名与密码错误");
                        }
                    }
                }
            }        private void quit_Click(object sender, EventArgs e)
            {
                this.Close();
                Application.Exit();
                
            }
        }
    }
    找不到啊
      

  2.   

    在设计器界面上点击窗体,右键->属性->事件->FormClosing
      

  3.   


    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {  DialogResult diaresult = MessageBox.Show("确认退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
      if (diaresult != DialogResult.Yes)
      {
         e.Cancel = true;
      }
               
    }
      

  4.   

    这个问题不用添加事件处理,面是是采用重写基类方法就可以了,可以把如下的代码直接粘到窗体的代码里:protected override void OnFormClosing(FormClosingEventArgs e)
    {
    if (MessageBox.Show(this, "确定要关闭吗", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
    {
    e.Cancel = true;
    }
    }
      

  5.   

    首先,你要确保你的FormClosing事件正常,然后入如果你想阻止关闭窗体的话,在事件体中加入如下语句即可e.Cancel = true;
      

  6.   

    太感谢了
    不过为什么出是否退出的提示出3次呢过程是这样,LOGIN窗体-点确定-LOGIN隐藏(HIDE)-FORM2显示(SHOW)-FORM关闭-FORM1显示-这时按红叉已经不起作用了,用了hbxtlhx  的方法,自行在里面加入  application.exit();退出成功,不过提示按确定要出3次不解 
      

  7.   

    Form.Hide他会执行Closing事件跟踪一下就知道了~~~~不知道你到底想干什么~~~~
      

  8.   

    在Closing中有个CloseReason
    可以利用一下~~~~