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 AddFontForm_SubFontHeightChooserForm : Form { public int _myHeight = 10; Bitmap _displayB, _displayORIGINAL; Color _clearColour = Color.Black; public AddFontForm_SubFontHeightChooserForm(int h, Bitmap i) { InitializeComponent(); _myHeight = h; TXT_HEIGHT.Text = _myHeight.ToString(); _displayORIGINAL = i; DrawNewHeight(_myHeight); } public bool DrawNewHeight(int inH) { if (inH <= 0 || inH > _displayORIGINAL.Height) { return false; } try { _displayB = new Bitmap(PICT_EXAMPLE.Width, inH); Graphics _g = Graphics.FromImage(_displayB); _g.DrawImageUnscaledAndClipped(_displayORIGINAL, new Rectangle(new Point(0, 0), new Size(PICT_EXAMPLE.Width, inH))); _g.Dispose(); //PICT_EXAMPLE.BackgroundImage = _displayB; //if (inH < PICT_EXAMPLE.Height) { Bitmap _show = new Bitmap(_displayORIGINAL.Width, PICT_EXAMPLE.Height); Graphics _showG = Graphics.FromImage(_show); _showG.Clear(_clearColour); float _scale = (float)PICT_EXAMPLE.Height / (float)inH; _showG.DrawImage(_displayB, new Rectangle(0, 0, (int)((float)PICT_EXAMPLE.Width * _scale), PICT_EXAMPLE.Height)); _showG.Dispose(); PICT_EXAMPLE.BackColor = _clearColour; PICT_EXAMPLE.BackgroundImageLayout = ImageLayout.None; PICT_EXAMPLE.BackgroundImage = _show; } PICT_EXAMPLE.Update(); return true; } catch (Exception e) { return false; } } #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; return; } if (e.KeyData == Keys.Decimal || e.KeyValue == 190) { if (sender == TXT_HEIGHT) { if (TXT_HEIGHT.Text.Contains(".")) { e.SuppressKeyPress = true; return; } } else { e.SuppressKeyPress = true; return; } } int _t = 1; string _2use = TXT_HEIGHT.Text; if (e.KeyData != Keys.Back) { _2use = TXT_HEIGHT.Text + ((char)e.KeyValue).ToString(); } else { if (_2use.Length > 1) { _2use = _2use.Remove(_2use.Length - 1); } else { return; } } if (int.TryParse(_2use, out _t)) { if (DrawNewHeight(_t)) { _myHeight = _t; } } 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 AddFontForm_SubFontHeightChooserForm_FormClosing(object sender, FormClosingEventArgs e) { if (_myHeight <= _displayORIGINAL.Height && _myHeight > 0) { this.DialogResult = DialogResult.OK; } else { e.Cancel = true; } } private void BTN_SAVE_Click(object sender, EventArgs e) { if (_myHeight <= _displayORIGINAL.Height && _myHeight > 0) { this.DialogResult = DialogResult.OK; } } private void PICT_EXAMPLE_Click(object sender, EventArgs e) { if (_clearColour == Color.Black) { _clearColour = Color.White; } else { _clearColour = Color.Black; } DrawNewHeight(_myHeight); } } }