using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace FCC_Uber_MDX_Configurator { public partial class AddStaticImageForm : Form { public GlobalStaticClass.FusionImage_StaticImage CurrentStaticImage; public AddStaticImageForm() { InitializeComponent(); InitializeSetup(); } public AddStaticImageForm(GlobalStaticClass.FusionImage_StaticImage input_GSI) { InitializeComponent(); CurrentStaticImage = new GlobalStaticClass.FusionImage_StaticImage(input_GSI._path, new Bitmap(input_GSI._image)); CurrentStaticImage._height = input_GSI._height; CurrentStaticImage._pages = new List(input_GSI._pages.ToArray()); CurrentStaticImage._width = input_GSI._width; CurrentStaticImage._x = input_GSI._x; CurrentStaticImage._y = input_GSI._y; CurrentStaticImage._z_order = input_GSI._z_order; InitializeSetup(); for (int i = 0; i < CHECKLIST_PAGES.Items.Count; i++) { int _pageParse = -1; if (int.TryParse(CHECKLIST_PAGES.Items[i].ToString(), out _pageParse)) { CHECKLIST_PAGES.SetItemChecked(i, CurrentStaticImage._pages.Contains(_pageParse - 1)); } } UpdateForm(); } private void InitializeSetup() { CHECKLIST_PAGES.Items.Clear(); for (int i = 0; i < GlobalStaticClass._Global_List_Graphics_PageList.Count; i++) { CHECKLIST_PAGES.Items.Add(((int)(i + 1)).ToString()); } } #region Verify Textboxes Only get Number Inputs private void KeyDown_IsANumber(object sender, KeyEventArgs e) { if (!char.IsDigit((char)e.KeyValue) && e.KeyData != Keys.Back && e.KeyData != Keys.Left && e.KeyData != Keys.Right && e.KeyData != Keys.Decimal && e.KeyValue != 190 && !e.KeyCode.Equals(Keys.NumPad0) && !e.KeyCode.Equals(Keys.NumPad1) && !e.KeyCode.Equals(Keys.NumPad2) && !e.KeyCode.Equals(Keys.NumPad3) && !e.KeyCode.Equals(Keys.NumPad4) && !e.KeyCode.Equals(Keys.NumPad5) && !e.KeyCode.Equals(Keys.NumPad6) && !e.KeyCode.Equals(Keys.NumPad7) && !e.KeyCode.Equals(Keys.NumPad8) && !e.KeyCode.Equals(Keys.NumPad9)) { e.SuppressKeyPress = true; } if (e.KeyData == Keys.Decimal || e.KeyValue == 190) { if (sender == TXT_ZORDER) { if (TXT_ZORDER.Text.Contains(".")) { e.SuppressKeyPress = true; } } else { e.SuppressKeyPress = true; } } return; } #endregion #region Verify a Number is entered in TextBox private void Leave_VerifyTXTIsValid(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; double _tempDbl; if (!double.TryParse(_senderBox.Text, out _tempDbl)) { ErrorForm _tempErrorForm = new ErrorForm(_senderBox.Name, "The value you entered is not valid"); _tempErrorForm.ShowDialog(); _senderBox.Focus(); } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Unknown Error", "There was an unexpected untraceable error caught in the application. If you can reproduce this error, please let me know at FusionControlCentre@gmail.com"); _tempErrorForm.ShowDialog(); } } #endregion private void UpdateForm() { TXT_ORIGINALSIZE_WIDTH.Text = "???"; TXT_ORIGINALSIZE_HEIGHT.Text = "???"; BTN_SAVE.Enabled = false; if (CurrentStaticImage == null) { return; } if (CurrentStaticImage._image == null) { return; } if (CurrentStaticImage._image.Size.Width > PICT_PREVIEW.Size.Width || CurrentStaticImage._image.Size.Height > PICT_PREVIEW.Size.Height) { PICT_PREVIEW.BackgroundImageLayout = ImageLayout.Zoom; } else { PICT_PREVIEW.BackgroundImageLayout = ImageLayout.Center; } PICT_PREVIEW.BackgroundImage = CurrentStaticImage._image; TXT_ORIGINALSIZE_WIDTH.Text = CurrentStaticImage._image.Width.ToString(); TXT_ORIGINALSIZE_HEIGHT.Text = CurrentStaticImage._image.Height.ToString(); int show_x, show_y; TXT_SHOWSIZE_WIDTH.Text = CurrentStaticImage._width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentStaticImage._height.ToString(); if (int.TryParse(TXT_SHOWSIZE_WIDTH.Text, out show_x) && int.TryParse(TXT_SHOWSIZE_HEIGHT.Text, out show_y)) { if (show_x == 0 && show_y == 0) { TXT_SHOWSIZE_WIDTH.Text = CurrentStaticImage._image.Width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentStaticImage._image.Height.ToString(); } } else { TXT_SHOWSIZE_WIDTH.Text = CurrentStaticImage._image.Width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentStaticImage._image.Height.ToString(); } TXT_LOCATION_X.Text = CurrentStaticImage._x.ToString(); TXT_LOCATION_Y.Text = CurrentStaticImage._y.ToString(); TXT_ZORDER.Text = CurrentStaticImage._z_order.ToString(); BTN_SAVE.Enabled = true; } private void BTN_SAVE_Click(object sender, EventArgs e) { if (CurrentStaticImage == null) { (new ErrorForm("Invalid Static Image", "Image has not been fully setup")).ShowDialog(); return; } int loc_x = 0, loc_y = 0, width = 0, height = 0; float z = 0.0f; if (!int.TryParse(TXT_LOCATION_X.Text, out loc_x) || !int.TryParse(TXT_LOCATION_Y.Text, out loc_y) || !int.TryParse(TXT_SHOWSIZE_HEIGHT.Text, out height) || !int.TryParse(TXT_SHOWSIZE_WIDTH.Text, out width) || !float.TryParse(TXT_ZORDER.Text, out z)) { (new ErrorForm("Invalid Number", "A numeric input is invalid. Make sure that the location, size, and z-order inputs contain numbers only.")).ShowDialog(); return; } if (!(CHECKLIST_PAGES.CheckedIndices.Count > 0)) { (new ErrorForm("Invalid Page", "There must be at least 1 visible page selected.")).ShowDialog(); return; } List tempPages = new List(); for (int i = 0; i < CHECKLIST_PAGES.CheckedItems.Count; i++) { int _tempI = -1; if (int.TryParse(CHECKLIST_PAGES.CheckedItems[i].ToString(), out _tempI)) { tempPages.Add((int)(_tempI - 1)); } } CurrentStaticImage._x = loc_x; CurrentStaticImage._y = loc_y; CurrentStaticImage._width = width; CurrentStaticImage._height = height; CurrentStaticImage._z_order = z; CurrentStaticImage._pages = new List(tempPages.ToArray()); this.DialogResult = DialogResult.OK; } private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void BTN_LOADIMAGE_Click(object sender, EventArgs e) { AddImageForm _tempAIF = null; if (CurrentStaticImage != null) { if (CurrentStaticImage._image != null && CurrentStaticImage._path != null) { _tempAIF = new AddImageForm(CurrentStaticImage._image, CurrentStaticImage._path); } else { _tempAIF = new AddImageForm(); } } else { _tempAIF = new AddImageForm(); } if (_tempAIF.ShowDialog() == DialogResult.OK) { this.DialogResult = DialogResult.None; if (CurrentStaticImage == null) { CurrentStaticImage = new GlobalStaticClass.FusionImage_StaticImage(_tempAIF.IMAGE_PATH, _tempAIF.IMAGE_BITMAP); } else { CurrentStaticImage._image = _tempAIF.IMAGE_BITMAP; CurrentStaticImage._path = _tempAIF.IMAGE_PATH; } UpdateForm(); } this.DialogResult = DialogResult.None; } } }