• C# Link Label Issue
    3 replies, posted
I'm working on a small assignment program for my programming class that involves making a small catalogue thing using structures. I tried to add a dynamic link label who's destination changes depending on the slider's value. However, I can't make the value of the slider's current position (named CurPos) a public variable which lets it be recongnized by the linklabel click event. Here's my current code: [CODE] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace OOPAssignment { public partial class FrmOne : Form { public FrmOne() { InitializeComponent(); } struct Games { public String Name; public String Date; public String Engine; public String Score; public String Picture; public String Review; } Games[] Game = new Games[14]; private void FrmOne_Load(object sender, EventArgs e) { string p = Application.StartupPath; Game[1].Name="Half-Life"; Game[1].Date = "November 19, 1998"; Game[1].Engine="GoldSrc"; Game[1].Score = "96"; Game[1].Picture = p + @"\1.jpg"; Game[1].Review = "http://www.metacritic.com/games/platforms/pc/halflife?q=Half-Life"; Game[2].Name = "Team Fortress Classic"; Game[2].Date = "April 7, 1999"; Game[2].Engine = "GoldSrc"; Game[2].Score = "N/A"; Game[2].Picture = p + @"\2.jpg"; Game[2].Review = "http://www.metacritic.com/search/process?sort=relevance&termtype=all&ts=Team+fortress+classic&ty=0&button=search"; Game[3].Name = "Counter Strike"; Game[3].Date = "November 8, 2000"; Game[3].Engine = "GoldSrc"; Game[3].Score = "88"; Game[3].Picture = p + @"\3.jpg"; Game[3].Review = "http://www.metacritic.com/games/platforms/pc/halflifecounterstrike?q=Counter-Strike"; Game[4].Name = "Day of Defeat"; Game[4].Date = "May 1, 2003"; Game[4].Engine = "GoldSrc"; Game[4].Score = "79"; Game[4].Picture = p + @"\4.jpg"; Game[4].Review = "http://www.metacritic.com/games/platforms/pc/dayofdefeat?q=Day%20of%20Defeat"; Game[5].Name = "Counter Strike:Condition Zero"; Game[5].Date = "March 20, 2004"; Game[5].Engine = "GoldSrc"; Game[5].Score = "65"; Game[5].Picture = p + @"\5.jpg"; Game[5].Review = "http://www.metacritic.com/games/platforms/pc/counterstrikeconditionzero?q=Condition%20Zero"; Game[6].Name = "Half-Life 2"; Game[6].Date = "November 16, 2004"; Game[6].Engine = "Source"; Game[6].Score = "96"; Game[6].Picture = p + @"\6.jpg"; Game[6].Review = "http://www.metacritic.com/games/platforms/pc/halflife2?q=Half-life%202"; Game[7].Name = "Counter Strike:Source"; Game[7].Date = "October 7, 2004"; Game[7].Engine = "Source"; Game[7].Score = "88"; Game[7].Picture = p + @"\7.jpg"; Game[7].Review = "http://www.metacritic.com/games/platforms/pc/counterstrikesource?q=counter-strike"; Game[8].Name = "Day of Defeat:Source"; Game[8].Date = "26 September 2005"; Game[8].Engine = "Source"; Game[8].Score = "80"; Game[8].Picture = p + @"\8.jpg"; Game[8].Review = "http://www.metacritic.com/games/platforms/pc/dayofdefeatsource?q=day%20of%20defeat%20source"; Game[9].Name = "Half-Life 2:Episode One"; Game[9].Date = "June 1, 2006"; Game[9].Engine = "Source"; Game[9].Score = "80"; Game[9].Picture = p + @"\9.jpg"; Game[9].Review = "http://www.metacritic.com/games/platforms/pc/halflife2episodeone?q=half-life 2 episode one"; Game[10].Name = "Half-Life 2:Episode Two"; Game[10].Date = "October 10, 2007"; Game[10].Engine = "Orange Box"; Game[10].Score = "90"; Game[10].Picture = p + @"\10.jpg"; Game[10].Review = "http://www.metacritic.com/games/platforms/pc/halflife2episode2?q=Half-life 2"; Game[11].Name = "Portal"; Game[11].Date = "October 10, 2007"; Game[11].Engine = "Orange Box"; Game[11].Score = "90"; Game[11].Picture = p + @"\11.jpg"; Game[11].Review = "http://www.metacritic.com/games/platforms/pc/portal?q=portal"; Game[12].Name = "Team Fortress 2"; Game[12].Date = "October 10, 2007"; Game[12].Engine = "Orange Box"; Game[12].Score = "92"; Game[12].Picture = p + @"\12.jpg"; Game[12].Review = "http://www.metacritic.com/games/platforms/pc/teamfortress2?q=Team Fortress 2"; Game[13].Name = "Left 4 Dead"; Game[13].Date = "November 17, 2008"; Game[13].Engine = "Left 4 Dead"; Game[13].Score = "89"; Game[13].Picture = p + @"\13.jpg"; Game[13].Review = "http://www.metacritic.com/games/platforms/pc/left4dead?q=left 4 dead"; txtName.Text = Game[1].Name; txtDate.Text = Game[1].Date; txtEngine.Text = Game[1].Engine; txtScore.Text = Game[1].Score; picPicture.Image = Image.FromFile(Game[1].Picture); } private void trbSlider_Scroll(object sender, EventArgs e) { // Get the index of the current value of the track bar - 1 //public int CurPos = this.trbSlider.Value; int CurPos = trbSlider.Value; // Based on the current index, retrieve the values of the // current game and assign each to the corresponding control txtName.Text = Game[CurPos].Name; txtDate.Text = Game[CurPos].Date; txtEngine.Text = Game[CurPos].Engine; txtScore.Text = Game[CurPos].Score; //lnkReview.Text = Game[CurPos].Review; picPicture.Image = Image.FromFile(Game[CurPos].Picture); } private void lnkReview_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("IExplore", Game[CurPos].ToString()); } } } [/CODE] I've never worked with link labels before and I'm stumped, I would really appreciate any help I could get.
this line: [code] System.Diagnostics.Process.Start("IExplore", Game[CurPos].ToString()); [/code] won't work for a start, since you're casting the Game object to a string and not getting the URL you stored. and you need to replace "Game[CurPos]" with: [code] Game[trbSlider.Value].Review; [/code]
Wow it worked! Thanks man, shame the only I can do is rate polite
I'd suggest letting it use the default browser the user has. [cpp]System.Diagnostics.Process.Start( "IExplore", Game[ trbSlider.Value ].Review );[/cpp] If you just launch the url, then it'll use whatever browser they have set as their default. [cpp]System.Diagnostics.Process.Start( Game[ trbSlider.Value ].Review );[/cpp]
Sorry, you need to Log In to post a reply to this thread.