怎么点击一下按钮,然后弹出一个文件选择框? 怎么弄,设计,写代码都可以,只能实现就行了!万分感谢!
解决方案 »
- 求助解决:配置有 NoSecurityChanges 标志的 AppDomainManager 修改了 AppDomain 的安全状态。
- 高手们,快点,求救啊....
- C#如何执行这条SQL语句str,以实现恢复数据库:str = @"RESTORE DATABASE tDB ......
- richTextBox保存txt文件
- 急了``
- 求下载功能代码
- 一个窗体上有无数个button,不确定有多少个.点每个button,在第二次点击鼠标就不运行下面的代码。
- AutoScrollPosition的问题,高手们快来帮忙啊!!!!!!!!!!!!!!!!!!!!!
- 自定义ComboBox控件
- 请问如何使用C#将Excel文件导入数据库中
- datalist分页遇到一个问题?
- 关于matlab转换数据的问题!
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);
}
}
}
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("嵌入的文本为空,请重新嵌入", "提示对话框");
------------------ 当点按钮时,自动弹出"确定取消"对话框,当点确定时就执行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的单击事件.
{
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!");
}
}