繁体   English   中英

在标签页内的列表中使字符串可单击

[英]Making a string clickable in the list inside tabpage

我正在一个标签页上。 在选项卡页面中,有一个列表,用于收集要显示的项目(它附在选项卡页面上)。 我正在尝试使添加到列表中的文件可单击,然后打开它们所在的目录。

我尝试了两种不同的方法。 我不能让他们工作。

方法一-创建一个链接标签,并附加System.Diagnostics.Process.Start(“ @” path“);然后将该链接标签添加到我的列表中。

方法二-仅使用字符串并使字符串可单击。

这是方法1的示例代码,我使用Microsoft例子对其进行了修改,以演示我的需要-此问题不仅在于它不起作用,而且仅将一项设置为可单击。

public Form1()
{
    this.linkLabel1 = new System.Windows.Forms.LinkLabel();

    this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);

    this.linkLabel1.Text = "Open folder";

    //Assume the list called ItemList is declared properly above
    //ItemList is attached to the tab page and whatever in it will be displayed item by item in seperated line.
    //I need to make them clickable.
    ItemList.Add(linkLabel1);
}

private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
    // Navigate to a URL.
    System.Diagnostics.Process.Start("@"path");
}

方法二

string item1 = "file.txt";
fullPath = Path.GetFullPath(item1);
string Link = String.Format("<a href=\"{0}\">Click here</a>", fullPath);
ItemList.Add(Link);

方法二的问题在于,它仅显示整个链接以href ....开头。

我可能还有其他工作要做,但假设我必须采用以下一种工作方式。.请帮助,谢谢。

您不能使列表中的值或字符串可单击,只能将控件作为用户在屏幕上可以看到的控件。 您必须重新考虑您的方法:用户将会看到什么,他会点击什么以及您当时想做什么。

另外,您根本不需要超链接来打开本地计算机上的文件或文件夹,因此LinkLabel可能不是最佳选择。 也许您最好选择一些更合适的东西,例如ListBox来列出您的文件名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM