예제 #1
0
        public void Use()
        {
            var messagebox = new MessageBox();

            messagebox.Name     = "消息框";
            messagebox.Position = "108,100";
            var btn = new Button();

            btn.Name     = "同意";
            btn.Position = "10,20";
            messagebox.Add(btn);
            var closeBtn = new Button();

            closeBtn.Name     = "取消";
            closeBtn.Position = "5,20";
            messagebox.Add(closeBtn);
            var lable = new Lable();

            lable.Name     = "我是消息!";
            lable.Position = "15,10";
            messagebox.Add(lable);

            Show(messagebox);
        }
예제 #2
0
 public static void Show(string text, MessageBoxCallBack callBack = null)
 {
     instace.Add(new MessageBoxContext(text, callBack));
 }
예제 #3
0
        private static void AddButtonsToForm(MessageBox msgBoxFrm, MessageBoxButtons buttons)
        {
            // Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
            int titleHeight = 0;// screenRectangle.Top - msgBoxFrm.Top;

               // var t = Type.GetType("Mono.Runtime");
               // if ((t != null))
               //     titleHeight = 25;

            switch (buttons)
            {
                case MessageBoxButtons.OK:

                    var but = new Button("OK");

                    but.MousePressedEvent += delegate { _state = DialogResult.OK; msgBoxFrm.Close(); };
                    msgBoxFrm.Add(but);
                    break;

                case MessageBoxButtons.YesNo:
                    var butyes = new Button("Yes");

                    butyes.MousePressedEvent += delegate { _state = DialogResult.Yes; msgBoxFrm.Close(); };
                    msgBoxFrm.Add(butyes);

                    var butno = new Button("No");

                    butno.MousePressedEvent += delegate { _state = DialogResult.No; msgBoxFrm.Close(); };
                    msgBoxFrm.Add(butno);
                    break;

                default:
                    throw new NotImplementedException("Only MessageBoxButtons.OK and YesNo supported at this time");
            }
        }
예제 #4
0
        public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            if (text == null)
                text = "";

            if (caption == null)
                caption = "";

            MessageBox mymb = new MessageBox(caption);

            mymb.mymb = mymb;

            // ensure we are always in a known state
            _state = DialogResult.None;

            // convert to nice wrapped lines.
            text = AddNewLinesToText(text);
            // get pixel width and height

            Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));

            SizeF textSize = graphics.MeasureString(text, SystemFonts.DefaultFont);

            textSize = new SizeF(textSize.Width * 3, textSize.Height * 1);
            // allow for icon
              //          if (icon != MessageBoxIcon.None)
            //                textSize.Width += SystemIcons.Question.Width;

            mymb.Size = new AssortedWidgets.Util.Size(textSize.Width + 50, textSize.Height + 100);

            //Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
            //int titleHeight = screenRectangle.Top - msgBoxFrm.Top;

            var lblMessage = new Label(text);

            var actualIcon = getMessageBoxIcon(icon);

            if (actualIcon == null)
            {
             //   lblMessage.Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN);
            }
            else
            {
             //   var iconPbox = new PictureBox
                {
              //      Image = actualIcon.ToBitmap(),
              //      Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN)
                };
              //  msgBoxFrm.Controls.Add(iconPbox);
            }

            mymb.Add(lblMessage);

            //mymb.Add(actualIcon);

            AddButtonsToForm(mymb, buttons);

            mymb.Pack();

            DialogManager.Instance.SetModalDialog(mymb);

            DialogResult answer = _state;

            return answer;
        }