Пример #1
0
        public FrmToast(StartPosition2 startPosition, MessageType messageType, string title, string text, int hideAfterXmSec)
        {
            InitializeComponent();
            _hideAfterXmSec = hideAfterXmSec;

            switch (messageType)
            {
            case MessageType.Information:
                toastImage.Image = Properties.Resources.information;
                break;

            case MessageType.Warning:
                toastImage.Image = Properties.Resources.warning;
                break;

            case MessageType.Error:
                toastImage.Image = Properties.Resources.error;
                break;

            case MessageType.Confirmation:
                toastImage.Image = Properties.Resources.confirmation;
                break;
            }
            ;

            lbTitle.Text = title;
            lbText.Text  = text;

            var sz = new Size(lbText.Width, 500);

            sz            = TextRenderer.MeasureText(text, lbText.Font, sz, TextFormatFlags.WordBreak);
            lbText.Height = sz.Height;

            lbAppName.Text = Application.ProductName;
            lbAppName.Top  = lbText.Height + lbText.Top + 5;

            Height = lbAppName.Top + lbAppName.Height + 22;

            //todo: taskbar position and size ... https://stackoverflow.com/questions/1264406/how-do-i-get-the-taskbars-position-and-size
            switch (startPosition)
            {
            case StartPosition2.TopLeft:
                Location = new Point(10, 100);
                break;

            case StartPosition2.TopRight:
                Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 10 - this.Width, 100);
                break;

            case StartPosition2.BottomLeft:
                Location = new Point(10, Screen.PrimaryScreen.WorkingArea.Height - this.Height - 5);
                break;

            case StartPosition2.BottomRight:
                Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 10 - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height - 20);
                break;
            }
        }
Пример #2
0
        public static void ShowToastForm(StartPosition2 startPosition, MessageType messageType, string title, string message, int duration,
                                         Form parentForm)
        {
            var f = new FrmToast(startPosition, messageType, title, message, duration);

            f.Show();

            if (parentForm != null)
            {
                parentForm.Focus(); //https://stackoverflow.com/questions/156046/show-a-form-without-stealing-focus
            }
        }