One way to implement infotool is to use the select tool to call the getinfo method in the toolused event processing function (a self-written method to obtain the attribute information of the current selected set ).
(1) Add the toolused event handler to the delegate in the form constructor:
Public form1 ()
{
Initializecomponent ();
// Add tools_used to toolusedeventhandler to handle the select tool's use Event
Mapcontrol1.tools. Used + = new MapInfo. Tools. toolusedeventhandler (tools_used );
}
(2) set the left mouse button tool as the select tool:
Private void btnselecttool_click (Object sender, eventargs E)
{
Mapcontrol1.tools. leftbuttontool = "select ";
}
(3). In the toolused processing function, if the select tool is used, call the getinfo method:
Private void tools_used (Object sender, MapInfo. Tools. toolusedeventargs E)
{
Switch (E. toolname)
{
Case "select ":
{
// If the select tool used, call getinfo method to show the feature's Information
This. getinfo (this );
// Note: The Break keyword is needed
Break;
}
}
}
(4) the specific implementation of the getinfo method is used to obtain the attribute information of the selected elements of the select tool:
Private void getinfo (Object sender)
{
Listbox1.items. Clear ();
MapInfo. Engine. isession session = MapInfo. Engine. session. Current;
// Specify which layer dose the feature belongs
Featurelayer lyr = mapcontrol1.map. Layers [combobox1.text] As featurelayer;
// Hold the default selection (the features you clicked) in
// Iresultsetfeaturecollection
Iresultsetfeaturecollection RSFC = session. Selections. defaultselection [lyr. Table];
If (RSFC! = NULL) // an exception will be thrown if you remove this if-clause
{
// Go through the default selection-the features
Foreach (feature F in RSFC)
{
// The columns of each feature
Foreach (MapInfo. Data. Column Col in F. columns)
{
// Show each field of every feature
Listbox1.items. Add (string. Format ("{0 }:{ 1}", col. tostring (), f [col. tostring ()]. tostring ()));
}
}
}
}