Pergunta

I am a beginner in gis and I have to make a simple application with 2 buttons a folderbrowser and a listbox.

But here is the thing in arcmap add-ins I need to work with multiple files like the button.cs etc but I don't know how I make the files interact with each other. I have been looking through many forums and the arcgis resource center. But I can't seem to find anything.

So what I want to do is be able to pass events/variables to other files. Please before you feel the urge to downvote or something like that try making me clear what I'm doing wrong (I wont learn to post better questions if I don't know whats wrong with them), thank you for the help.

Here is some code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;

namespace ArcMapAddin16
{
public class Button1 : ESRI.ArcGIS.Desktop.AddIns.Button
{
    public Button1()
    {
    }

    protected override void OnClick()
    {
        UID dockWinID = new UIDClass();
        dockWinID.Value = ThisAddIn.IDs.DockableWindow1;
        IDockableWindow dockWindow =      ArcMap.DockableWindowManager.GetDockableWindow(dockWinID);
        dockWindow.Show(true);

        listBox1.Items.Add("Sally");
        listBox1.Items.Add("Craig");

        ArcMap.Application.CurrentTool = null;
    }
    protected override void OnUpdate()
    {
        Enabled = ArcMap.Application != null;
    }
}

}
Foi útil?

Solução

from what I can understand, you want to instantiate a Button object (class) with some information, correct?

There are 2 options. The first is to define a constructor that allows you to inject parameters, the second is create the object then set properties with the information you need.

This is how this would look in code;

public class Person
{
 // default constructor
 public Person()
 {
 }

 public Person(string name, int age)
 {
  Name = name;
  Age = age;
 }

 public string Name {get;set;}
 public int Age {get;set;}
}

public class Employee
{
 private Person _person;

 // default constructor
 // Option 1;
 public Employee()
 {
  // create instance of person injecting name and age on instantiation
  Person = new Person("John Doe", "42");
 }

 // Option 2
 public Employee(string name, int age)
 {
  // create instance with default constructor 
  Person = new Person();

  // set properties once object is created.
  Person.Name = name;
  Person.Age = age;
 }

}

I don't know your programming skills, but if you're new to C#, then check out this link

I hope this helps.

Outras dicas

You need to implement an extension which you can then access from other components of your addin. The Custom selection extension sample shows how implement such communication between components.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top