C# linkLabelを使用してサイトに移動する

  • 作成日 2020.10.27
  • 更新日 2022.03.04
  • C#
C# linkLabelを使用してサイトに移動する

C#で、linkLabelを使用して、ブラウザを開いて指定したURLに移動するサンプルコードを記述してます。

環境

  • OS windows10 pro 64bit
  • Microsoft Visual Studio Community 2019 Version 16.7.1

linkLabel使い方

linkLabelを使用すると、ブラウザを開いて指定したURLに移動することができます。

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    System.Diagnostics.Process.Start("https://mebee.info/");
}

サンプルコード

以下は、
linkLabelをクリックすると、指定したURLをブラウザで開く
サンプルコードとなります。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace FormTestApp
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            linkLabel1.Text = "mebeeへ移動";
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://mebee.info/");
        }
    }
}

指定したURLが開いていることが確認できます。