none
How to create a popup notification without forms in VSTA? RRS feed

  • Question

  • I am trying to create a notification - similar to a message box, but with no interaction from the user. (it just displays onscreen)  I have several applications that have APIs for such a function - usually it's just called "notify".

    To take that one step farther, I'd also like a second notification, but one that allows copying and pasting from an onscreen text box. (I don't want to have to call NotePad, but I could)  Again, no created form, just out of the box, if possible.  If this isn't possible, I can copy the output programatically to the clipboard - but I'd still want that "dumb" notification.

    Is this possible with the .NET framework?  I'd like to avoid building any additional dependencies.  I'm using .NET framework 4.5 in Windows 10.

    Thanks in advance.

    Wednesday, March 11, 2020 5:20 AM

All replies

  • Hi MHan7,

    Thank you for posting here.

    What does a popup notification without a form mean, does it mean that only a small icon appears?

    If so, please refer to the following code.

     public partial class Form1 : Form
        {
            private NotifyIcon notifyIcon1;
            private ContextMenu contextMenu1;
            private MenuItem menuItem1;
            public Form1()
            {
                InitializeComponent();
                this.components = new Container();
                this.contextMenu1 = new ContextMenu();
                this.menuItem1 = new MenuItem();
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
               
                // Initialize contextMenu1
                this.contextMenu1.MenuItems.AddRange(
                            new MenuItem[] { this.menuItem1 });
    
                // Initialize menuItem1
                this.menuItem1.Index = 0;
                this.menuItem1.Text = "E&xit";
                this.menuItem1.Click += new EventHandler(this.menuItem1_Click);
    
                // Set up how the form should be displayed.
                this.ClientSize = new Size(292, 266);
                this.Text = "Notify Icon Example";
    
                // Create the NotifyIcon.
                this.notifyIcon1 = new NotifyIcon(this.components);
    
                // The Icon property sets the icon that will appear
                // in the systray for this application.
                notifyIcon1.Icon = new Icon(@"D:\Test\image\111.ico");
    
                // The ContextMenu property sets the menu that will
                // appear when the systray icon is right clicked.
                notifyIcon1.ContextMenu = this.contextMenu1;
    
                // The Text property sets the text that will be displayed,
                // in a tooltip, when the mouse hovers over the systray icon.
                notifyIcon1.Text = "Form1 (NotifyIcon example)";
                notifyIcon1.Visible = true;
    
                // Handle the DoubleClick event to activate the form.
            }
    
            private void menuItem1_Click(object Sender, EventArgs e)
            {
                // Close the form, which closes the application.
                this.Close();
            }

    If my understanding is wrong, please describe your request in detail, I am a little confused.

    Best Regards,

    Timon


    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, March 11, 2020 6:30 AM
  • Hello friend

    var notification = new System.Windows.Forms.NotifyIcon()
    {
        Visible = true,
        Icon = System.Drawing.SystemIcons.Information,
        // optional - BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info,
        // optional - BalloonTipTitle = "My Title",
        BalloonTipText = "My long description...",
    };
    
    // Display for 5 seconds.
    notification.ShowBalloonTip(5000);
    
    // This will let the balloon close after it's 5 second timeout
    // for demonstration purposes. Comment this out to see what happens
    // when dispose is called while a balloon is still visible.
    Thread.Sleep(10000);
    
    // The notification should be disposed when you don't need it anymore,
    // but doing so will immediately close the balloon if it's visible.
    notification.Dispose();

    Follow the link

    https://stackoverflow.com/questions/13373060/show-a-balloon-notification

    Wednesday, March 11, 2020 10:51 AM
  • Yeah, that's fantastic.  There are only 2 small issues with this:

    1) it appears down by the system tray, rather than in the extents of the application window (that it applies to)

    2) there seems to be a limit to how many characters I can put in the notification. (and I'd like to change that)


    • Edited by MHan7 Wednesday, March 11, 2020 5:11 PM
    Wednesday, March 11, 2020 5:11 PM
  • Hi MHan7,

    See the documentation provided by Microsoft.

    NotifyIcon Class

    1. The location of the notification is fixed, there seems to be no way to modify its location.

    2. There is no limit to the number of characters, but the size of the notification is fixed. If there are too many characters, it can only display a part.

    In addition to "NotifyIcon", you can also use "Tulpep.NotificationWindow". It can't adjust the notification position, but it can adjust the size.

    The only problem is that it is a third party Nuget package.

    I will provide a code example for you, you decide whether to use it.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using Tulpep.NotificationWindow;
    
    namespace WindowsFormsApp3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                PopupNotifier popup = new PopupNotifier();
                popup.TitleText = "BE HAPPY";
                popup.ContentText = "Thank you";
                popup.Size = new Size(300, 500);
                popup.Popup();// show  
             
            }
        }
    }
    

    Best Regards,

    Timon


    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.

    Thursday, March 12, 2020 3:46 AM
  • Highly level,

    Since Notification components are geared to show in the lower right corner of the desktop it seem prudent to come up with a custom form to do what you want. Actually, one for displaying and another for providing the copying information.

    Thinking of how a web app would do this is with a setTimeout method were in your code it would be a timer or await Task.Delay.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, March 12, 2020 9:31 PM
    Moderator