Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add the link to a button and insert the imagen for it.
how it can be possible!
Posted
Comments
maxrockM 22-Feb-13 8:58am    
Not clear. Do you want to have an image button which opens a link? Please tell more.
tusharkaushik 22-Feb-13 9:02am    
ya! but in windows forms

1 solution

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


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

        }
    }
}


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);
            }
        }



    
    }
}


Tested with C# 2012 .NET Framework 4.0
 
Share this answer
 
v8
Comments
tusharkaushik 22-Feb-13 9:07am    
what is interaction.shell in c# 2.0
Mike Meinz 22-Feb-13 9:17am    
See Interaction.Shell Method

I have to leave for the day now. Best regards!
Mike Meinz 22-Feb-13 16:10pm    
I updated Solution 1 with two working C# examples. For the first example, be sure to Add a Reference to Microsoft.VisualBasic in the References area of the project in the Visual Studio Solution Explorer window.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900