Beispiel #1
0
		public static string GetString(string title, string message, string initialText)
		{
			StringInputDlg sid = new StringInputDlg(title, message, initialText);
			sid.ShowDialog();
			string ret = sid.getResult();
			sid.Dispose();
			return ret;
		}
		private void mScaleMenuItem_Click(object sender, System.EventArgs e)
		{
			string percent = null;
			float pct = -1;
			StringInputDlg dlg = new StringInputDlg("Scale Form", "Enter a percentage to scale the form by", "100");
			if( dlg.ShowDialog(this) == DialogResult.OK )
			{
				percent = dlg.getResult();
			}
			dlg.Dispose();
			if( percent != null )
			{
				try
				{
					pct =   float.Parse(percent);
				}
				catch( FormatException )
				{
					MessageBox.Show(this, "ERROR!!", "Error with value entered ");
				}
			}
			float scale = pct/(float)100.0;
			if( pct > 20 )
			{
				Font newFont = new Font(this.Font.FontFamily, this.Font.SizeInPoints * scale);
				this.Font = newFont;
				this.ApplyAutoScaling();
			}
		}
Beispiel #3
0
        /// <summary>
        /// Prompt the user for input for a 'set' command
        /// </summary>
        /// <param name="input">The input string to operate on</param>
        /// <returns>empty string on cancel, 'SET' string when successful.</returns>
        public static string PromptForSetUserInput(string input)
        {
            string retVal = "";
            string msg = GetPromptUserMesage(input);
            string location = GetSetLocation(input);

            while (retVal == "")
            {
                StringBuilder rangeMsg = new StringBuilder(25);
                String userInputValue = "";
                int min = 0;
                int max = 0;
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(1-15)} )
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(0x1-0x15)} )
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter name of...":string(len=8)} ) maybe not this one.
                if (input.IndexOf("int", StringComparison.OrdinalIgnoreCase) > -1 &&
                    (GetHexRange(ref min, ref max, input, rangeMsg) || GetDecimalRange(ref min, ref max, input, rangeMsg)))
                {
                    string rangeMessage = rangeMsg.ToString();
                    NumberStyles style = rangeMessage.IndexOf('x') > 0 ? NumberStyles.HexNumber : NumberStyles.Integer;
                    string initialText = style == NumberStyles.HexNumber ? "0x" : "";
                    StringInputDlg dlg = new StringInputDlg(msg, rangeMessage, initialText);
                    int userVal = Int32.MinValue;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        userInputValue = dlg.getResult();
                        if (userInputValue.StartsWith("0x"))
                            userInputValue = userInputValue.Substring(2);

                        try
                        {
                            userVal = Int32.Parse(userInputValue, style);
                            if (userVal < min || userVal > max)
                            {
                                userVal = Int32.MinValue;
                                throw new Exception("Invalid input.");
                            }
                        }
                        catch (Exception e)
                        {
                            MainClass.ShowError(string.Format(
                                "Error with '{0}'. Value '{1}' is invalid for range {2}",
                                msg, userInputValue, rangeMessage));
                        }
                        if (userVal > Int32.MinValue)
                        {
                            retVal = string.Format("SET({0}, 0x{1:x})", location, userVal);
                        }
                    }
                    else
                    {
                        retVal = " "; // trigger us to leave the loop
                    }
                    dlg.Dispose();
                }
                else
                {
                    MainClass.ShowError("ERROR applying line: " + input);
                    retVal = null;
                }
            }
            return retVal;
        }