About the Control text symbols using the SymbologyControl Sample
[C#]
TextSymbols.cs
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS; namespace TextSymbols { public class Form1 : System.Windows.Forms.Form { private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1; private ESRI.ArcGIS.Controls.AxPageLayoutControl axPageLayoutControl1; private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null; private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.ComboBox comboBox1; internal System.Windows.Forms.Label Label1; internal Label label2; private ITextSymbol m_textSymbol; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { //Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown(); if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.axToolbarControl1 = new ESRI.ArcGIS.Controls.AxToolbarControl(); this.axPageLayoutControl1 = new ESRI.ArcGIS.Controls.AxPageLayoutControl(); this.button1 = new System.Windows.Forms.Button(); this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl(); this.textBox1 = new System.Windows.Forms.TextBox(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.Label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit(); this.SuspendLayout(); // // axToolbarControl1 // this.axToolbarControl1.Location = new System.Drawing.Point(8, 8); this.axToolbarControl1.Name = "axToolbarControl1"; this.axToolbarControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axToolbarControl1.OcxState"))); this.axToolbarControl1.Size = new System.Drawing.Size(200, 28); this.axToolbarControl1.TabIndex = 0; // // axPageLayoutControl1 // this.axPageLayoutControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.axPageLayoutControl1.Location = new System.Drawing.Point(0, 56); this.axPageLayoutControl1.Name = "axPageLayoutControl1"; this.axPageLayoutControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPageLayoutControl1.OcxState"))); this.axPageLayoutControl1.Size = new System.Drawing.Size(640, 328); this.axPageLayoutControl1.TabIndex = 1; this.axPageLayoutControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IPageLayoutControlEvents_Ax_OnMouseDownEventHandler(this.axPageLayoutControl1_OnMouseDown); // // button1 // this.button1.Location = new System.Drawing.Point(216, 8); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(128, 23); this.button1.TabIndex = 2; this.button1.Text = "Select Text Symbol"; this.button1.Click += new System.EventHandler(this.button1_Click); // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(80, 32); this.axLicenseControl1.Name = "axLicenseControl1"; this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState"))); this.axLicenseControl1.Size = new System.Drawing.Size(32, 32); this.axLicenseControl1.TabIndex = 3; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(352, 8); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(192, 20); this.textBox1.TabIndex = 4; this.textBox1.Text = "TextElement with selected TextSymbol"; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.Location = new System.Drawing.Point(552, 8); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(80, 21); this.comboBox1.TabIndex = 5; // // Label1 // this.Label1.Location = new System.Drawing.Point(351, 38); this.Label1.Name = "Label1"; this.Label1.Size = new System.Drawing.Size(296, 16); this.Label1.TabIndex = 7; this.Label1.Text = "2) Right click on the display to add a text element"; // // label2 // this.label2.Location = new System.Drawing.Point(214, 37); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(296, 16); this.label2.TabIndex = 8; this.label2.Text = "1) Select a text symbol"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(640, 382); this.Controls.Add(this.Label1); this.Controls.Add(this.comboBox1); this.Controls.Add(this.textBox1); this.Controls.Add(this.axLicenseControl1); this.Controls.Add(this.button1); this.Controls.Add(this.axPageLayoutControl1); this.Controls.Add(this.axToolbarControl1); this.Controls.Add(this.label2); this.Name = "Form1"; this.Text = "Change Text Symbol"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion [STAThread] static void Main() { if (!RuntimeManager.Bind(ProductCode.Engine)) { if (!RuntimeManager.Bind(ProductCode.Desktop)) { MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down."); return; } } Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { //Set buddy control axToolbarControl1.SetBuddyControl(this.axPageLayoutControl1); //Add ToolbarControl items axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand"); axToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool"); axToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool"); axToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand"); axToolbarControl1.AddItem("esriControls.ControlsSelectTool"); //Add values for the text size to the combo box comboBox1.Items.Add("8pt"); comboBox1.Items.Add("10pt"); comboBox1.Items.Add("12pt"); comboBox1.Items.Add("14pt"); comboBox1.SelectedIndex = 0; } private void button1_Click(object sender, System.EventArgs e) { //Create a new SymbolForm Form2 symbolForm = new Form2(); //Get the IStyleGalleryItem that has been selected in the SymbologyControl IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassTextSymbols); if (styleGalleryItem == null) return; //Set the TextSymbol m_textSymbol = (ITextSymbol) styleGalleryItem.Item; //Release the SymbolForm symbolForm.Dispose(); } private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e) { //Check if the right button of the mouse was clicked if (e.button != 2) return; //Ensure a text symbol has been selected if (m_textSymbol == null) return; //Create a point and set its coordinates IPoint point = new PointClass(); point.X = e.pageX; point.Y = e.pageY; //Create a text element ITextElement textElement = new TextElementClass(); textElement.Text = textBox1.Text; //Set the size of the text if (comboBox1.SelectedItem.ToString() == ("8pt")) m_textSymbol.Size = 8.0; else if (comboBox1.SelectedItem.ToString() == ("10pt")) m_textSymbol.Size = 10.0; else if (comboBox1.SelectedItem.ToString() == ("12pt")) m_textSymbol.Size = 12.0; else if (comboBox1.SelectedItem.ToString() == ("14pt")) m_textSymbol.Size = 14.0; //Set the TextElement symbol to that of the selected text symbol textElement.Symbol = m_textSymbol; textElement.ScaleText = true; //QI to IElment IElement element = (IElement) textElement; //Set the TextElement's geometry element.Geometry = point; //Add the element to the GraphicsContainer axPageLayoutControl1.ActiveView.GraphicsContainer.AddElement(element, 0); //Refresh the PageLayout axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null); } } }
[Visual Basic .NET]
TextSymbols.vb
Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Display Public Class Form1 Inherits System.Windows.Forms.Form Private m_textSymbol As ITextSymbol #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine) 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 'Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown() If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents AxToolbarControl1 As ESRI.ArcGIS.Controls.AxToolbarControl Friend WithEvents AxPageLayoutControl1 As ESRI.ArcGIS.Controls.AxPageLayoutControl Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label1 As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) Me.AxToolbarControl1 = New ESRI.ArcGIS.Controls.AxToolbarControl Me.AxPageLayoutControl1 = New ESRI.ArcGIS.Controls.AxPageLayoutControl Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl Me.Button1 = New System.Windows.Forms.Button Me.TextBox1 = New System.Windows.Forms.TextBox Me.ComboBox1 = New System.Windows.Forms.ComboBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'AxToolbarControl1 ' Me.AxToolbarControl1.Location = New System.Drawing.Point(8, 8) Me.AxToolbarControl1.Name = "AxToolbarControl1" Me.AxToolbarControl1.OcxState = CType(resources.GetObject("AxToolbarControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxToolbarControl1.Size = New System.Drawing.Size(184, 28) Me.AxToolbarControl1.TabIndex = 0 ' 'AxPageLayoutControl1 ' Me.AxPageLayoutControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.AxPageLayoutControl1.Location = New System.Drawing.Point(0, 56) Me.AxPageLayoutControl1.Name = "AxPageLayoutControl1" Me.AxPageLayoutControl1.OcxState = CType(resources.GetObject("AxPageLayoutControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxPageLayoutControl1.Size = New System.Drawing.Size(672, 360) Me.AxPageLayoutControl1.TabIndex = 1 ' 'AxLicenseControl1 ' Me.AxLicenseControl1.Enabled = True Me.AxLicenseControl1.Location = New System.Drawing.Point(56, 24) Me.AxLicenseControl1.Name = "AxLicenseControl1" Me.AxLicenseControl1.OcxState = CType(resources.GetObject("AxLicenseControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxLicenseControl1.Size = New System.Drawing.Size(32, 32) Me.AxLicenseControl1.TabIndex = 2 ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(200, 8) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(128, 23) Me.Button1.TabIndex = 3 Me.Button1.Text = "Select Text Symbol" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(336, 8) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(256, 20) Me.TextBox1.TabIndex = 4 Me.TextBox1.Text = "TextElement with selected TextSymbol" ' 'ComboBox1 ' Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.ComboBox1.Location = New System.Drawing.Point(600, 8) Me.ComboBox1.Name = "ComboBox1" Me.ComboBox1.Size = New System.Drawing.Size(64, 21) Me.ComboBox1.TabIndex = 5 ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(336, 32) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(296, 16) Me.Label1.TabIndex = 6 Me.Label1.Text = "2) Right click on the display to add a text element" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(197, 32) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(296, 16) Me.Label2.TabIndex = 7 Me.Label2.Text = "1) Select a text symbol " ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(672, 414) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.ComboBox1) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.AxLicenseControl1) Me.Controls.Add(Me.AxPageLayoutControl1) Me.Controls.Add(Me.AxToolbarControl1) Me.Controls.Add(Me.Label2) Me.Name = "Form1" Me.Text = "Change Text Symbol" CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) Me.PerformLayout() End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Set buddy control AxToolbarControl1.SetBuddyControl(Me.AxPageLayoutControl1) 'Add ToolbarControl items AxToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand") AxToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool") AxToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool") AxToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand") AxToolbarControl1.AddItem("esriControls.ControlsSelectTool") 'Add values for the text size to the combo box ComboBox1.Items.Add("8pt") ComboBox1.Items.Add("10pt") ComboBox1.Items.Add("12pt") ComboBox1.Items.Add("14pt") ComboBox1.SelectedIndex = 0 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Create a new SymbolForm Dim symbolForm As Form2 = New Form2 'Get the IStyleGalleryItem that has been selected in the SymbologyControl Dim styleGalleryItem As IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassTextSymbols) If styleGalleryItem Is Nothing Then Exit Sub 'Set the TextSymbol m_textSymbol = CType(styleGalleryItem.Item, ITextSymbol) 'Release the SymbolForm symbolForm.Dispose() End Sub Private Sub AxPageLayoutControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent) Handles AxPageLayoutControl1.OnMouseDown 'Check if the right button of the mouse was clicked If e.button <> 2 Then Exit Sub 'Ensure a label style has been selected If m_textSymbol Is Nothing Then Exit Sub 'Create a point and set its coordinates Dim point As IPoint = New PointClass point.X = e.pageX point.Y = e.pageY 'Create a text element Dim textElement As ITextElement = New TextElementClass textElement.Text = TextBox1.Text 'Set the size of the text If ComboBox1.SelectedItem = ("8pt") Then m_textSymbol.Size = 8.0 ElseIf ComboBox1.SelectedItem = ("10pt") Then m_textSymbol.Size = 10.0 elseIf ComboBox1.SelectedItem = ("12pt") Then m_textSymbol.Size = 12.0 ElseIf ComboBox1.SelectedItem = ("14pt") Then m_textSymbol.Size = 14.0 End If 'Set the TextElement symbol to that of the selected text symbol textElement.Symbol = m_textSymbol textElement.ScaleText = True 'QI to IElment Dim element As IElement element = textElement 'Set the TextElement's geometry element.Geometry = point 'Add the element to the GraphicsContainer AxPageLayoutControl1.ActiveView.GraphicsContainer.AddElement(element, 0) 'Refresh the PageLayout AxPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, Nothing) End Sub End Class