jeudi 26 février 2015

Creating Panning Buttons in C#


I am new to this and still trying to learn. I have a bunch of VBA code that I am trying to convert to C# and even the most basic things are hanging me up.


Currently I am trying to build a button that pans the display Left when pressed.


The original VBA code that I have looks as follows:



Sub pan_left()
On Error GoTo Errhandler


Dim pMxDocument As IMxDocument
Dim pactiveview As IActiveView
Dim penv As IEnvelope
Dim pxmax, pxmin, pymax, pymin As Double
Dim nxmax, nxmin, nymax, nymin As Double
Dim width, height As Double

Set pMxDocument = ThisDocument
Set pactiveview = pMxDocument.FocusMap
Set penv = pactiveview.Extent

pxmax = penv.XMax
pxmin = penv.XMin
pymax = penv.YMax
pymin = penv.YMin

width = pxmax - pxmin
height = pymax - pymin
nxmax = pxmax + (width / 1.08)
nxmin = pxmin + (width / 1.08)
nymax = pymax
nymin = pymin

penv.XMax = nxmax
penv.XMin = nxmin
penv.YMax = nymax
penv.YMin = nymin

pactiveview.Extent = penv
pactiveview.Refresh

ThisDocument.fTimer
Exit Sub
Errhandler:
On Error Resume Next


End Sub


I have been trying to write it using the Desk top Addins. I have found some code on ESRI's website found here: Pan Left (Not sure if I am even on the right track.)


Currently my code looks as follows:



using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.ADF.CATIDs;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Framework;



namespace NAIP_QQv1

{



[ClassInterface(ClassInterfaceType.None)]

[Guid("593EDF4F-D1FE-4a8d-8076-C3B583C37F6B")]



public class PanDown : ICommand

{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);

//
// TODO: Add any COM registration code here
//
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);

//
// TODO: Add any COM unregistration code here
//
}

#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Register(regKey);

}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Unregister(regKey);

}

#endregion
#endregion


[DllImport("user32.dll")]
static extern IntPtr SetFocus(IntPtr hWnd);


private System.Drawing.Bitmap m_bitmap;
private IntPtr m_hBitmap;
private IHookHelper m_pHookHelper;


public class Pan_Left : ESRI.ArcGIS.Desktop.AddIns.Button
{

public Pan_Left()
{
//m_pHookHelper = new HookHelperClass ();

}

protected override void OnClick()
{//Get the active view
IActiveView pActiveView = m_pHookHelper.ActiveView;

//Get the extent
IEnvelope pEnvelope = (IEnvelope)pActiveView.Extent;


}

protected override void OnUpdate()
{
}
}
}
}




Aucun commentaire:

Enregistrer un commentaire