有没有办法在运行时添加和运行特定的代码?

时间:2013-12-03 01:08:07

标签: database vb.net

我正在Gmaps.Net内创建控件,并设法在其中动态添加标记。有一件事,我想让标记运行不同的代码。

假设我在地图上预设了3个标记。

1 - `Camera1.Show()`
2 - `Camera2.Show()`
3 - `Camera3.Show()`

如果有人想要添加另一个,它应该运行4 - Camera2.Show()或任何他想要将该标记绑定到的相机。

我现在想到的过程是,因为我将有一个用于保存标记位置的数据库,是否可以在MS Access中保存代码?

类似......

获取此代码 - Camera5.Show()并将其添加到动态添加的按钮中..谢谢!

更新:这是我的一些代码..

Dim f2c1 As New Form2
Dim f2c2 As New Form2
Dim f2c3 As New Form2
Dim camera1 As New GMapMarkerGoogleGreen(New PointLatLng(14.579929, 121.058901))


If item Is camera1 Then       ' camera1 is one of the markers that I predefined in the code
        With f2c1             ' so in terms of adding more, I need to save the new ones' latlong in DB
            If .Visible = True Then
                .Hide()
            Else
                .Show()
                .AxXHDec1.Camera = 1                           ' camera ID--needs database
                .AxXHDec1.Host = "some ip add"                 ' host address--needs database
                .AxXHDec1.Play = 1                             ' true / false
                .AxXHDec1.Command = "SetPass -4 guest guest"   ' some password
                .AxXHDec1.ShowText = 7
                .AxXHDec1.ShowInfo = 1
                map_OnMapDrag()
            End If
        End With
    End If

这有点像我想要再次使用。我想将此添加到某个function,因为我只创建Form2 f2c1f2c2f2c3的实例,即aXxhdec是一个activeX。好的事情是只能使用一个。

1 个答案:

答案 0 :(得分:0)

Public Class Camera
   private _myCam As I_AM_NOT_SURE

   _Lat As Single = 0
   Friend Property Latitude As Single
        Get
            Return _Lat 
        End Get
        Set(ByVal value As Single)
            _Lat = value
        End Set
   End Property

   _Long As Single = 0
   Friend Property Longitude As Single
        Get
            Return _Long 
        End Get
        Set(ByVal value As Single)
            _Long = value
        End Set
   End Property

   ' a way to make the camera take care of itself:
  Public Sub CreateView

     myCam = New GMapMarkerGoogleGreen( _
             New PointLatLng(_Lat, _Long ))

    ... the rest of that code
  End Sub

你的代码似乎从这里出来。相机不仅应管理设置,还应创建“视图”。代码中的大多数文字都是变量,可以保存/读取等等Lat / Long似乎是最重要的。保存时,从类中获取值并保存到以下任何地方:

 dbLat var.... = Camera1.Latitude
 dbLong var.... = Camera1.Longitude 

然后把它们放回去。从数据库中读取数据并:

 Dim Camera1 as New Camera

 Camera1.Longitude = dt.row(0)("Longitude")
 Camera1.Latitude = dt.row(0)("Latitude")
  ... etc
 End With

 Camera1.CreateView      ' create the view (?)

非常粗糙,但我没有太多事情要继续,但变量的原理和通过属性暴露它们是重点。