/// <summary> /// Prompts the user to enter some text.<para/> /// This essentially does InputBox's job but much prettier. /// </summary> /// <param name="prompt">The prompt text to display to the user.</param> /// <param name="title">The title of the prompt to show.</param> /// <param name="defaultValue">The default value in the prompt box. This will be selected initially.</param> /// <param name="captionImage">An image to show in the dialog, or null to show no message.</param> /// <returns>Returns the text entered by the user, or null if the user cancelled the interaction.</returns> public static string EnterText(string prompt, string title, string defaultValue = "", Image captionImage = null) { EnterTextDialog dialog = new EnterTextDialog(title, prompt, defaultValue, captionImage); if (dialog.ShowDialog() == DialogResult.OK) { return(dialog.Value); } else { return(null); } }
// add a page to the document private void pageToolStripMenuItem_Click(object sender, EventArgs e) { string pageName = EnterTextDialog.EnterText("Enter a name for the new page.", "New Page", CreateResourceName("Page"), Properties.Resources.Page32); if (pageName != null) { Page page = new Page() { Name = pageName }; AddResource(page); OpenResourceEditor(page); } }
// add an equation to the document private void equationToolStripMenuItem_Click(object sender, EventArgs e) { string equationName = EnterTextDialog.EnterText("Enter a name for the new equation.", "New Equation", CreateResourceName("Equation"), Properties.Resources.Equation32); if (equationName != null) { Equation equation = new Equation() { Name = equationName }; AddResource(equation); OpenResourceEditor(equation); } }
private void duplicateToolStripMenuItem_Click(object sender, EventArgs e) { Resource resource = SelectedResource; if (resource != null) { string newResourceName = EnterTextDialog.EnterText( String.Format("Enter a name for the duplicate of {0}.", resource.Name), "Duplicate", String.Format("Copy of {0}", resource.Name), resource.GetResourceIcon(true)); if (newResourceName != null) { OpenResourceEditor(DuplicateResource(resource, newResourceName)); } } }
private void renameToolStripMenuItem_Click(object sender, EventArgs e) { Resource resource = SelectedResource; if (resource != null) { Image captionImage = resource.GetResourceIcon(true); string newName = EnterTextDialog.EnterText("Enter a new name for this resource.", "Rename", resource.Name, captionImage); if (newName != null) { resource.Name = newName; DocumentModified = true; RefreshResourceListView(); NotifyResourceModified(resource); } } }
// add a data set to the document private void dataSetToolStripMenuItem_Click(object sender, EventArgs e) { string dataSetName = EnterTextDialog.EnterText("Enter a name for the new data set.", "New Data Set", CreateResourceName("Data Set"), Properties.Resources.DataSet32); if (dataSetName != null) { DataSet dataSet = new DataSet(Properties.Settings.Default.DefaultDataSetVariables) { Name = dataSetName }; DataSetCreator creator = new DataSetCreator(dataSet); if (creator.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DialogResult = System.Windows.Forms.DialogResult.None; AddResource(dataSet); OpenResourceEditor(dataSet); } } }