如何在按钮的单击事件中插入链接 [英] how to insert a link in click event of button

查看:79
本文介绍了如何在按钮的单击事件中插入链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将链接添加到按钮并为其插入图像。

怎么可能!

i want to add the link to a button and insert the imagen for it.
how it can be possible!

推荐答案

下面是让C#程序用URL启动浏览器的两种方法。





示例程序#1

添加对Microsoft.VisualBasic的引用

Below are two ways to have a C# program start the browser with a URL.


Sample program #1
Add Reference to Microsoft.VisualBasic
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 Microsoft.VisualBasic;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strURL = "http://www.CodeProject.com";

            if (strURL.Length > 0)
            {
                int hPID = Interaction.Shell("cmd /c Start " + strURL, AppWinStyle.Hide);
            }

        }
    }
}





用C#测试2012 .NET Framework 4.0





示例程序#2



Tested with C# 2012 .NET Framework 4.0


Sample Program #2

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.Diagnostics;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = true;
                myProcess.StartInfo.FileName = "http://www.CodeProject.com";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
            }
            catch (Exception ex)
            {
               MessageBox.Show (ex.Message);
            }
        }



    
    }
}





使用C#2012 .NET Framework 4.0进行测试



Tested with C# 2012 .NET Framework 4.0


这篇关于如何在按钮的单击事件中插入链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆