Callback in vb.net
来源:互联网 发布:sass 淘宝镜像 编辑:程序博客网 时间:2024/06/09 21:34
Even though I'm not quite sure as to what the problem exactly is
with your callback function (was not included in your sample code),
here is the complete code for a very simple Visual Basic .NET app,
using two MI OLE callback functions (receiving status text and
custom tool input event notification):
Form1 contains the map window (PictureBox, "pbMap") and a text box
("tbStatus"), displaying the contents of the status line.
''''''''''''' Begin of VBN code '''''''''''''''''''''''''''''''''''
Public Class Form1
' The MapInfo OLE object:
Private mi As Object
' The object implementing the COM/OLE2 automation server as
' the target of the callbacks originating from the MI OLE object:
Private comServObj As New ComClass1
' A shared object reference to the status text control for
' later access within the status text callback function:
Public Shared tbStatObj As Object
Public Sub New()
' Initialize main form (built with VS Form Designer):
InitializeComponent()
' Save persistent (shared) obj ref to status text control:
tbStatObj = Me.tbStatus
' Create and configure the MI COM object, open a map etc.:
mi = CType(CreateObject("MapInfo.Application"), MapInfo.DMapInfo)
mi.do("Set Application Window " & CType(Me.pbMap.Handle, String))
mi.do("Set Next Document Parent " & CType(Me.pbMap.Handle, String) _
& " Style 1")
mi.do("Open Table ""c:/maps/world.tab"" Interactive Map From World")
mi.Do("Set Map Display Position")
mi.Do("Create Buttonpad ""SelectGeneric"" As Toolbutton ID 785 " _
& "DrawMode 34 Cursor 134 Calling OLE ""SelectGeneric""")
mi.Do("Run Menu Command ID 785")
mi.SetCallback(comServObj)
End Sub
End Class
' Register this class as a COM/OLE2 class:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
' Unique IDs for this COM app interface:
Public Const ClassId As String =
"9CC9946D-C1E4-4f42-9E8C-C4693BD04577"
Public Const InterfaceId As String =
"CC6697F7-968D-47dc-9B5B-84DEF8FD5D6B"
Public Const EventsId As String =
"2A765F7E-E628-4427-A730-A695543EDB79"
Public Sub New()
MyBase.New()
End Sub
' Callback function receiving the contents of the MapInfo status line,
' when changed:
Public Sub SetStatusText(ByVal strStatus As String)
' Show status line text in text box:
CType(Form1.tbStatObj, Control).Text = strStatus
End Sub
' Callback function for notification of user input events
' generated by the custom tool (ID 785, see above):
Public Sub SelectGeneric(ByVal str As String)
MessageBox.Show("A user input event occurred with the parameters:" _
& vbCrLf & str, "MI Custom Tool Callback")
End Sub
End Class
''''''''''''' End of VBN code '''''''''''''''''''''''''''''''''''
with your callback function (was not included in your sample code),
here is the complete code for a very simple Visual Basic .NET app,
using two MI OLE callback functions (receiving status text and
custom tool input event notification):
Form1 contains the map window (PictureBox, "pbMap") and a text box
("tbStatus"), displaying the contents of the status line.
''''''''''''' Begin of VBN code '''''''''''''''''''''''''''''''''''
Public Class Form1
' The MapInfo OLE object:
Private mi As Object
' The object implementing the COM/OLE2 automation server as
' the target of the callbacks originating from the MI OLE object:
Private comServObj As New ComClass1
' A shared object reference to the status text control for
' later access within the status text callback function:
Public Shared tbStatObj As Object
Public Sub New()
' Initialize main form (built with VS Form Designer):
InitializeComponent()
' Save persistent (shared) obj ref to status text control:
tbStatObj = Me.tbStatus
' Create and configure the MI COM object, open a map etc.:
mi = CType(CreateObject("MapInfo.Application"), MapInfo.DMapInfo)
mi.do("Set Application Window " & CType(Me.pbMap.Handle, String))
mi.do("Set Next Document Parent " & CType(Me.pbMap.Handle, String) _
& " Style 1")
mi.do("Open Table ""c:/maps/world.tab"" Interactive Map From World")
mi.Do("Set Map Display Position")
mi.Do("Create Buttonpad ""SelectGeneric"" As Toolbutton ID 785 " _
& "DrawMode 34 Cursor 134 Calling OLE ""SelectGeneric""")
mi.Do("Run Menu Command ID 785")
mi.SetCallback(comServObj)
End Sub
End Class
' Register this class as a COM/OLE2 class:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
' Unique IDs for this COM app interface:
Public Const ClassId As String =
"9CC9946D-C1E4-4f42-9E8C-C4693BD04577"
Public Const InterfaceId As String =
"CC6697F7-968D-47dc-9B5B-84DEF8FD5D6B"
Public Const EventsId As String =
"2A765F7E-E628-4427-A730-A695543EDB79"
Public Sub New()
MyBase.New()
End Sub
' Callback function receiving the contents of the MapInfo status line,
' when changed:
Public Sub SetStatusText(ByVal strStatus As String)
' Show status line text in text box:
CType(Form1.tbStatObj, Control).Text = strStatus
End Sub
' Callback function for notification of user input events
' generated by the custom tool (ID 785, see above):
Public Sub SelectGeneric(ByVal str As String)
MessageBox.Show("A user input event occurred with the parameters:" _
& vbCrLf & str, "MI Custom Tool Callback")
End Sub
End Class
''''''''''''' End of VBN code '''''''''''''''''''''''''''''''''''
- Callback in vb.net
- TraceLog in VB.NET
- Service Management in VB.NET
- First example In VS.NET 2005 Beta2(Script Callback)
- “Invalid postback or callback argument” in ASP.NET 的解决办法
- 【VB/.NET】What Is Attribute In .NET?
- Introduction to OOP in VB.NET
- Calculate elapsed time in VB.NET
- Dynamic Script for executing in VB.NET
- Send Email code in VB.NET
- Introduction to OOP in VB.NET
- GDI+ Programming in C# and VB .NET
- Pro ASP.NET 2.0 in VB 2005
- GetInvocationList of an event in VB.NET
- VB.NET中使用委托(Delegate)来注册回调(callback)函数
- Callback Functions in JavaScript
- Callback functions in GLFW
- callback in js
- YouTube 的架构扩展 - DBA notes
- 多边形的填充方式ALTERNATE与WINDING的区别
- 大型Web2.0站点构建技术初探
- 用foreach对数组进行遍历
- innerText和innerHTML的区别
- Callback in vb.net
- C/C++语言声明的优先级
- IIS出现server application error,解决办法
- 用foreach对交错数组[多维数组]进行遍历
- 通用表表达式(CTEs)
- 软件工程介绍(Data Stuctures and the Java Collections Framework)
- .net泛型方法应用技巧
- JDBC2/3.0 特征 介绍
- SQL SERVER 日志文件被删除后的修复