Simple implementation of the desktop information tool (infotool) in mapxtreme

Source: Internet
Author: User

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 ()));
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.