vb.net窗体嵌入 vb如何在窗体中添加命令按钮( 二 )


Private Const WM_SYSCOMMAND As Int32 = H112
Private Const SC_MAXIMIZE As Int32 = HF030
Private Const SC_MINIMIZE As Int32 = HF020
Private Const SC_RESTORE As Int32 = HF120
Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Int32, ByVal nCmdShow As Int32) As Int32
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShellExecute(Me.Panel1.Handle, "open", "c:\windows\system32\cmd.exe", Nothing, ".", SW_HIDE)
System.Threading.Thread.Sleep(50)
Dim h As IntPtr = FindWindow(Nothing, "c:\windows\system32\cmd.exe")
ShowWindow(h, SW_HIDE)
SetParent(h, Me.Panel1.Handle)'嵌到panel1内
SendMessage(h, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
把其中的c:\windows\system32\cmd.exe换成你要嵌入的应用程序
VB窗体下如何嵌入一个EXCEL表1.部件-添加-可插入对象--选择excel 表格就可以在窗体添加该表格控件
2.工程-引用-Microsoft Excel 11.0 Object Library
下面给个简单的例子
Private Sub Command1_Click()
Dim xlExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim AppExcel As Object
Set xlExcel = CreateObject("Excel.Application")
xlExcel.Workbooks.Open "C:\test.xls"
Set xlBook = xlExcel.Workbooks("test.xls")
Set xlSheet = xlBook.Worksheets(1)
Text1.Text = xlSheet.Cells(1, 1).Value
Text1.Text = Text1.Text"ADD"
xlSheet.Cells(1, 1).Value = https://www.04ip.com/post/Text1.Text
Application.DisplayAlerts = False
xlBook.Close SaveChanges:=True
Application.DisplayAlerts = True
End Sub
vb.net窗体嵌入的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于vb如何在窗体中添加命令按钮、vb.net窗体嵌入的信息别忘了在本站进行查找喔 。

推荐阅读