You'll need a button for click event and a label on your form:
private void button1_Click(object sender, EventArgs e)
{
PickTextInDrawing.SelectTextInDwg(label1);
}
public static void SelectTextInDwg(Label label1)
{
Document document = AcadApp.DocumentManager.MdiActiveDocument;
Editor editor = document.Editor;
Database database = HostApplicationServices.WorkingDatabase;
PromptEntityOptions options = new PromptEntityOptions("\nSelect Text Object: < pick > ");
options.AllowNone = false;
options.SetRejectMessage("\nMust be DBText. ");
options.AddAllowedClass(typeof(DBText), false);
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
PromptEntityResult selection = editor.GetEntity(options);
if (selection.Status == PromptStatus.OK)
{
using (document.LockDocument())
{
using (Transaction trans = database.TransactionManager.StartTransaction())
{
DBText text = trans.GetObject(selection.ObjectId, OpenMode.ForRead, false, false) as DBText;
label1.Text = text.TextString;
trans.Commit();
}
}
}
else
{
label1.Text = "Missed Pick:";
}
}