• 添加、删除标签以及窗体间参数的传递



     

    这是在实现Arcgis Engine的书签的添加以及读取时接触到的:点击添加标签后,弹出给标签命名的窗体,输入名称后将该名字添加到另一个标签列表的窗体。在主对话框分别实现存储和读取的接口。

    主窗体的实现的代码如下:

    Private Sub 添加书签ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 存为书签ToolStripMenuItem.Click
            Dim pMapBookmarks As IMapBookmarks
            pMapBookmarks = AxMapControl1.ActiveView.FocusMap
            Dim pAOIBookmark As IAOIBookmark
            pAOIBookmark = New AOIBookmark
            pAOIBookmark.Location = AxMapControl1.ActiveView.Extent
    
    
            Dim Bookmark As New Bookmark
            'Dim pBMname As String
            ' Bookmark.MdiParent = Me
            Bookmark.ShowDialog()
            'My.Forms.Bookmark.Bookmark_Load(sender, e)
    
            If pBookmarkName IsNot Nothing Then
                pAOIBookmark.Name = pBookmarkName
    
                pMapBookmarks.AddBookmark(pAOIBookmark)
    
            End If
    
        End Sub
    
        Private Sub 打开书签ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开书签ToolStripMenuItem.Click
            Dim pMapBookmarks As IMapBookmarks
            pMapBookmarks = CType(AxMapControl1.ActiveView.FocusMap, IMapBookmarks)
            Dim pEnumSpatialBM As IEnumSpatialBookmark
            pEnumSpatialBM = pMapBookmarks.Bookmarks
    
    
            BookmarkList.ShowDialog()
            Dim pOpenBMname As String
            pOpenBMname = OpenBMname
    
            Dim pSpatialBM As ISpatialBookmark
            pSpatialBM = pEnumSpatialBM.Next
            While (pSpatialBM IsNot Nothing)
    
                If pSpatialBM.Name = pOpenBMname Then
                    pSpatialBM.ZoomTo(AxMapControl1.ActiveView.FocusMap)
                    AxMapControl1.ActiveView.Refresh()
                    Return
                End If
                pSpatialBM = pEnumSpatialBM.Next
            End While
          
    
        End Sub
    End Class

    添加书签窗体的代码如下:

    Public BookmarkList As New BookmarkList
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            pBookmarkName = TextBox1.Text
        End Sub
    
        Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'My.Forms.MainForm.BMname = TextBox1.Text
            pBookmarkName = TextBox1.Text
            My.Forms.MainForm.BookmarkList.additem(pBookmarkName)
            Me.Hide()
        End Sub


    书签窗体代码

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer
            i = ComboBox1.Items.Count
            My.Forms.MainForm.OpenBMname = ComboBox1.Text
            Me.Hide()
        End Sub
    
            Public Sub additem(ByVal BookmarkName As String)
            ComboBox1.Items.Add(BookmarkName)
        End Sub

    其中pBookmarkName是在新建的模块中定义的公共变量。

    在书签的过程中,主要实现不同窗体间参数的传递。传递方法是:(假如form2 textbox的值向form1的字符串变量m传递)

    方法一:

    定义模块变量str

    form2窗体:

    str=textbox.text

    form1窗体:

    m=str

    方法二:

    在form1中定义公共变量:

    public str as string

    Private sub ButtonOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOK.Click

    str=textbox.text

    End sub

    在form2中

    直接调用a=My.Forms.Form2.str

    还有一个问题是:显示标签对话框时,用Form2.ShowDialog()而不是Form2.Show()。用后者会运行程序时,运行到Form2.show(),并没有完全弹出Form2,程序也没有调到Form2中,而是继续往下。改成ShowDialog是可以解决问题,可是不知道为什么……哪位知道指点一下哦~

  • 相关阅读:
    [BZOJ 1552] 排序机械臂
    [BZOJ 1124][POI 2008] 枪战 Maf
    [BZOJ 1647][USACO 2007 Open] Fliptile 翻格子游戏
    [BZOJ 1592] Making The Grade路面修整
    [BZOJ 3829][POI2014] FarmCraft
    [技术] 如何正确食用cnblogs的CSS定制
    [BZOJ 1458] 士兵占领
    今天写了一个Imageloader,,AndroidStudio报了Error:Execution failed for task ':app:mergeDebugResources'. > Error: Java.util.concurrent.ExecutionException: com.Android.ide.common.process.ProcessException: 这个错误
    Http响应码代表的含义
    获取WIFI列表,在旧手机上运行就没有问题,在新手机上就怎么也获取不到WIFI列表,长度一直为0,还不报异常,很疑惑。
  • 原文地址:https://www.cnblogs.com/beileierhao/p/2486089.html
Copyright © 2020-2023  润新知