Select to view content in your preferred language

ArcObjects TextBox on Map Document

6467
20
04-07-2014 11:28 AM
JamariPowers
Deactivated User
ArcMap 10.0
Arc Objects
Visual Studio 2010

I am new to using ArcObjects and have been getting more and more familiar with ArcMap. I am using Visual Studio and been having trouble creating / placing a simple textbox on an mxd. I am working in C#. I have a toolbar with buttons and hope to accomplish this on button click. The text box should be able to support text inside it as well.

Trying to start off small and work my way up. Any help on this topic would be greatly appreciated. Thanks in advance.
0 Kudos
20 Replies
AhmedEl-Sisi
Deactivated User
You can place ITextElement on your map.
Check Text Element Snippt for Globe to get the idea.
0 Kudos
JamariPowers
Deactivated User
Thanks for your input. I will take a look. I'm assuming the ITextElement, in simplistic terms, is a box that contains text? My confusion stems from wanting a text element or a textbox element. But again I assume they are essentially the same. Still getting used to Esri ArcObjects and training m mind to conform to their framework.
0 Kudos
LeoDonahue
Deactivated User
I'm assuming the ITextElement, in simplistic terms, is a box that contains text?

Yes.  That is why the previous post provided a link to the API documentation for ITextElement.

My confusion stems from wanting a text element or a textbox element. But again I assume they are essentially the same.

They are not the same.  There is no such thing as a Textbox element in the ArcObjects API. 

If "by the same" you mean they both provide a way to set and display text, then yes, they are essentially the same in that regard.  You could check the ArcObjects API, but the .NET version is really impossible to find anything unless you are willing to click on every tree node in every namespace. 

<sarcasm>Let's see, if I don't know what I'm looking for, perhaps it might be in the carto namespace, but maybe in A?  or B?  or C? Maybe it's cartoUI, but is it IA, or IB? or..  a list would be nice... </sarcasm>

Click this:  http://resources.arcgis.com/en/help/arcobjects-java/api/arcobjects/index.html

Scroll through the frame on the lower left side of your browser.  No Textbox elements.

Components that are provided by your IDE are usually added to a form or a dockable window and then displayed over the map document, or docked into one of the dockable areas.
0 Kudos
KenBuja
MVP Esteemed Contributor
You could check the ArcObjects API, but the .NET version is really impossible to find anything unless you are willing to click on every tree node in every namespace. 

<sarcasm>Let's see, if I don't know what I'm looking for, perhaps it might be in the carto namespace, but maybe in A?  or B?  or C? Maybe it's cartoUI, but is it IA, or IB? or..  a list would be nice... </sarcasm>



This is one reason I am using H3Viewer to browse through all the help documentation.

[ATTACH=CONFIG]32957[/ATTACH]
0 Kudos
LeoDonahue
Deactivated User
That looks nice.  Now they need to get that on the web.
0 Kudos
JamariPowers
Deactivated User

If "by the same" you mean they both provide a way to set and display text, then yes, they are essentially the same in that regard.  You could check the ArcObjects API, but the .NET version is really impossible to find anything unless you are willing to click on every tree node in every namespace. 


Yes, that's what I meant. I think at this point, I've nearly gone through every tree node in every namespace. Completely new to this Esri ArcObjects thing. Clearly I'm still learning, but thanks so much for your assistance / help. I should be able to get somewhere now.
0 Kudos
JamariPowers
Deactivated User
I am having some trouble. I have tried the following:

protected override void OnClick()
        {
            IElement _element;

            IMxDocument _mxDoc = ArcMap.Application.Document as IMxDocument;
            IMap _map = _mxDoc.FocusMap;
            IActiveView _activeView = _map as IActiveView;
            IPageLayout3 _pageLayout = _activeView as IPageLayout3;

            if (_activeView is IPageLayout3)
            {

                ITextElement _textElement = new TextElementClass();
                _element = _textElement as IElement;

                ITextSymbol _textSymbol = new TextSymbolClass();
                _textElement.Text = "Test me";
            }
            else
            {
                MessageBox.Show("This tool only functions in layout view");
            }
            _activeView.Refresh();
           
        }

But I am receiving the message box from the else statement. Am I even doing this right??

Please help??
0 Kudos
LeoDonahue
Deactivated User
Apply this logic to whatever language you are programming in.  I won't speak it's name. 🙂

package gov.gis.leo;

import java.io.IOException;

import javax.swing.JOptionPane;

import com.esri.arcgis.addins.desktop.Button;
import com.esri.arcgis.arcmapui.IMxDocument;
import com.esri.arcgis.carto.IActiveView;
import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.carto.IPageLayout;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.interop.AutomationException;


public class Button1 extends Button {

    @Override
    public void init(IApplication arg0) throws IOException, AutomationException {
        super.init(arg0);
        this.app = arg0;
        
        // Initialize our map document
        mxDocument = (IMxDocument)app.getDocument();
    }

    /**
     * Called when the button is clicked.
     * 
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void onClick() throws IOException, AutomationException {

        activeView = mxDocument.getActiveView();
        
        if(activeView instanceof IPageLayout){
            JOptionPane.showMessageDialog(null, "You are in Page Layout view");
        }
        
        if(activeView instanceof IMap){
            JOptionPane.showMessageDialog(null, "You are in data view");
        }
    }
    
    private IMxDocument mxDocument;
    private IApplication app;
    private IActiveView activeView;

}


0 Kudos
JamariPowers
Deactivated User
Ok, I think I'm good until I hit the IF statement. I'm working in C# and not necessarily sure of how to write those statements in the "C#" way.

Wait,..scratch that. It worked. Using your logic and some syntax adjustments, I was able to determine which view I was in. Thank you so much.
0 Kudos