Detailed introduction to realizing the tray effect in C#

黄舟
Release: 2017-03-01 10:54:21
Original
1378 people have browsed it


In the development of desktop programs, it is often considered to implement tray shortcut operations on the status bar. The implementation of tray programs is still relatively complicated in the API era. First, you can view its functions in MSDN details,

and then make complex settings according to the parameters it requires.
In the .NET era, MS encapsulates these troublesome details, and developers can easily control and operate the tray program. Now take a simple example as an example to illustrate:
1. Add notifyIcon control and contextMenuStrip control
2. Set its properties icon and contextMenuStrp properties. For the Icon property, you only need to select a tray icon, and contextMenuStrip is used for the first step of association. shortcut menu.
3. Add the SizeChanged event program of the form to call the tray when the form is minimized:
     

   if (this.WindowState == FormWindowState.Minimized)
            {
                this.Hide();        //可以要,也可以不要,取决于是否隐藏主窗体
                this.notifyIcon.Visible = true;
            }
Copy after login

4. Add the Click event of notifyIcon to open the shortcut menu item, or other changes Complex operating options, as needed.

    private void Form1_SizeChanged(object sender, EventArgs e)
        {
if (this.WindowState == FormWindowState.Minimized)
            {
this.Hide();
this.notifyIcon1.Visible = true;
            }
        }
private void notifyIcon1_Click(object sender, EventArgs e)
        {
this.contextMenuStrip1.Show(MousePosition.X,MousePosition.Y);
        }
Copy after login



# The above is the content of the C# tray program , for more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template