Reference from ITool to Form? (ArcGIS Engine)

810
6
04-22-2010 08:37 AM
WesBailes
New Contributor III
I have a custom tool from which I want to update content (textbox, DataGridView, etc.) on the main form.  I am developing in VB.Net but any help is appreciated.  Thanks!
0 Kudos
6 Replies
KirkKuykendall
Occasional Contributor III
You might want to have a dockablewindow instead of a form, in which case you'd use IDockableWindowManager.GetDockablewindow, then access the datagrid or whatever via IDockableWindow.UserData.

Or, you could have an IExtension maintain a reference to your form and have your tool find the Extension in the OnCreate, and access the form via methods exposed by the extension.
0 Kudos
WesBailes
New Contributor III
I'm not sure that option one would work due to it being a standalone mapping application developed with ArcGIS Engine which uses windows form on startup.  I did see this thread from the old site which seems to make sense, but I'm not sure how to declare my tool as it is not available to be referenced at the module level? 

http://forums.esri.com/Thread.asp?c=159&f=1707&t=224532&mc=7#msgid681654 
0 Kudos
SaqibMehmood
New Contributor
Have you thought about adding a reference of your form/window in the custom tool that you developed?
0 Kudos
WesBailes
New Contributor III
Have you thought about adding a reference of your form/window in the custom tool that you developed?


I think that is what I need help with...I can declare a new form (see below), but I'm not sure how to refer to an existing one (the main form in an ArcGIS Engine Standalone app)


  Dim myForm As StructureInfoForm = New StructureInfoForm(m_hookHelper)
        myForm.CurrentFeature(CDbl(pRow.Value(pRow.Fields.FindField("uid"))))
        myForm.Show()
0 Kudos
KirkKuykendall
Occasional Contributor III
oops, sorry, I didn't notice you're talking about arcengine.

When your main form starts up, set IToolBarControl.CustomProperty to your main form.

Expose a getter on your main form that allows access to the form you want your tool to work with.

Add a member variable to your tool that references your main form.

Cast the hook passed to your tool in OnCreate  to IToolBarControl and set the member variable main form reference to the IToolBarControl.CustomProperty. 

In the MouseDown (or whatever) access your form via m_MyMainForm.MyOtherForm.SomeProperty.
0 Kudos
WesBailes
New Contributor III
Thanks for all of the suggestions!  Kirk, your step by step worked perfectly...thanks a bunch!
0 Kudos