/// <summary>
		/// Creates and returns a reference to a new message box with the specified name. The
		/// caller does not have to dispose the message box.
		/// </summary>
		/// <param name="name">The name of the message box</param>
		/// <returns>A new message box</returns>
		/// <remarks>If <c>null</c> is specified as the message name then the message box is not
		/// managed by the Manager and will be disposed automatically after a call to Show().
		/// Otherwise the message box is managed by MessageBoxExManager who will eventually
		/// dispose it.</remarks>
		public static MessageBoxEx CreateMessageBox(string name)
		{
			if (name == null)
				throw new ArgumentNullException("name", "'name' parameter cannot be null");

			if (s_messageBoxes.ContainsKey(name))
			{
				string err = string.Format("A MessageBox with the name {0} already exists.",name);
				throw new ArgumentException(err,"name");
			}

			var msgBox = new MessageBoxEx {Name = name};
			s_messageBoxes[name] = msgBox;

			return msgBox;
		}
        /// <summary>
        /// Creates a new message box with the specified name. If null is specified
        /// in the message name then the message box is not managed by the Manager and
        /// will be disposed automatically after a call to Show()
        /// </summary>
        /// <param name="name">The name of the message box</param>
        /// <returns>A new message box</returns>
        public static MessageBoxEx CreateMessageBox(string name)
        {
            if(name != null && _messageBoxes.ContainsKey(name))
            {
                string err = string.Format("A MessageBox with the name {0} already exists.",name);
                throw new ArgumentException(err,"name");
            }

            MessageBoxEx msgBox = new MessageBoxEx();
            msgBox.Name = name;
            if(msgBox.Name != null)
            {
                _messageBoxes[name] = msgBox;
            }

            return msgBox;
        }
Example #3
0
        public void RememberOkBox()
        {
            string       name   = "X";
            MessageBoxEx msgBox = MessageBoxExManager.CreateMessageBox(name);

            msgBox.Caption = name;
            msgBox.Text    = "Blah blah blah?";

            msgBox.AddButtons(MessageBoxButtons.YesNo);

            msgBox.SaveResponseText  = "Don't ask me again";
            msgBox.UseSavedResponse  = false;
            msgBox.AllowSaveResponse = true;

            //click the yes button when the dialog comes up
            ExpectModal(name, "ConfirmModalByYesAndRemember", true);

            Assert.AreEqual("Yes", msgBox.Show());

            ExpectModal(name, "DoNothing", false /*don't expect it, because it should use our saved response*/);
            msgBox.UseSavedResponse = true;
            Assert.AreEqual("Yes", msgBox.Show());
        }
		/// <summary>
		/// Gets the saved response for the specified message box
		/// </summary>
		/// <param name="msgBox">The message box whose saved response is to be retrieved</param>
		/// <returns>The saved response if exists, null otherwise</returns>
		internal static string GetSavedResponse(MessageBoxEx msgBox)
		{
			string msgBoxName = msgBox.Name;
			if (msgBoxName == null)
				return null;

			string result = null;
			if (s_savedResponses.ContainsKey(msgBoxName))
				result = s_savedResponses[msgBoxName];

			return result;
		}
		/// <summary>
		/// Set the saved response for the specified message box
		/// </summary>
		/// <param name="msgBox">The message box whose response is to be set</param>
		/// <param name="response">The response to save for the message box</param>
		internal static void SetSavedResponse(MessageBoxEx msgBox, string response)
		{
			if(msgBox.Name == null)
				return;

			s_savedResponses[msgBox.Name] = response;
		}
        /// <summary>
        /// Gets the saved response for the specified message box
        /// </summary>
        /// <param name="msgBox">The message box whose saved response is to be retrieved</param>
        /// <returns>The saved response if exists, null otherwise</returns>
        internal static string GetSavedResponse(MessageBoxEx msgBox)
        {
            string msgBoxName = msgBox.Name;
            if(msgBoxName == null)
            {
                return null;
            }

            if(_savedResponses.ContainsKey(msgBoxName))
            {
                return _savedResponses[msgBox.Name].ToString();
            }
            else
            {
                return null;
            }
        }