很多程序中左上角最常见的“打开”菜单怎么来实现?
要求点击后弹出一个窗口,可以对电脑中的文件进行浏览选中。也就是大部分程序点击“打开”按钮所实现的功能。
要求点击后弹出一个窗口,可以对电脑中的文件进行浏览选中。也就是大部分程序点击“打开”按钮所实现的功能。
解决方案 »
- 这个什么原因啊
- 跪求一大师指点,Access数据导入复杂Excel模板
- 怎么VSPrinter控件没有打印设置按钮呢?
- EXCEL获得动态集CopyFromRecordset方法,是不是只有ADO和DAO支持啊?oracle的0040(oradyset)可以实现吗?
- 倾尽最后80分:在局域网的客户端,如何访问局域网的服务器上的注册表信息 ??
- 前辈多指教:新手的几个简单问题集(1)
- 怎样取得一个对象的所有属性的列表。
- 如何作一个这样的特殊格式报表,只要解决200分相送
- 怎样得到SendMessage后的结果?
- 请问句柄(handle)是什么意思?
- 同过通讯控件mscomm是否可以做到发送一个字节以后几十毫秒发送下一个字节
- 自己编的软件出现了问题 、、无法解决,,求帮助
2.在菜单所在的窗体上加一个commondialog控件
3.在菜单"打开"的点击事件写commondialog.showopen
'在设计时按 ctrl+ t 键, 勾选 microsoft Common Dialog control (sp3) 确定 ,向窗体添加
'一个commondialong控件
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub open_Click()
CommonDialog1.ShowOpen
'ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件、打开一个目录、打印一个文件等等),并对外部程序有一定的控制。
ShellExecute 0, "open", CommonDialog1.FileName, "", "", 5
End Sub
On Error Goto cuowu '设置错误处理
Commondialog1.Filter = "*.*|*.*" '这里是文件过滤器
Commondialog1.CancelError = True
Commondialog1.ShowOpen
Shell Commondialog1.FileName '这里可以处理选中的文件
cuowu: '错误处理
If Err.Number = 32755 then '设置错误码过滤
Msgbox "不能选择取消!",,"打开菜单项"
Exit Sub
End If
Dim a as String
a = Msgbox ("出现错误!错误码为:" & Err.Number & chr(13) & chr(10) & "要保存错误记录吗?",vbyesno,"错误")
Select Case a
Case vbyes
Open App.Path & "\Error.log" for append as #1
print #1,Err.Number
Close #1
End Select
End Sub
[code=VB]
Private Sub Open_Click()
On Error Goto cuowu '设置错误处理
Commondialog1.Filter = "*.*|*.*" '这里是文件过滤器
Commondialog1.CancelError = True
Commondialog1.ShowOpen
Shell Commondialog1.FileName '这里可以处理选中的文件
cuowu: '错误处理
If Err.Number = 32755 then '设置错误码过滤
Msgbox "不能选择取消!",,"打开菜单项"
Exit Sub
End If
Dim a as String
a = Msgbox ("出现错误!错误码为:" & Err.Number & chr(13) & chr(10) & "要保存错误记录吗?",vbyesno,"错误")
Select Case a
Case vbyes
Open App.Path & "\Error.log" for append as #1
print #1,Err.Number
Close #1
End Select
End Sub[/code]
Dim openFileDlg As New OpenFileDialog()
openFileDlg.DefaultExt = "*.txt"
openFileDlg.Filter = "RTF文档(*.rtf)|*.rtf|文本文档(*.txt)|*.txt|所有文件(*.*)|*.*"
openFileDlg.ShowReadOnly = True Dim filename As String = Nothing
If openFileDlg.ShowDialog() = Windows.Forms.DialogResult.OK And (openFileDlg.FileName.Length) > 0 Then
filename = openFileDlg.FileName
NewNToolStripMenuItem_Click(sender, e)
CntChildForm -= 1
Dim activeChild As ChildForm = Me.ActiveMdiChild
If (Not activeChild Is Nothing) Then
Dim fileExt As String = Nothing
If filename.Trim <> String.Empty Then
activeChild.RichTextBox1.ResetText()
fileExt = System.IO.Path.GetExtension(filename).ToUpper
If fileExt = ".RTF" Then
activeChild.RichTextBox1.LoadFile(filename, RichTextBoxStreamType.RichText)
Else
activeChild.RichTextBox1.LoadFile(filename, RichTextBoxStreamType.PlainText)
End If
activeChild.Name = filename
activeChild.Text = filename
End If
End If End If
End Sub