public static string InputBox(string Prompt, string Title = "", string DefaultResponse = "", int XPos = -1, int YPos = -1) { IWin32Window parentWindow = null; IVbHost vBHost = HostServices.VBHost; if (vBHost != null) { parentWindow = vBHost.GetParentWindow(); } if (Title.Length == 0) { if (vBHost == null) { Title = GetTitleFromAssembly(Assembly.GetCallingAssembly()); } else { Title = vBHost.GetWindowTitle(); } } if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { return(InternalInputBox(Prompt, Title, DefaultResponse, XPos, YPos, parentWindow)); } InputBoxHandler handler = new InputBoxHandler(Prompt, Title, DefaultResponse, XPos, YPos, parentWindow); Thread thread = new Thread(new ThreadStart(handler.StartHere)); thread.Start(); thread.Join(); if (handler.Exception != null) { throw handler.Exception; } return(handler.Result); }
public static MsgBoxResult MsgBox(object Prompt, MsgBoxStyle Buttons = 0, object Title = null) { IWin32Window owner = null; string text = null; string titleFromAssembly; IVbHost vBHost = HostServices.VBHost; if (vBHost != null) { owner = vBHost.GetParentWindow(); } if ((((Buttons & 15) > MsgBoxStyle.RetryCancel) || ((Buttons & 240) > MsgBoxStyle.Information)) || ((Buttons & 0xf00) > MsgBoxStyle.DefaultButton3)) { Buttons = MsgBoxStyle.ApplicationModal; } try { if (Prompt != null) { text = (string)Conversions.ChangeType(Prompt, typeof(string)); } } catch (StackOverflowException exception) { throw exception; } catch (OutOfMemoryException exception2) { throw exception2; } catch (ThreadAbortException exception3) { throw exception3; } catch (Exception) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", new string[] { "Prompt", "String" })); } try { if (Title == null) { if (vBHost == null) { titleFromAssembly = GetTitleFromAssembly(Assembly.GetCallingAssembly()); } else { titleFromAssembly = vBHost.GetWindowTitle(); } } else { titleFromAssembly = Conversions.ToString(Title); } } catch (StackOverflowException exception4) { throw exception4; } catch (OutOfMemoryException exception5) { throw exception5; } catch (ThreadAbortException exception6) { throw exception6; } catch (Exception) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", new string[] { "Title", "String" })); } return((MsgBoxResult)MessageBox.Show(owner, text, titleFromAssembly, ((MessageBoxButtons)Buttons) & ((MessageBoxButtons)15), ((MessageBoxIcon)Buttons) & ((MessageBoxIcon)240), ((MessageBoxDefaultButton)Buttons) & ((MessageBoxDefaultButton)0xf00), ((MessageBoxOptions)Buttons) & ((MessageBoxOptions)(-4096)))); }