/// <summary> /// Use the same interface than the MessageBox. See the doc of the Message box. /// </summary> /// <returns>the dialog result as for the Message box</returns> public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, ref bool checkboxValue) { // create a message box ForgetableMessageBox messageBox = new ForgetableMessageBox(); // set the parameters messageBox.Text = caption; messageBox.messageLabel.Text = text; messageBox.setButtons(buttons); messageBox.setDefaultButtons(defaultButton); messageBox.setIcon(icon); messageBox.dontShowCheckBox.Checked = checkboxValue; // show the message box in modal state and get its result DialogResult result = messageBox.ShowDialog(owner); // put back the check state flag in the ref variable checkboxValue = messageBox.dontShowCheckBox.Checked; // and return the result return result; }
/// <summary> /// Use the same interface than the MessageBox. See the doc of the Message box. /// </summary> /// <returns>the dialog result as for the Message box</returns> public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, ref bool checkboxValue) { // create a message box ForgetableMessageBox messageBox = new ForgetableMessageBox(); // set the parameters messageBox.Text = caption; messageBox.messageLabel.Text = text; messageBox.setButtons(buttons); messageBox.setDefaultButtons(defaultButton); messageBox.setIcon(icon); messageBox.dontShowCheckBox.Checked = checkboxValue; // show the message box in modal state and get its result DialogResult result = messageBox.ShowDialog(owner); // put back the check state flag in the ref variable checkboxValue = messageBox.dontShowCheckBox.Checked; // and return the result return(result); }
private void ReplaceButton_Click(object sender, EventArgs e) { List <LayerBrick> layers = null; // check if the selection must be performed in the current selection // or in several layers if (this.inCurrentSelectionRadioButton.Checked) { // only one layer is selected layers = new List <LayerBrick>(1); // get the current selected layer because we will need it (normally it is never null) LayerBrick selectedLayer = (Map.Instance.SelectedLayer) as LayerBrick; if (selectedLayer != null) { layers.Add(selectedLayer); } } else { layers = new List <LayerBrick>(this.LayerCheckedListBox.CheckedIndices.Count); foreach (int index in this.LayerCheckedListBox.CheckedIndices) { layers.Add(mBrickOnlyLayerList[index]); } } // get the search and replace part number string searchingPartNumber = this.FindComboBox.SelectedItem as string; string replacementPartNumber = this.ReplaceComboBox.SelectedItem as string; // create the action Actions.Bricks.ReplaceBrick replaceAction = new Actions.Bricks.ReplaceBrick(layers, searchingPartNumber, replacementPartNumber, this.inCurrentSelectionRadioButton.Checked); // check if there was a budget limitation and if the user cancel the action bool canDoTheAction = true; if (Settings.Default.DisplayWarningMessageForBrickNotReplacedDueToBudgetLimitation && replaceAction.IsLimitedByBudget) { // if some brick cannot be replaced, display a warning message // use a local variable to get the value of the checkbox, by default we don't suggest the user to hide it bool dontDisplayMessageAgain = false; // display the warning message DialogResult result = ForgetableMessageBox.Show(BlueBrick.MainForm.Instance, Properties.Resources.ErrorMsgSomeBrickWereNotReplacedDueToBudgetLimitation, Properties.Resources.ErrorMsgTitleWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, ref dontDisplayMessageAgain); // set back the checkbox value in the settings (don't save the settings now, it will be done when exiting the application) Properties.Settings.Default.DisplayWarningMessageForBrickNotReplacedDueToBudgetLimitation = !dontDisplayMessageAgain; // change the action flag depending of the answer of the user canDoTheAction = (result == DialogResult.Yes); } // do the action if we should if (canDoTheAction) { Actions.ActionManager.Instance.doAction(replaceAction); } // close the window this.Close(); }
private bool exportAllImages(string fileName, ImageFormat choosenFormat) { // compute the column and row size depending on the selected area to export and the number of cells in the grid float columnWidthInStud = mSelectedAreaInStud.Width / (int)this.columnCountNumericUpDown.Value; float rowHeightInStud = mSelectedAreaInStud.Height / (int)this.rowCountNumericUpDown.Value; // get the image width, height and scale from the numeric updown int imageWidth = (int)(this.imageWidthNumericUpDown.Value); int imageHeight = (int)(this.imageHeightNumericUpDown.Value); double scalePixelPerStud = (double)(this.scaleNumericUpDown.Value); // create a fileInfo to get the filename and the extension separately FileInfo fileInfo = new FileInfo(fileName); int extensionIndex = fileInfo.FullName.LastIndexOf(fileInfo.Extension); string fileNameWithoutExtension = (extensionIndex >= 0 ? fileInfo.FullName.Remove(extensionIndex) : fileInfo.FullName) + "_"; // a variable to know if we should check for overriding files // we don't check if the warning message box was forgotten by user (which means he wants override) bool shouldCheckForExistingFile = Settings.Default.DisplayWarningMessageForOverridingExportFiles; // iterate on the grid of image to export for (int i = 0; i < this.columnCountNumericUpDown.Value; ++i) { for (int j = 0; j < this.rowCountNumericUpDown.Value; ++j) { // create the Bitmap and get the graphic context from it Bitmap image = new Bitmap(imageWidth, imageHeight, PixelFormat.Format24bppRgb); Graphics graphics = Graphics.FromImage(image); graphics.Clear(Map.Instance.BackgroundColor); graphics.SmoothingMode = SmoothingMode.Default; // the HighQuality let appears some grid line above the area cells graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingMode = CompositingMode.SourceOver; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; // this one need to be high else there's some rendering bug appearing with a lower mode, the scale of the stud looks not correct when zooming out. // define the area to draw depending on the current coordinates of the grid cell that we are exporting RectangleF areaInStud = new RectangleF(mSelectedAreaInStud.X + (columnWidthInStud * i), mSelectedAreaInStud.Y + (rowHeightInStud * j), columnWidthInStud, rowHeightInStud); // draw the bitmap Map.Instance.draw(graphics, areaInStud, scalePixelPerStud, false); Map.Instance.drawWatermark(graphics, areaInStud, scalePixelPerStud); // construct a filename for each image (if there's more than one image) string cellImageFileName = fileName; if ((this.columnCountNumericUpDown.Value > 1) || (this.rowCountNumericUpDown.Value > 1)) { cellImageFileName = fileNameWithoutExtension + MapData.Tools.AlphabeticIndex.ConvertIndexToHumanFriendlyIndex(i + 1, true) + MapData.Tools.AlphabeticIndex.ConvertIndexToHumanFriendlyIndex(j + 1, false) + fileInfo.Extension; } // check if the file already exist before overriding it if (shouldCheckForExistingFile && File.Exists(cellImageFileName)) { // use a local variable to get the value of the checkbox, by default we don't suggest the user to hide it bool dontDisplayMessageAgain = false; // display the warning message DialogResult result = ForgetableMessageBox.Show(this, Resources.ErrorMsgExportFileExists.Replace("&", cellImageFileName), Resources.ErrorMsgTitleWarning, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, ref dontDisplayMessageAgain); // set back the checkbox value in the settings (don't save the settings now, it will be done when exiting the application) Settings.Default.DisplayWarningMessageForOverridingExportFiles = !dontDisplayMessageAgain; shouldCheckForExistingFile = !dontDisplayMessageAgain; // we should continue with a Yes, goes to the next loop for a no, and stop iterating for a cancel if (result == DialogResult.Yes) { shouldCheckForExistingFile = false; } else if (result == DialogResult.No) { // special case, if the user check the don't show the message again, and click "no", we assume it's a "no" for all images, so do a cancel instead if (dontDisplayMessageAgain) { return(false); // operation was canceled } else { continue; } } else if (result == DialogResult.Cancel) { return(false); // operation was canceled } } // save the bitmap in a file image.Save(cellImageFileName, choosenFormat); } } // saving process ended successfully return(true); }