向ArcGIS Toolbar中添加任意的windows組件的方法(VB.Net源碼)

來源:互聯網
上載者:User

編寫ArcGIS程式時經常遇到向Toolbar中添加諸如TextBox等組件的需求,

本文介紹向ArcGIS Toolbar添加任意windows組件的方法。

新寫一個類CommandCustomControl,該類實現ICommand介面和IToolControl介面,

在引用CommandCustomControl表單中添加一個windows組件,

比如Label、textbox、combobox,然後傳入CommandCustomControl中。

調用方法如下:

    Dim pText As New CommandCustomControl
    pText.CustomControl = TextBox1
    AxToolbarControl1.AddItem(pText)
    Dim pCombo As New CommandCustomControl
    pCombo.CustomControl = ComboBox1
    AxToolbarControl1.AddItem(pCombo)

下面給出CommandCustomControl類的原始碼:

Imports ESRI.ArcGIS.SystemUI
Imports System.Windows.Forms
''' <summary>
''' 自訂的command,可以向toolbar中加入label、textbox等組件
''' </summary>
''' <remarks>該類實現ICommand介面和IToolControl介面,在引用CommandCustomControl表單中添加一個windows組件,比如Label、textbox、combobox,然後傳入CommandCustomControl中。</remarks>
Public Class CommandCustomControl
  Implements IToolControl
  Implements ICommand

#Region "變數和屬性"
  Public pCompNotify As ICompletionNotify
  Private m_Control As Control
  ''' <summary>
  ''' 傳入的control,如Label,textbox等等
  ''' </summary>
  ''' <value></value>
  ''' <returns></returns>
  ''' <remarks>可以在此傳入control,或者在建構函式中建立control,當然最好是在外面傳入control,這樣可以在外面設計control,並捕獲control的相關事件</remarks>
  Property CustomControl() As Control
    Get
      Return m_Control
    End Get
    Set(ByVal value As Control)
      m_Control = value
    End Set
  End Property
#End Region

  ''' <summary>
  ''' 建構函式
  ''' </summary>
  ''' <remarks></remarks>
  Sub New()
    m_Control = New Label
    m_Control.Text = "label"
  End Sub

#Region "實現IToolControl"
  Public ReadOnly Property hWnd() As Integer Implements ESRI.ArcGIS.SystemUI.IToolControl.hWnd
    Get
      Return m_Control.Handle
    End Get
  End Property

  Public Function OnDrop(ByVal barType As ESRI.ArcGIS.SystemUI.esriCmdBarType) As Boolean Implements ESRI.ArcGIS.SystemUI.IToolControl.OnDrop
    If barType = esriCmdBarType.esriCmdBarTypeToolbar Then
      Return True
    End If
  End Function

  Public Sub OnFocus(ByVal complete As ESRI.ArcGIS.SystemUI.ICompletionNotify) Implements ESRI.ArcGIS.SystemUI.IToolControl.OnFocus
    pCompNotify = complete
  End Sub
#End Region

#Region "實現ICommand"
  Public ReadOnly Property Bitmap() As Integer Implements ESRI.ArcGIS.SystemUI.ICommand.Bitmap
    Get

    End Get
  End Property

  Public ReadOnly Property Caption() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Caption
    Get

    End Get
  End Property

  Public ReadOnly Property Category() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Category
    Get

    End Get
  End Property

  Public ReadOnly Property Checked() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Checked
    Get
      Return True
    End Get
  End Property

  Public ReadOnly Property Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled
    Get
      Return True
    End Get
  End Property

  Public ReadOnly Property HelpContextID() As Integer Implements ESRI.ArcGIS.SystemUI.ICommand.HelpContextID
    Get

    End Get
  End Property

  Public ReadOnly Property HelpFile() As String Implements ESRI.ArcGIS.SystemUI.ICommand.HelpFile
    Get

    End Get
  End Property

  Public ReadOnly Property Message() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Message
    Get

    End Get
  End Property

  Public ReadOnly Property Name() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Name
    Get

    End Get
  End Property

  Public Sub OnClick() Implements ESRI.ArcGIS.SystemUI.ICommand.OnClick

  End Sub

  Public Sub OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate

  End Sub

  Public ReadOnly Property Tooltip() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Tooltip
    Get

    End Get
  End Property
#End Region

End Class

給出完整程式下載:/Files/wall/TestCommandCustomControl.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.