Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Add a custom string property to a linklabel?Dear all I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms. I am currently making an "app launcher" which reads a text file line by line.

View previous topic View next topic Go down 
AuthorMessage
Joost
Member
Member
Joost

Posts : 3
Join date : 2011-05-11

Add a custom string property to a linklabel?Dear all  I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms.  I am currently making an "app launcher" which reads a text file line by line.  Empty
PostSubject: Add a custom string property to a linklabel?Dear all I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms. I am currently making an "app launcher" which reads a text file line by line.    Add a custom string property to a linklabel?Dear all  I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms.  I am currently making an "app launcher" which reads a text file line by line.  EmptyWed May 11, 2011 11:39 pm

Dear all

I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms.

I am currently making an "app launcher" which reads a text file line by line. Each line is a path to a useful program somewhere else on my pc. A link label is automatically made for each path (i.e. each line) in the text file.

I would like the .Text property of the link label to be an abbreviated form of the path (i.e. just the file name, not the whole path). I have found out how to shorten the string in this way (so far so good !)

However, I would also like to store the full path somewhere - as this is what my linklabel will need to link to. In Javascript I could pretty much just add this property to linklabel like so: mylinklabel.fullpath=line; (where line is the current line as we read through the text file, and fullpath is my "custom" property that I would like to try and add to the link label. I guess it needs declaring, but I am not sure how.

Below is the part of my code which creates the form, reads the text file line by line and creates a link label for the path found on each line:

Code:

 private void Form1_Load(object sender, EventArgs e)  //on form load
        {
            http://System.Console.WriteLine("hello!");
            int counter = 0;
            string line;
            string filenameNoExtension;
            string myfile = @"c:\\users\matt\desktop\file.txt";

            //string filenameNoExtension = Path.GetFileNameWithoutExtension(myfile);


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


                LinkLabel mylinklabel = new LinkLabel();
                filenameNoExtension = Path.GetFileNameWithoutExtension(line);  //shortens the path to just the file name without extension
                mylinklabel.Text = filenameNoExtension;
                //string fullpath=line;        //doesn't work
                http://mylinklabel.fullpath=line;  //doesn't work
                mylinklabel.Text = filenameNoExtension;  //displays the shortened path
                this.Controls.Add(mylinklabel);
                mylinklabel.Location = new Point(0, 30 + counter * 30);
                mylinklabel.AutoSize = true;
                mylinklabel.VisitedLinkColor = System.Drawing.Color.White;
                mylinklabel.LinkColor = System.Drawing.Color.White;



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

               
                counter++;
            }

            file.Close();

        }

So, how can I store a full path as a string inside the linklabel for use in my onclick function later on?
Back to top Go down
Skilletrockz
Super Moderator
Super Moderator
Skilletrockz

Posts : 45
Join date : 2011-05-11

Add a custom string property to a linklabel?Dear all  I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms.  I am currently making an "app launcher" which reads a text file line by line.  Empty
PostSubject: Re: Add a custom string property to a linklabel?Dear all I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms. I am currently making an "app launcher" which reads a text file line by line.    Add a custom string property to a linklabel?Dear all  I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms.  I am currently making an "app launcher" which reads a text file line by line.  EmptyWed May 11, 2011 11:40 pm

A couple ways you can do it:

1. You could use the Tag property and store the full path in there.
2. You could use a collection like a Dictionary to store the full path.
3. Create a custom control based on the LinkLabel that has a specific property for storing the full path.
Back to top Go down
 

Add a custom string property to a linklabel?Dear all I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms. I am currently making an "app launcher" which reads a text file line by line.

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» C: Read from file and write to file
» How to remove part of string?
» Convert string to date
» Very useful simple coding tip - how to save time working with lists
» Obtain JS Requested Query String

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Add a custom string property to a linklabel?Dear all  I am totally new to visual C#. Whilst I can sort of manage console apps, I easily get lost when it comes to coding forms.  I am currently making an "app launcher" which reads a text file line by line.  Edit-trash Useless :: Trash-