Scrolling MessageBox in C #

I am using Addin in VS2008, C # and I need messages to display (error messages and others).

I do not know the length of the messages, so I want to use a Scrollable MessageBox.

I found this article since 2007: Mike Gold on July 30, 2007.

http://www.c-sharpcorner.com/UploadFile/mgold/ScrollableMessageBox07292007223713PM/ScrollableMessageBox.aspx

Now, in 2011, any other good components? I want to evaluate several components.

Update:

another component, but older: MessageBoxExLib http://www.codeproject.com/KB/dialog/MessageBoxEx.aspx

Custom .NET Winforms mailbox. http://www.codeproject.com/KB/dialog/Custom_MessageBox.aspx

+3
c # scroll messagebox add-in
Jan 13 '11 at 15:44
source share
3 answers

Take this: FlexibleMessageBox - A flexible replacement for the .NET MessageBox

This is a proven class that easily replaces all of your uses of MessageBox.Show and allows you to get more features in a single class file that you can easily add to your project.

+6
Feb 25 '15 at 12:11
source share

I just implemented a simple form with a scrollable multi-line TextBox when I needed something similar to show the long status reports or exceptions detected by the application. You can change the borders, etc., to make it look like a shortcut if you want. Then just a new one and call its ShowDialog method or complete its creation in some static element like a MessageBox. As far as I know, the .NET team has not built anything more flexible than MessageBox.

EDIT FROM COMMENTS:

The code for creating a window with a text box that can be displayed using the static method is pretty simple. Although I generally donโ€™t like explicit requests for code, I will definitely be this time:

 public class SimpleReportViewer : Form { /// <summary> /// Initializes a new instance of the <see cref="SimpleReportViewer"/> class. /// </summary> //You can remove this constructor if you don't want to use the IDE forms designer to tweak its layout. public SimpleReportViewer() { InitializeComponent(); if(!DesignMode) throw new InvalidOperationException("Default constructor is for designer use only. Use static methods instead."); } private SimpleReportViewer(string reportText) { InitializeComponent(); txtReportContents.Text = reportText; } private SimpleReportViewer(string reportText, string reportTitle) { InitializeComponent(); txtReportContents.Text = reportText; Text = "Report Viewer: {0}".FormatWith(reportTitle); } /// <summary> /// Shows a SimpleReportViewer with the specified text and title. /// </summary> /// <param name="reportText">The report text.</param> /// <param name="reportTitle">The report title.</param> public static void Show(string reportText, string reportTitle) { new SimpleReportViewer(reportText, reportTitle).Show(); } /// <summary> /// Shows a SimpleReportViewer with the specified text, title, and parent form. /// </summary> /// <param name="reportText">The report text.</param> /// <param name="reportTitle">The report title.</param> /// <param name="owner">The owner.</param> public static void Show(string reportText, string reportTitle, Form owner) { new SimpleReportViewer(reportText, reportTitle).Show(owner); } /// <summary> /// Shows a SimpleReportViewer with the specified text, title, and parent form as a modal dialog that prevents focus transfer. /// </summary> /// <param name="reportText">The report text.</param> /// <param name="reportTitle">The report title.</param> /// <param name="owner">The owner.</param> public static void ShowDialog(string reportText, string reportTitle, Form owner) { new SimpleReportViewer(reportText, reportTitle).ShowDialog(owner); } /// <summary> /// Shows a SimpleReportViewer with the specified text and the default window title. /// </summary> /// <param name="reportText">The report text.</param> public static void Show(string reportText) { new SimpleReportViewer(reportText).Show(); } /// <summary> /// Shows a SimpleReportViewer with the specified text, the default window title, and the specified parent form. /// </summary> /// <param name="reportText">The report text.</param> /// <param name="owner">The owner.</param> public static void Show(string reportText, Form owner) { new SimpleReportViewer(reportText).Show(owner); } /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SimpleReportViewer)); this.txtReportContents = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // txtReportContents // this.txtReportContents.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtReportContents.Location = new System.Drawing.Point(13, 13); this.txtReportContents.Multiline = true; this.txtReportContents.Name = "txtReportContents"; this.txtReportContents.ReadOnly = true; this.txtReportContents.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txtReportContents.Size = new System.Drawing.Size(383, 227); this.txtReportContents.TabIndex = 0; // // SimpleReportViewer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(408, 252); this.Controls.Add(this.txtReportContents); this.Icon = Properties.Resources.some_icon; this.Name = "SimpleReportViewer"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; this.Text = "Report Viewer"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private TextBox txtReportContents; } 

Using:

 var message = GetSomeRidiculouslyLongMessage(); //assumes it called from inside another Form SimpleReportViewer.ShowDialog(message, "My Message", this); 

This particular implementation also supports displaying as a normal, non-dialog box using Show () method overloads.

+2
Jan 13 '11 at 16:56
source share

I searched for a scrollable mailbox for WPF and then found a MaterialMessageBox, which (in my opinion) looks like a nice alternative to FlexibleMessageBox for WPF. You can download it from GitHub here: https://github.com/denpalrius/Material-Message-Box or install it as a nuget package inside Visual Studio ( https://www.nuget.org/packages/MaterialMessageBox/ ).

The only problem I ran into was that you cannot use it from outside the main thread, so my solution was caused by the main thread and show a message from there: mainWindow.Dispatcher.Invoke(() => MaterialMessageBox.Show("message text"));

0
Oct 08 '17 at 17:57
source share



All Articles