日期:2014-05-18 浏览次数:21175 次
OpenFileDialog dlg; = new OpenFileDialog(); dlg.FileName = "图片"; dlg.DefaultExt = "*.*"; dlg.Filter = "全部文件(.*)|*.*|bmp文件(.bmp)|*.bmp|jpg文件(.jpg)|*.jpg|gif文件(.gif)|*.gif|png文件(.png)|*.png|ico文件(.ico)|*.ico"; Nullable<bool> result = dlg.ShowDialog(); if (result == true) { filePath.Text = "图片路径:" + dlg.FileName; sort.IsEnabled = true; }
------解决方案--------------------
一样操作
WPF 控件
按钮:Button 和 RepeatButton。
对话框:OpenFileDialog、PrintDialog 和 SaveFileDialog。
参考
------解决方案--------------------
这是我最近做的,传输文件的时候,先打开窗口
private void btnSendFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { txtMessage.Text = ofd.FileName; fullfilename = ofd.FileName; filename = fullfilename.Substring(fullfilename.LastIndexOf("\\") + 1); FileStream filestreamlength = new FileStream(fullfilename, FileMode.Open, FileAccess.Read); string sendMessageFile = "receivefile|" + filename + "|" + filestreamlength.Length.ToString() + "|"; byte[] byteFile=new byte[1024]; byteFile = Encoding.Unicode.GetBytes(sendMessageFile); clientSocket.BeginSendTo(byteFile, 0, byteFile.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null); filestreamlength.Close(); txtMessage.Text = string.Empty; } }
------解决方案--------------------
项目中选择"引用"
找到:system.windows.forms即可.