基本プロジェクトに LinkLabel を配置します。

プロパティの Text をクリックして今回は適当に
http://wiki.livedoor.jp/glwrapper/ |
と、入力します。

LinkLabel をダブルクリックして以下のコードを追加します。
// アクセス済とする
linkLabel1->LinkVisited = true;
// 既定のアプリケーションで URL を開く
System::Diagnostics::Process::Start(linkLabel1->Text); |
ビルドして実行してみましょう。
url をクリックするとwebブラウザが起動してwebページが表示されます。

MyForm.cpp
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#include "MyForm.h"
using namespace Project1;
[STAThreadAttribute]
int main(){
MyForm ^form1 = gcnew MyForm;
form1->ShowDialog();
return 0;
}
|
MyForm.h
#pragma once
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// MyForm の概要
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: ここにコンストラクター コードを追加します
//
}
protected:
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::LinkLabel^ linkLabel1;
protected:
protected:
protected:
private:
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
/// コード エディターで変更しないでください。
/// </summary>
void InitializeComponent(void)
{
this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
this->SuspendLayout();
//
// linkLabel1
//
this->linkLabel1->AutoSize = true;
this->linkLabel1->Location = System::Drawing::Point(61, 109);
this->linkLabel1->Name = L"linkLabel1";
this->linkLabel1->Size = System::Drawing::Size(173, 12);
this->linkLabel1->TabIndex = 0;
this->linkLabel1->TabStop = true;
this->linkLabel1->Text = L"http://wiki.livedoor.jp/glwrapper/";
this->linkLabel1->LinkClicked += gcnew
System::Windows::Forms::LinkLabelLinkClickedEventHandler(this,
&MyForm::linkLabel1_LinkClicked);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->linkLabel1);
this->Name = L"MyForm";
this->Text = L"Hello C++/CLI World !!";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void linkLabel1_LinkClicked(System::Object^ sender,
System::Windows::Forms::LinkLabelLinkClickedEventArgs^ e) {
// アクセス済とする
linkLabel1->LinkVisited = true;
// 既定のアプリケーションで URL を開く
System::Diagnostics::Process::Start(linkLabel1->Text);
}
};
}
|
最終更新:2013年09月18日 21:24