C++ LinkLabel in VStudio

Hello I'm making a Windows Form App and I wanted to link websites that helped me finish it.

In a lot of tutorials, I found it's simply

 
  Process.Start("Link")


But this doesn't seem to work anymore.

So I went to https://msdn.microsoft.com/en-us/library/5acykfhc(v=vs.100).aspx and found this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private:
   void linkLabel1_LinkClicked(System::Object ^  sender,
      System::Windows::Forms::LinkLabelLinkClickedEventArgs ^  e)
   {
      try
      {
         VisitLink();
      }
      catch (Exception ^ ex)
      {
         MessageBox::Show("Unable to open link that was clicked.");
      }
   }
private:
   void VisitLink()
   {
      // Change the color of the link text by setting LinkVisited 
      // to true.
      linkLabel1->LinkVisited = true;
      // Call the Process.Start method to open the default browser 
      // with a URL:
      System::Diagnostics::Process::Start("http://www.microsoft.com");
   }


now this works but only if there is 1 link label present. Unfortunately, I'm adding more than 1

This is the error it provides me
Compiler Error C2535
One way to do it is to use the same event handler for each linklabel. However to make this work you need to store the complete link(like http://google.de) in the linklabel text property. In the event handler you can use the following code.
1
2
3
4
5
6
7
  System::Void linkLabel1_LinkClicked(System::Object^  sender,  
  System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) 
  {
    LinkLabel^ label = dynamic_cast<LinkLabel^>(sender);
    label->LinkVisited = true;
    System::Diagnostics::Process::Start(label->Text);
  }



In a lot of tutorials, I found it's simply
Process.Start("Link")
But this doesn't seem to work anymore.


Well this is C# synthax so it won't work in C++.
Last edited on
Topic archived. No new replies allowed.