-
August 19th, 2011, 06:05 PM
#1
Clicking linklabel once causes link to open multiple (3) times
Just as the title says, clicking the link opens the same page three times in seperate tabs on a single browser (Google Chrome). Weird thing is, it's not happening on my computer but when I gave the program to my friend he reported this. The code is your usual linkclicked event:
Code:
kayanYazi = new LinkLabel();
kayanYazi.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkAc);
private void linkAc(object sender, LinkLabelLinkClickedEventArgs e)
{
string target = e.Link.LinkData as string;
System.Diagnostics.Process.Start(target);
}
Is there any way to prevent the event from running multiple times (if that's the reason)? And why does it vary from PC to PC?
-
August 19th, 2011, 06:35 PM
#2
Re: Clicking linklabel once causes link to open multiple (3) times
My first thought is... are you using Chrome on your system? Have you tried installing Chrome and testing on your system to see if it just has to do with the browser.
Second thought is, are you sure your friend isn't trying to 'double-click' the link, you'd be suprised how many people I see do that, like they're trying to open a folder or start a program... this could be why he fires multiple instances...
If you can't watch him/her use it... try throwing a 'wrench' in your handler... once in the handler, disable the link, Thread.Sleep(2000) (2 second lock), then re-enable the link... to try and prevent any double/triple-clicking...
That's all I can think of off the top of my head, since there is no 'good' reason your event would fire multiple times on it's own.
-
August 19th, 2011, 08:08 PM
#3
Re: Clicking linklabel once causes link to open multiple (3) times
Well, your advice actually worked It wasn't about browser or multiple clicks though. I'm using Chrome too, and he reported sometimes there were 20 seperate tabs opened with a single click (which he can't do accidently), even locking the computer for a while. But anyway, I modified the code as such:
Code:
private void linkAc(object sender, LinkLabelLinkClickedEventArgs e)
{
Thread.Sleep(250);
string target = e.Link.LinkData as string;
System.Diagnostics.Process.Start(target);
System.Windows.Forms.Timer engel = new System.Windows.Forms.Timer();
Thread.Sleep(250);
}
And voila, problem's gone. Weird, isn't it.
-
August 19th, 2011, 08:20 PM
#4
Re: Clicking linklabel once causes link to open multiple (3) times
Whoops, he reported the problem again. But it seems it occurs rarely right now. If only there would be a solid solution :/ Every little error annoys me..
-
August 19th, 2011, 08:21 PM
#5
Re: Clicking linklabel once causes link to open multiple (3) times
"That's all I can think of off the top of my head, since there is no 'good' reason your event would fire multiple times on it's own."
Unless there are 3 event handlers somehow (happens - the debugger can tell you this), or his mouse button is busted.
-
August 19th, 2011, 11:09 PM
#6
Re: Clicking linklabel once causes link to open multiple (3) times
Originally Posted by ExCx
Code:
kayanYazi = new LinkLabel();
kayanYazi.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkAc);
How many times are the lines of code above getting called?
-
August 20th, 2011, 07:57 AM
#7
Re: Clicking linklabel once causes link to open multiple (3) times
Hmm, now that's a good question. This program is a news ticker, so everytime a LinkLabel leaves the right edge of the screen a new one is created. Here's that whole code piece:
Code:
public void yaziYarat(int x)
{
ConfigReader CFGR = new ConfigReader();
FontStyle fontStil = (FontStyle)Enum.Parse(typeof(FontStyle), CFGR.configOlustur("fontstyle"), true);
Font yaziFontu = new Font(CFGR.configOlustur("fonttype"), Convert.ToSingle(CFGR.configOlustur("fontsize")), fontStil, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
bilgiYazi = Metin.yaziOlustur();
kayanYazi[x].Parent = bantArkaplan;
kayanYazi[x].AutoSize = true;
kayanYazi[x].BackColor = Color.Black;
kayanYazi[x].Font = yaziFontu;
kayanYazi[x].LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
kayanYazi[x].LinkColor = Color.FromName(CFGR.configOlustur("fontcolor"));
kayanYazi[x].Location = new System.Drawing.Point(ekranEn, ekranBoy/160);
kayanYazi[x].Name = "kayanYazi" + x;
kayanYazi[x].Size = new System.Drawing.Size(80, 19);
kayanYazi[x].TabIndex = 1;
kayanYazi[x].TabStop = true;
kayanYazi[x].Text = bilgiYazi[0];
Controls.Add(kayanYazi[x]);
Controls.SetChildIndex(kayanYazi[x], 1);
kayanYazi[x].Links.Clear();
kayanYazi[x].Links.Add(0, bilgiYazi[0].Length, bilgiYazi[1]);
kayanYazi[x].LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkAc);
kayanYazi[x].MouseEnter += new System.EventHandler(this.bantDurdur);
kayanYazi[x].MouseLeave += new System.EventHandler(this.bantDevam);
}
There are totally 20 of these. So when it comes kayanYazi[19], x goes back to "0" and so on. There's a timer which manages labels to scroll (altering their location each tick), and also controlling if a label leaves the edge (I do it with IntersectsWith method) to create a new one. Well that's the best way I could find, and it works for me too. But that could be the root of this problem..
-
August 20th, 2011, 12:10 PM
#8
Re: Clicking linklabel once causes link to open multiple (3) times
Originally Posted by ExCx
But that could be the root of this problem..
It's a good place to start.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|