New features in C # - problems with links and link functions

I am new to C # and previously wrote only written programs in JavaScript, so it's easy on me!

I wrote an application launcher that reads a text file line by line. Each line is just the path to the program, for example. C: \ Users \ Jim \ Desktop \ Gravity.exe

So far, my program can successfully read each line and create a list of links. As expected, each link appears as a path.

The problem I am facing is that these links will not work. However, they will work if they all got the same fixed path. I would like each link to use the .Text property as the destination. (see comments “works” and “does not work” in my code below). The only error I get is "cannot find the file specified."

I would really appreciate any help with this, as I find C # is much more complicated than Javascript!

public partial class Form1 : Form
{
    private void Form1_Load(object sender, EventArgs e)   //on form load
    {
        int counter = 0;
        string line;
        string myfile = @"c:\users\matt\desktop\file.txt";

        // Read the file and display it line by line.
        System.IO.StreamReader file = new System.IO.StreamReader(myfile);
        while ((line = file.ReadLine()) != null)
        {
            //MessageBox.Show(line);   //check whats on each line

            LinkLabel mylinklabel = new LinkLabel();        //LinkLabel tells us the type of the object   e.g.  string mystring ="hello";
            mylinklabel.Text = line;
            this.Controls.Add(mylinklabel);
            mylinklabel.Location = new Point(0, 30 + counter * 30);

            mylinklabel.Click += new System.EventHandler(LinkClick);

            counter++;
        }
        file.Close();
    }

    private void LinkClick(object sender, System.EventArgs e)
    {
        //Process.Start(this.Text);  //doesn't work
        Process.Start(@"C:\Users\Jim\Desktop\gravity.exe");   //works
    }        
}

Update:

Thanks for your guys. I changed the corresponding line:

Process.Start(((LinkLabel)sender).Text); 

... and it really works. But perhaps I could ask a question about this line, as I find the syntax a bit unusual and confusing.

sender LinkLabel? , , LinkLabel.sender? ( JavaScript! (LinkLabel)sender)

:

private void LinkClick(object sender, System.EventArgs e)

? , object sender? System.EventArgs e? LinkClick - , , ?

, # !

.

+3
4

this.Text .

this . LinkLabel, . , sender .

, - .

LinkLabel lnk = sender as LinkLabel;
System.Diagnostics.Process.Start(lnk.Text);
+3

"this.Text" FORMS. ((LinkLabel) ).Text

0
private void LinkClick(object sender, System.EventArgs e)
{
    LinkLabel ll = (LinkLabel)sender;
    System.Diagnostics.Process.Start(ll.Text);
}
0
source

This example shows the best way to achieve this.

http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.linkclicked%28v=VS.100%29.aspx

 private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
        // Determine which link was clicked within the LinkLabel.
        this.linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true;

        // Display the appropriate link based on the value of the 
        // LinkData property of the Link object.
        string target = e.Link.LinkData as string;

        // If the value looks like a URL, navigate to it.
        // Otherwise, display it in a message box.
        if(null != target && target.StartsWith("www"))
        {
            System.Diagnostics.Process.Start(target);
        }
        else
        {    
            MessageBox.Show("Item clicked: " + target);
        }
    }
0
source