none
coloring massage box in C# RRS feed

  • Question

  • Hi,

    I want to show some messages using one message box but I want to show each message in new line and with different color. this message contains string and variable. for example:

    "the number of employee is 12000"  that 12000 is the value of variable in my windows form application. how can I do it?

    thanks.

    Tuesday, December 26, 2017 7:22 AM

All replies

  • I am not familiar with everything that you can do in VBA but even if it is possible to do it, it will be easier to just create your own window (form or whatever) that you use as a message box.


    Sam Hobbs
    SimpleSamples.Info

    Tuesday, December 26, 2017 9:44 AM
  • Hi nadianaji,

    you are working with C#. so displaying the labels dynamically in windows form will the easiest solution.

    you can generate the labels dynamically and add it to form and then display the form to user.

    it is label so you can format with different colors as per your requirement.

    example code.

     private void button2_Click(object sender, EventArgs e)
            {
                InitializeComponent();
                int x = 20; int y = 70;
               
                for (int i = 0; i < 10; i++)
                {
                    
                    this.Controls.Add(new Label { Text = "I am label", Height = 20, Width = 100, Name = "lable" + i, BackColor = Color.White,ForeColor= Color.Black, Location = new Point(x, y) });               
                    y += 30;
                }
            }

    Output:

    below are some other ways to achieve the same requirement.

    A Custom Message Box

    Custom Message Box

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 27, 2017 1:56 AM
    Moderator
  • Hi nadianaji,

    >> want to show some messages using one message box but I want to show each message in new line and with different color

    For built-in MessageBox, it is impossible, we could not custom the MessageBox.

    For a workaround, we could try to implement our own MessageBox by Form.

    I suggest you refer links below:

    # How to customize message box

    https://stackoverflow.com/questions/3734796/how-to-customize-message-box

    # Color different parts of a RichTextBox string

    https://stackoverflow.com/questions/1926264/color-different-parts-of-a-richtextbox-string

    If you have any issue to achieve this, please feel free to let us know.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Tony---- Tuesday, January 2, 2018 9:00 AM
    Monday, January 1, 2018 9:24 AM