Ejemplo n.º 1
0
        /// <summary>Displays a message box in front of the specified object and with the specified text, caption, buttons, and icon.</summary>
        public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            using (ShowText st = new ShowText())
            {
                st.Message = text;
                if (caption != null)
                {
                    st.Text = caption;
                }

                // Set the dialogbox/taskbar icon to the icon of the owning form.
                if (owner != null)
                {
                    Form f = owner as Form;
                    if (f == null)
                    {
                        Control c = owner as Control;
                        if (c != null)
                        {
                            f = c.FindForm();
                        }
                    }
                    if (f != null && f.Icon != null)
                    {
                        st.Icon = (Icon)f.Icon.Clone();
                    }
                }

                // Determine the MessageBoxIcon to use
                Icon iconInstance = null;
                switch (icon)
                {
                case MessageBoxIcon.Error:                      iconInstance = iconError;               break;

                case MessageBoxIcon.Information:        iconInstance = iconInformation; break;

                case MessageBoxIcon.Question:           iconInstance = iconQuestion;    break;

                case MessageBoxIcon.Warning:            iconInstance = iconWarning;             break;
                }
                if (iconInstance != null)
                {
                    System.Windows.Forms.PictureBox pb = new PictureBox();
                    pb.SizeMode = PictureBoxSizeMode.Normal;
                    pb.Size     = iconInstance.Size;
                    pb.Image    = iconInstance.ToBitmap();
                    pb.Location = new Point(st.textBox1.Left + 2, st.textBox1.Top + (st.textBox1.Height / 2) - (pb.Height / 2));
                    pb.Anchor   = AnchorStyles.Left;
                    int shiftAmount = pb.Size.Width + 5;
                    st.textBox1.Left  += shiftAmount;
                    st.textBox1.Width -= shiftAmount;
                    st.Controls.Add(pb);
                }

                // Show the DialogBox.

                DialogResult dr = st.ShowDialog(owner);
                return(dr);
            }
        }
Ejemplo n.º 2
0
        private void btnSystemInfo_Click(object sender, System.EventArgs e)
        {
            string wininfoexe     = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), @"Microsoft Shared\MSInfo\msinfo32.exe");         //C:\Program Files\Common Files\
            string consoleinfoexe = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "SystemInfo.exe");

            if (System.IO.File.Exists(wininfoexe))
            {
                Process.Start(wininfoexe);
            }
            else if (System.IO.File.Exists(consoleinfoexe))
            {
                ProcessStartInfo psi = new ProcessStartInfo(consoleinfoexe);
                psi.CreateNoWindow         = true;
                psi.ErrorDialog            = false;
                psi.RedirectStandardError  = false;
                psi.RedirectStandardOutput = true;
                psi.WindowStyle            = ProcessWindowStyle.Hidden;
                psi.WorkingDirectory       = Environment.GetFolderPath(Environment.SpecialFolder.System);
                psi.UseShellExecute        = false;

                Process proc = System.Diagnostics.Process.Start(psi);
                string  text = proc.StandardOutput.ReadToEnd();
                ShowText.Show(this, text);
            }
            else
            {
                MessageBox.Show("System Information can not be displayed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Show a messagebox showing the specified exception.</summary>
        /// <remarks>Uses <see cref="ShowText"/> to display the exception text and stacktrace information</remarks>
        public static void ExceptionMessageBox(Form parentform, Exception ex)
        {
            string        stackTrace = ex.StackTrace;
            StringBuilder sb         = new StringBuilder("Exception thrown:");

            do
            {
                sb.Append(Environment.NewLine);
                sb.Append(ex.Message);
                ex = ex.InnerException;
            } while (ex != null);
            sb.Append(Environment.NewLine);
            sb.Append(stackTrace);
            sb.Replace("\x0D", "");                  // Remove all CR chars
            sb.Replace("\x0A", Environment.NewLine); // Replace all LF chars with the NewLine string.
            ShowText.Show(parentform, sb.ToString(), parentform == null ? "Exception" : parentform.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 4
0
 public static void ShowMessage(string s, string caption)
 {
     ShowText.Show(s, caption);
 }
Ejemplo n.º 5
0
 public static void ShowMessage(string s)
 {
     ShowText.Show(s);
 }