18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

BUILDING APPLICATIONS WITH WINDOWS CONTROLS<br />

3. Add the following code to the beginning of the Form_Load event:<br />

private void Form1_Load(object sender, System.EventArgs e)<br />

{<br />

// Suppress drawing while resizing.<br />

this.SetStyle(ControlStyles.EnableNotifyMessage,true);<br />

This method of suppressing resize drawing<br />

works by examining the windows messages sent<br />

to the form. When a form starts resizing,<br />

windows sends the WM_ENTERSIZEMOVE<br />

Windows(messge). At this point you suppress<br />

drawing to the MapControl and<br />

PageLayoutControl and draw using a “stretchy<br />

bitmap”. When Windows sends the<br />

WM_EXITSIZEMOVE the form is released from<br />

resizing and you resume with a full redraw at<br />

the new extent.<br />

}<br />

4. Add the following constants to the class:<br />

public class Form1 : System.Windows.Forms.Form<br />

{<br />

…<br />

private const int WM_ENTERSIZEMOVE = 0x231;<br />

private const int WM_EXITSIZEMOVE = 0x232;<br />

…<br />

5. Add the following code to override the OnNotifyMessage method.<br />

protected override void OnNotifyMessage(System.Windows.Forms.Message m)<br />

{<br />

base.OnNotifyMessage (m);<br />

if (m.Msg == WM_ENTERSIZEMOVE)<br />

{<br />

axMapControl1.SuppressResizeDrawing(true, 0);<br />

axPageLayoutControl1.SuppressResizeDrawing(true, 0);<br />

}<br />

else if (m.Msg == WM_EXITSIZEMOVE)<br />

{<br />

axMapControl1.SuppressResizeDrawing(false, 0);<br />

axPageLayoutControl1.SuppressResizeDrawing(false, 0);<br />

}<br />

}<br />

6. Build and run the application. Try resizing the form.<br />

Adding commands to the ToolbarControl<br />

<strong>ArcGIS</strong> <strong>Engine</strong> comes with more than 120 commands and tools that work with<br />

the MapControl, the PageLayoutControl, and the ToolbarControl directly. These<br />

commands and tools provide you with a lot of frequently used GIS functionality<br />

for map navigation, graphics management, and feature selection. You will now<br />

add some of these commands and tools to your application.<br />

1. In the Form_Load event add the following code before the load document<br />

code.<br />

private void Form1_Load(object sender, System.EventArgs e)<br />

{<br />

string progID;<br />

// Add generic commands.<br />

progID = "esriControlToolsGeneric.ControlsOpenDocCommand";<br />

axToolbarControl1.AddItem(progID, -1 , -1, false, 0,<br />

esriCommandStyles.esriCommandStyleIconOnly);<br />

Chapter 6 • <strong>Developer</strong> scenarios • 339

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!