怎么点击一下按钮,然后弹出一个文件选择框? 怎么弄,设计,写代码都可以,只能实现就行了!万分感谢!

解决方案 »

  1.   


            private void btnOpenFile_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.DefaultExt = "jpg";
                ofd.Filter = "Jpg文件(*.jpg)|*.jpg|Bmp文件(*.bmp)|*.bmp|Gif文件(*.gif)|*.gif";
                ofd.Title = "选择背景图片";
                ofd.Multiselect = false;
                ofd.ShowDialog();            if (ofd.FileName.Trim() != string.Empty)
                {
                    try
                    {
                        pnlBgImage.BackgroundImage = Image.FromFile(ofd.FileName.Trim());
                        tbBackgroundFile.Text = ofd.FileName.Trim();
                    }
                    catch
                    {
                        MessageBox.Show("装入图像文件失败,请检查文件格式是否正确或文件是否已经损坏。", "程序出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
      

  2.   

    //这是打开文件的对话框:
    private void button1_Click(object sender, EventArgs e)
            {            string Fname;
                openFileDialog1.FileName = null;
                openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.Title = "打开文件";
                openFileDialog1.InitialDirectory = Application.StartupPath;
                openFileDialog1.RestoreDirectory = true;
                openFileDialog1.ShowDialog();
                Fname = openFileDialog1.FileName;
                if (Fname != "")
                    if (openFileDialog1.FilterIndex == 1)
                    {
                        rtbdisplay.LoadFile(Fname, RichTextBoxStreamType.PlainText);
                        if (rtbdisplay.Text.Length == 0)
                            MessageBox.Show("嵌入的文本为空,请重新嵌入", "提示对话框");
                    }
              }
    //若只是打开一个提示对话框,则用MessageBox.Show();函数就可以,里面有很多种重载函数,给你举一个例子:MessageBox.Show("嵌入的文本为空,请重新嵌入", "提示对话框");
      

  3.   

    给按钮加上OnClientClick="return confirm('确定记录cookie吗?')" 然后在OnClick事件里写cookie值 
    ------------------ 当点按钮时,自动弹出"确定取消"对话框,当点确定时就执行Button1_Click事件.可以把改写cookie值<asp:Button ID="Button1" runat="server" Text="保存" OnClick="Button1_Click" OnClientClick="return confirm('确定记录cookie吗?')" />放在Button1_Click事件里;我js不是很熟,用js也是可以写cookie的. 
    ------ 可以在客户端事件里使用"__doPostBack('Button1','')"调用button1的服务器端事件 <asp:Button ID="Button2" Text="保存" OnClick="__doPostBack('Button1','')" /> 
    用js触发Button2的单机事件就执行了服务器端控件Button1的单击事件.
      

  4.   

    private void button3_Click(object sender, EventArgs e)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string result = this.OutToExcel(saveFileDialog1.FileName, this.dataGridView1); //this.dataGridView1:DataGridView控件
                    MessageBox.Show(result.ToString());
                }
                else
                {
                    MessageBox.Show("NO Saved!");                
                }
            }