1

Let's take an example from android. Assume you send a message to someone and after message was send you can see (for a few seconds) kind of notification on the screen like Your message was send.

enter image description here

That is exactly what I would like to find in Winform. In my Winform app user click on the button and I would like to make kind of UI response, show him a message for a few sec, like Button clicked.

How to do it?

P.S. Actually I tried to find out how to do it, but everything that I found is kind of notification on the screen at the right bottom corner. It is not actually what I am looking for. I need something like you can see on screenshot. This text should appear in the form, not on the corner of the screen.

P.S 2 Tooltip also not what I am looking for. Tooltip is something that binded close to the button(view). I need kind of general UI response. User click on buttons and instead to show him a dialog that force user to move his mouse and close the dialog, I need kind of softy message that disappear after a few sec.

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • 1
    have you **tried** anything so far? – Franz Gleichmann May 25 '20 at 10:58
  • 1
    @FranzGleichmann edited my question – Sirop4ik May 25 '20 at 11:01
  • What about tootips https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.tooltip?view=netcore-3.1 ? – Miamy May 25 '20 at 11:03
  • You can take this thing [here](https://stackoverflow.com/a/51435842/7444103), change the shape to whatever you like and set whatever text you need. It can also be shown on top of other controls. – Jimi May 25 '20 at 11:35
  • To draw Arcs, see [here](https://stackoverflow.com/a/54794097/7444103), [here](https://stackoverflow.com/a/56533229/7444103), or [here](https://stackoverflow.com/a/54139910/7444103)... – Jimi May 25 '20 at 11:49
  • @Sirop4ik Did you able to find a solution? If so, please answer your own question! – Meric Ozcan Dec 17 '22 at 17:49

2 Answers2

1

@Miamy's solution not a bad one, however you have to center text in notification box, and you don't need to use timer. Here the custom tooltip class which centers the tooltip text location and you can see the output below:

enter image description here

Moreover I added some coloring features along with default timer implementation.

class CustomToolTip : ToolTip
{

    public int SIZE_X = 500;
    public int SIZE_Y = 50;

    public CustomToolTip()
    {
        this.OwnerDraw = true;
        this.Popup += new PopupEventHandler(this.OnPopup);
        this.Draw += new DrawToolTipEventHandler(this.OnDraw);
    }

    string m_EndSpecialText;
    Color m_EndSpecialTextColor = Color.Black;

    public Color EndSpecialTextColor
    {
        get { return m_EndSpecialTextColor; }
        set { m_EndSpecialTextColor = value; }
    }

    public string EndSpecialText
    {
        get { return m_EndSpecialText; }
        set { m_EndSpecialText = value; }
    }

    private void OnPopup(object sender, PopupEventArgs e) // use this event to set the size of the tool tip
    {
        e.ToolTipSize = new Size(SIZE_X, SIZE_Y);
    }


    private void OnDraw(object sender, DrawToolTipEventArgs e) // use this event to customise the tool tip
    {
        Graphics g = e.Graphics;

        LinearGradientBrush b = new LinearGradientBrush(e.Bounds,
            Color.AntiqueWhite, Color.LightCyan, 45f);

        g.FillRectangle(b, e.Bounds);

        g.DrawRectangle(new Pen(Brushes.Black, 1), new Rectangle(e.Bounds.X, e.Bounds.Y,
            e.Bounds.Width - 1, e.Bounds.Height - 1));


        System.Drawing.Size toolTipTextSize = TextRenderer.MeasureText(e.ToolTipText, e.Font);

        g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Black,
            new PointF((SIZE_X - toolTipTextSize.Width)/2, (SIZE_Y - toolTipTextSize.Height) / 2)); 

        b.Dispose();
    }
}

You can call this tooltip as below code:

                CustomToolTip notifyError = new CustomToolTip();
                notifyError.Show("Please enter a number.", this, 100, 100, 2000);

Above code creates notification box at 100, 100 location for 2 seconds.

Meric Ozcan
  • 678
  • 5
  • 25
0

I need kind of softy message that disappear after a few sec.

I think the tooltips are what you are looking for. The idea is you can programmatically control where to show a tooltip and when to hide it.

Please start a new WinForms project. Add three buttons, ToolTip and Timer to the form. Write the next event handlers (and bind them to the corresponding components):

    private void button_Click(object sender, EventArgs e)
    {            
        toolTip1.Show(((Button)sender).Text + " is pressed", this, 300, 300);
        timer1.Enabled = true;
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Enabled = false;
        toolTip1.Hide(this);
    }

After demo starting you'll see a tooltip with certain text appearing at the same position for the 1 second.

Miamy
  • 2,162
  • 3
  • 15
  • 32