ArcGIS Engine + C # instance development tutorial 4 Add and implement status bar Information

Source: Internet
Author: User
Abstract: In the previous lecture, We have synchronized two views: mapcontrol and pagelayoutcontrol. In this article, we will add and implement the status bar information. Application Program The status bar is generally used to display the current state of the program, the tool currently used. GIS applications usually display the coordinates, scales, and other information of the current cursor in the status bar. After learning the content of this lecture, you will learn the basic method of Status Bar programming, and be able to add and display the following information in the status bar of our program: current tool information, current scale, current coordinates.

 Tutorial directory:

First, the establishment of the desktop GIS application framework

Ii. Menu addition and implementation

Third, synchronize mapcontrol with pagelayoutcontrol

Lecture 4 Add and implement status bar Information

Fifth, the implementation of eagleeye

Sixth, right-click menu addition and implementation

Tutorial bug and optimization solution 1

7. Implementation of layer symbol selector 1

7. Implementation of layer symbol selector 2

Lecture 8 query and display of attribute data tables

------------------------------------------------------------------

In the previous lecture, We have synchronized two views: mapcontrol and pagelayoutcontrol. In this article, we will add and implement the status bar information.

The Application Status Bar is generally used to display the current state of the program and the tools currently used. GIS applications usually display the coordinates, scales, and other information of the current cursor in the status bar.

After learning the content of this lecture, you will learn the basic method of Status Bar programming, and be able to add and display the following information in the status bar of our program:

    • Current tool information
    • Current Scale
    • Current Coordinate

1,Add a status bar project

In the design view, click the status bar in the form, find the "items" item in its property panel, click the button on the right, and select "statuslabel" in the drop-down box ", click "Add button", add four statuslabels in sequence, and modify the attribute parameters as shown in the following table:

Serial number

Name attribute

Text attributes

Spring attributes

Description

1

Messagelabel

Ready

False

Current tool information

2

Blank

True

Placeholder

3

Scalelabel

Scale

False

Current Scale

4

Coordinatelabel

Current Coordinate

False

Current Coordinate

As shown in figure:

Tips:

The status bar we designed is as follows:

Ready

(Blank)

Scale

Current Coordinate

The spring attribute indicates that auto scaling can be performed based on the remaining space in the status bar. Therefore, we joined the blank project only to take a seat to achieve the right alignment of the scalelabel and coordinatelabel projects and left alignment of the messagelabel project.

2,Displays information about the currently used tool.

First, add the onmousemove event of axtoolbarcontrol1 (I believe you have read the above tutorial and know how to add the event. If you do not know it, we recommend that you review the previous lecture ). In its Event Response FunctionCodeAs follows:

 

Private void axtoolbarcontrolpoliconmousemove (Object sender, itoolbarcontrolevents_onmousemoveevent E)

{

// Obtain the index number of the tool where the mouse is located

Int Index = axtoolbarcontrol1.hittest (E. X, E. Y, false );

If (index! =-1)

{

// Obtain the toolbaritem of the tool where the mouse is located

Itoolbaritem toolbaritem = axtoolbarcontrol1.getitem (INDEX );

// Set the status bar Information

Messagelabel. Text = toolbaritem. Command. message;

}

Else

{

Messagelabel. Text = "ready ";

}

}

3,Display current scale

Add the onmousemove event of axmapcontrol1. The Code is as follows:

 

Private void axmapcontrolpoliconmousemove (Object sender, imapcontrolevents2_onmousemoveevent E)

{

// Display the current scale

Scalelabel. Text = "Scale 1:" + (long) This. axmapcontrol1.mapscale). tostring ();

}

4,Show current coordinates

The current coordinate is also the response in the onmousemove event of axmapcontrol1. Therefore, you only need to add the following code to the axmapcontrolpoliconmousemove function:

 

// Display the current Coordinate

Coordinatelabel. Text = "Current coordinate X =" + E. MapX. tostring () + "Y =" + E. mapy. tostring () + "" + this. axmapcontrol1.mapunits;

Press F5 to compile and run the program. We can see that our program is working properly. However, you may find that the coordinate units behind the current coordinate are "esriunknownunits" or "esrimeters", that is, the system adds "ESRI" before the normal unit ", we naturally don't feel comfortable pursuing perfection. Simply replace it.

First, define a global coordinate unit variable smapunits, as shown below:

 

Private string smapunits;

Then initialize in the form1_load function:

 

Smapunits = "unknown ";

Add the onmapreplaced event of the axmapcontrol1 control and replace the coordinate units in the event response function. The Code is as follows:

 

Private void axmapcontrolpoliconmapreplaced (Object sender, imapcontrolevents2_onmapreplacedevent E)

{

Esriunits mapunits = axmapcontrol1.mapunits;

Switch (mapunits)

{

Case esriunits. esricentimeters:

Smapunits = "centimeters ";

Break;

Case esriunits. esridecimaldegrees:

Smapunits = "decimal degrees ";

Break;

Case esriunits. esridecimeters:

Smapunits = "decimeters ";

Break;

Case esriunits. esrifeet:

Smapunits = "feet ";

Break;

Case esriunits. esriinches:

Smapunits = "inches ";

Break;

Case esriunits. esrikilometers:

Smapunits = "kilometers ";

Break;

Case esriunits. esrimeters:

Smapunits = "meters ";

Break;

Case esriunits. esrimiles:

Smapunits = "Miles ";

Break;

Case esriunits. esrimillimeters:

Smapunits = "millimeters ";

Break;

Case esriunits. esrinauticalmiles:

Smapunits = "nauticalmiles ";

Break;

Case esriunits. esripoints:

Smapunits = "points ";

Break;

Case esriunits. esriunknownunits:

Smapunits = "unknown ";

Break;

Case esriunits. esriyards:

Smapunits = "yards ";

Break;

}

}

5,Compile and run

Press F5 to compile and run the program. If you are careful enough, I believe you have succeeded!

In this section, we will introduce the basic usage of the statusstrip control and call methods for displaying tool information, current scale, and current coordinates in AE.

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.