C++ Tutorial: Using a Link Label Control in C++/CLI

   In this tutorial I am going to show you one more control – Link Label. This control is little similar to Label Control – it represents text. But if you click on the text of Link Label control you can go to a specific location, for example to the page in the internet. In the program of this tutorial we will make an opportunity for user to choose the browser and the page to surf the World Wide Web. Preparation    First of all you need to create a new Windows Forms Application project. Prepare main form by dragging controls on it. In my program I used such controls: 2 Labels, 2 Text Boxes and 1 Link Label. After you have designed your form you need to code. Code    Now I will explain how the program works. First of all you need to write a url to the desired web page in the first Text Box Control. After that you also need to fill another Text Box. In this control you need to write a full path to the browser you wish to use for surfing the net. Then the user is filled all Text Boxes he should click on the Link Label. Our program will open desired page in the desired browser. So we need to code Link Label Clicked event. The code is below. We make two String^ variables to store paths we need. After that we use them in the last line to call the browser and open the page.
  1. private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
  2.  
  3.                                  String^ url=textBox1->Text;
  4.                                  String^ path=textBox2->Text;
  5.                                  System::Diagnostics::Process::Start(path,url);
  6.  
  7.                          }

Add new comment