0

I've searched the questions for an answer but couldn't quite find a clear cut example. I am trying to display a simple text box in C#. I am working with C#, ArcMap and ArcObjects. I have created a toolbar that has a button in it. Upon clicking the button, I just need a text box to appear on the page. So far, this is what I've got, but nothing is producing when I click my button. Thanks for your help in advance.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace Map
{
    public class ArcGISAddin4 : ESRI.ArcGIS.Desktop.AddIns.Button
    {
        public ArcGISAddin4()
        {
        }

        protected override void OnClick()
        {
            TextBox dynamicTextBox = new TextBox();
            dynamicTextBox.Text = "My First Text Box";
            dynamicTextBox.Name = "First Text Box";
            dynamicTextBox.Enabled = true;
        }

        protected override void OnUpdate()
        {
        }
    }
}
Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
user1898629
  • 329
  • 1
  • 4
  • 22

2 Answers2

1

You must add the TextBox to the surrounding container (the form for example). Otherwise the program won't know where it's supposed to be displayed.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • There is no natural "form" per say. There is an mxd (map document) that is loaded into ArcMap that I need the text box to display on the map document. But I guess I should consider the mad document to be the "form". I will give this a try. Thanks for your help. – user1898629 Mar 28 '14 at 20:59
1

You should add dynamicTextBox to a specific container such as form. Such as this:

 TextBox dynamicTextBox = new TextBox();
 dynamicTextBox.Text = "My First Text Box";
 dynamicTextBox.Name = "First Text Box";
 dynamicTextBox.Enabled = true;
 this.Contols.Add(dynamicTextBox);//this is a pseudo code
  • `this.Contols.Add(dynamicTextBox);` would probably be better since I doubt the OP is referring to his current object in a variable. – Evan L Mar 28 '14 at 19:46
  • Thanks for the input, I will give it a shot though and continue testing. – user1898629 Mar 28 '14 at 20:59
  • I can't enter in the code --> this.Controls.Add(dynamicTextBox); ...I get an error saying that there is no definition for 'Controls' and no extension method...... Of course this is accurate, but I am not using a typical form. I guess you can't just display a textbox on an mxd through this way. – user1898629 Mar 31 '14 at 17:39