using System; using System.Windows.Forms; using FastReport.Design; using FastReport.Utils; using FastReport.Forms; namespace FastReport { /// /// The class introduces some menu items specific to the TextObjectBase. /// public class TextObjectBaseMenu : BreakableComponentMenu { #region Fields /// /// The "Format" menu item. /// public ContextMenuItem miFormat; /// /// The "Allow Expressions" menu item. /// public ContextMenuItem miAllowExpressions; /// /// The "Hide Zeros" menu item. /// public ContextMenuItem miHideZeros; private SelectedTextBaseObjects textObjects; #endregion #region Private Methods private void miFormat_Click(object sender, EventArgs e) { using (FormatEditorForm form = new FormatEditorForm()) { form.TextObject = textObjects.First; if (form.ShowDialog() == DialogResult.OK) { textObjects.SetFormat(form.Formats); Change(); } } } private void miAllowExpressions_Click(object sender, EventArgs e) { textObjects.SetAllowExpressions(miAllowExpressions.Checked); Change(); } private void miHideZeros_Click(object sender, EventArgs e) { textObjects.SetHideZeros(miHideZeros.Checked); Change(); } #endregion Private Methods /// /// Initializes a new instance of the TextObjectBaseMenu /// class with default settings. /// /// The reference to a report designer. public TextObjectBaseMenu(Designer designer) : base(designer) { textObjects = new SelectedTextBaseObjects(designer); textObjects.Update(); MyRes res = new MyRes("ComponentMenu,TextObject"); miFormat = CreateMenuItem(168, res.Get("Format"), new EventHandler(miFormat_Click)); miAllowExpressions = CreateMenuItem(res.Get("AllowExpressions"), new EventHandler(miAllowExpressions_Click)); miHideZeros = CreateMenuItem(res.Get("HideZeros"), new EventHandler(miHideZeros_Click)); miAllowExpressions.BeginGroup = true; miAllowExpressions.CheckOnClick = true; miHideZeros.CheckOnClick = true; int insertPos = Items.IndexOf(miEdit) + 1; Items.Insert(insertPos, miFormat); insertPos = Items.IndexOf(miCut); Items.Insert(insertPos, miAllowExpressions); Items.Insert(insertPos + 1, miHideZeros); TextObjectBase obj = textObjects.First; bool enabled = !obj.HasRestriction(Restrictions.DontModify); miAllowExpressions.Enabled = enabled; miAllowExpressions.Checked = obj.AllowExpressions && enabled; miHideZeros.Enabled = enabled; miHideZeros.Checked = obj.HideZeros && enabled; } } }