Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
i want to add the link to a button and insert the imagen for it.
how it can be possible!
Posted 22-Feb-13 3:35am
Comments
maxrockM at 22-Feb-13 8:58am
   
Not clear. Do you want to have an image button which opens a link? Please tell more.
tusharkaushik at 22-Feb-13 9:02am
   
ya! but in windows forms

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
            }
 
        }
    }
}
 
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
  Permalink  
v8
Comments
tusharkaushik at 22-Feb-13 9:07am
   
what is interaction.shell in c# 2.0
Mike Meinz at 22-Feb-13 9:17am
   
See Interaction.Shell Method
 
I have to leave for the day now. Best regards!
Mike Meinz at 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)

  Print Answers RSS
0 OriginalGriff 7,215
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100