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); }
/// <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) { 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 { ShowError("ERROR applying line: " + input); retVal = null; } } return(retVal); }