开发者

Change link without change the name

开发者 https://www.devze.com 2023-03-31 03:01 出处:网络
Is it possible to change link without changing the name? ex: linllabeltext.link = \"http://mylink.com/\";

Is it possible to change link without changing the name? ex:

linllabeltext.link = "http://mylink.com/";

doesn't work

and this change开发者_开发知识库 the name

linklabeltext.test = "http://mylink.com/"

change the test

I have added this function at click

Process.Start(linklabetext.text);

how?

full code:

private void (......)
{
.....
var name = result.name;
.......
labelLink1.text = name;
}

private void labelLink1_click....
{
Process.Start(labelLink1.text);
}

but this code change the name of labelLink1 in a link es: http://mysate.com but the name of labelLink is Visit a Web Site


Take a look at the examples on MSDN. Specifically where they create the LinkLabel and set it's link(s) and text:

this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.linkLabel1.Text = "Register Online.  Visit Microsoft.  Visit MSN.";
if(this.linkLabel1.Text.Length >= 45)
{
    this.linkLabel1.Links[0].LinkData = "Register";
    this.linkLabel1.Links.Add(24, 9, "www.microsoft.com");
    this.linkLabel1.Links.Add(42, 3, "www.msn.com");
    //  The second link is disabled and will appear as red.
    this.linkLabel1.Links[1].Enabled = false;
}

I've never actually used this control before, but it appears that you set the .Text to any string and then set the "links" to correspond to substrings within the .Text property.

Edit: I just noticed that you're also using the wrong event for clicking on the link. You don't want to bind to the LinkLabel control's Click event. It has a LinkClicked event which puts more information in the event about the link being clicked. Take a look at, of course, the MSDN examples:

private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
    // Specify that the link was visited.
    this.linkLabel1.LinkVisited = true;

    // Navigate to a URL.
    System.Diagnostics.Process.Start("http://www.microsoft.com");
}


Dunno if it'll help or not, since I'm not completely sure what you're after, but here's a quick example of how to use a LinkLabel. Enter any valid url in the text box, click the link below it, and the url will be opened by calling Process.Start(). The text of the LinkLabel will not change, regardless of what url you enter. (Which I think is what you're after.)

Change link without change the name

0

精彩评论

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