-
프로그램 종료시 트레이 아이콘도 같이 삭제되도록하는 코드프로그램(C# etc.) 2023. 1. 16. 14:53
다음은 알림을 처리하는 방법에 대한 예입니다프로그램이 종료될 때 아이콘 개체:
using System; using System.Windows.Forms; class MyForm : Form { NotifyIcon notifyIcon1 = new NotifyIcon(); public MyForm() { // ... code to create and configure the NotifyIcon ... // Add a context menu to the icon notifyIcon1.ContextMenuStrip = new ContextMenuStrip(); notifyIcon1.ContextMenuStrip.Items.Add("Exit"); notifyIcon1.ContextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(ContextMenuStrip_ItemClicked); } private void ContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Text == "Exit") { // Dispose the NotifyIcon before exiting the program notifyIcon1.Dispose(); Application.Exit(); } } // Alternatively, you can dispose the NotifyIcon in the FormClosing event protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); notifyIcon1.Dispose(); } }
이 예에서는 알림상황에 맞는 메뉴의 "Exit" 항목을 클릭하면 아이콘 개체가 처리됩니다. 통지에서 Dispose() 메서드가 호출됩니다알림에 사용되는 리소스를 해제하는 Icon1 개체아이콘.
또는 알림을 삭제할 수 있습니다Form 클래스의 OnFormClosing 메서드를 재정의하고 해당 클래스에서 Dispose() 메서드를 호출하여 FormClosing 이벤트의 아이콘 개체입니다.
알림을 폐기하는 것이 중요합니다메모리 누수 또는 기타 문제를 방지하기 위해 프로그램이 종료될 때 아이콘 개체입니다.'프로그램(C# etc.)' 카테고리의 다른 글
창최소화 이벤트 코드 (0) 2023.01.16 this.ShowInTaskbar = true; 이후에 포커싱 주는 코드 (0) 2023.01.16 프로그램 시작되면서 트레이 아이콘으로 시작하는 코드 (0) 2023.01.16 NotifyIcon 등록방법 설명해줘 (0) 2023.01.16 동일한 프로그램이 동시에 2개가 켜지지 않도록하는 c# 코드 (0) 2023.01.16