Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2007, 11:01 PM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default Need Help with Dynamic Link Label Click Events

Hi

I take in a file and filter through the file grabbing certain stuff and then I stick each group of the code into its own file and create a link label for each one.

I now need to be able to make Click events for each of these lables that contain:

A path to the file to of one of the filtered groups. So say I open a file up and it filters a math equation out and puts it into a .txt file located at G:\hold\equation1.txt(equation1.txt is the file name that it will be called).

I want to have a path going to that file for my first equations. So when a user clicks on that first link label it will display that file.

Of course they could have 10 equations in that file that gets filtered out and each one gets its on txt file(so equation1.txt,equation2.txt,etc) all located in G:\hold\equation[insert number here].txt

How do I do this in c#?

How can I go about to do this. For now my paths are absoulte but later on I am going to change them to be relative.

 
Old November 6th, 2007, 11:04 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Is this a windows application or a Web application?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 6th, 2007, 11:07 PM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

windows application.

 
Old November 7th, 2007, 04:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You could store a value in the Label.Tag property, then extract that in the onlick event (which would be the same event for each label) and look whatever you need to up in an array or collection.

for(int i = 0; i < numEquations; i++)
{
    Label l = new Label();
    l.Text = "Equation " + i;
    FileNameArray.Add("equation" + i + ".txt");
    l.Tag = i;
    l.Click += new System.EventHandler(Label_Click);
    // add the label to the form.
}

public void Label_Click(object sender, EventArgs e)
{
   Label l = sender as Label;
   if( l == null ) return;
   int i = int.Parse(l.Tag);

   string filename = FileNameArray(i);
   string equation = EquationArray(i);

   ... etc
}


/- Sam Judson : Wrox Technical Editor -/
 
Old November 8th, 2007, 03:47 AM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Thanks that Really helped out a lot. I have been able to change your example(I left out some parts since I did not know what they where and the stuff I had worked).

Now I have a better idea of how to make dynamic event handlers.






Similar Threads
Thread Thread Starter Forum Replies Last Post
double click to open link thutt Dreamweaver (all versions) 0 February 8th, 2007 05:01 PM
Dynamic Text in Label funnylearning .NET Framework 2.0 2 September 18th, 2006 12:59 PM
Tool tip foe link label in c# yagyesha C# 2 December 14th, 2005 05:08 AM
Click on link in VB6 Perseus Beginning VB 6 1 August 30th, 2005 05:52 PM
multiple checkboxes with same name click events kcs_chandra Classic ASP Databases 3 October 24th, 2004 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.