开发者

How to insert link in notification using C#?

开发者 https://www.devze.com 2023-04-08 09:58 出处:网络
I am developing an application to watch file changes in folder and display notification to users.This function is OK.But I have a difficult to insert link(file directory) in notification.As this link

I am developing an application to watch file changes in folder and display notification to users.This function is OK.But I have a difficult to insert link(file directory) in notification.As this link is need to open watched folder.

Can anyone suggest how this could be implemented?

code:

watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);

private void OnChanged(object source, FileSystemEventArgs e)
{
    this.notifyIcon1.ShowBalloonTip(1, "File " + e.ChangeType, e.FullPath, ToolTipIcon.Info);            
}
private void OnRenamed(object source, RenamedEventArgs e)
{
    this.notifyIcon1.ShowBalloonTip(1, "File Renamed", e.OldFullPath + " renamed to " + e.FullPath, ToolTipIcon.Info);
}

I would like to display file directory of [e.FullPath] as link in notification(except e.Name). eg. e.FullPath -> C:\TEMP\test.txt, e.Name -> test.txt I want to display [C:\TEMP] as link.

Thanks all for suggesting.That difficult is OK now.If click notification, open watched folder.

My code:

this.notifyIcon1.BalloonTipClicked += new System.EventHandler(this.linkLabel_L开发者_如何学运维inkClick);

private void linkLabel_LinkClick(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start(C:\TEMP\test.txt);            
}


If you are using MessageBox for notifications, then you need to implement your own form and put whatever you need on it, like LinkLabel as Jake suggested.

And the desired location can be opened by putting the following code into LinkClicked eventhandler (assuming the text of your link is the location you want to open):

System.Diagnostics.Process.Start(linkLabel1.Text);


Assuming you want to let the user click a link in the notification that opens the path in Explorer, here's one way to do it.

  1. Add a LinkLabel to the notification window.
  2. Create a LinkLabel.Link object in the code behind that stores the desired path.
  3. Set up a handler for the LinkLabel's LinkClicked event and make a call to open Explorer to the path in the Link.
// step 2 -- implement where you have access to the desired path
linkLabel1.Links.Add(new LinkLabel.Link(0, 0, "C:\\"));

// step 3 -- open the path in Explorer
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消