프로그램(C# etc.)
NotifyIcon 등록방법 설명해줘
질문폭격
2023. 1. 16. 14:46
다음은 통지를 작성하고 사용하는 방법에 대한 예입니다C#의 아이콘:
먼저 알림을 추가해야 합니다Visual Studio의 도구 상자에서 끌거나 알림의 새 인스턴스를 만들어 양식에 대한 아이콘 개체코드의 아이콘 클래스입니다.
그런 다음 알림의 아이콘 속성을 설정해야 합니다알림 영역에 표시할 아이콘에 대한 아이콘 개체입니다. 기존 아이콘 파일을 사용하거나 아이콘 편집기를 사용하여 새 아이콘을 만들 수 있습니다.
알림의 표시 속성 설정아이콘 개체가 true이므로 아이콘이 알림 영역에 표시됩니다.
마우스가 아이콘 위로 이동할 때 도구 설명을 표시하도록 텍스트 속성을 설정할 수도 있습니다.
코드의 예는 다음과 같습니다:
using System;
using System.Windows.Forms;
class MyForm : Form
{
NotifyIcon notifyIcon1 = new NotifyIcon();
public MyForm()
{
// Set the icon to display in the notification area
notifyIcon1.Icon = new Icon("myicon.ico");
// Set the text to display in the tooltip
notifyIcon1.Text = "My Program";
// Make the icon visible
notifyIcon1.Visible = true;
}
}
알림의 ContextMenuStrip 속성을 설정할 수도 있습니다ContextMenuStrip 개체에 대한 아이콘 개체로, 사용자가 아이콘을 마우스 오른쪽 단추로 클릭하면 이전 예에서 보듯이 상황에 맞는 메뉴가 표시됩니다.
또한 알림의 마우스 클릭 이벤트도 처리할 수 있습니다아이콘을 클릭할 때 특정 작업을 수행하는 아이콘입니다.
notifyIcon1.MouseClick += new MouseEventHandler(notifyIcon1_MouseClick);
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Perform an action when the left mouse button is clicked
}
else if (e.Button == MouseButtons.Right)
{
// Perform an action when the right mouse button is clicked
}
}
아이콘 작업을 마치면 알림을 삭제해야 합니다아이콘 개체가 사용하는 리소스를 해제합니다.