Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#WinForm
Adding image to windows form in C# that connects(Hyperlink) to a website when clicked like I say http://www.codeproject.com/
 
I changed image of Linklabel but the text of linklabel is also displayed in the form;But I want to show only image in the form to be displayed.
On text deletion of linklabel-image is also not displayed.
I used code(below)and changed image using properties of linklabel.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
 
namespace linklabelcontrols
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // Add a link to the LinkLabel.
            LinkLabel.Link link = new LinkLabel.Link();
            link.LinkData = "http://www.codeproject.com";
            linkLabel1.Links.Add(link);
        }
 
        private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        { //now connection process start here
            Process.Start(e.Link.LinkData as string);
        }
    }
}
Posted 2-Nov-12 22:57pm
Edited 2-Nov-12 23:04pm
v2

1 solution

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

Solution 1

Does the Image[^] property do what you want?
  Permalink  
Comments
Abhishek Pant at 3-Nov-12 5:32am
   
Oops! No, Like you wrote Image above with with a connected link now the same thing I want to write on Windows Forms with a image over there that connects the link in place of text as "Image".
Richard MacCutchan at 3-Nov-12 5:58am
   
I understand what you are trying to do but I don't have time to test this myself, so I'm not sure what it looks like. What happens if it does not have any text?
Abhishek Pant at 3-Nov-12 6:18am
   
The Image also disappears. But link remains there. Then If nothing is displayed how could the user know that there is a link.
Richard MacCutchan at 3-Nov-12 7:35am
   
I have had a quick look at this and it seems that it requires some text to be clicked on. I think you will have to add some extra code to override some of the default behaviour in order to achieve what you want.
Abhishek Pant at 3-Nov-12 7:45am
   
Can u elaborate this "extra code to override some of the default behaviour "
Richard MacCutchan at 3-Nov-12 7:54am
   
Well no, that's the part you have to write. You need to look at all the events and methods of the control to decide which ones you need to override to make the control do what you want.
Abhishek Pant at 3-Nov-12 8:01am
   
Ok,Thanks for the hint.
Richard MacCutchan at 3-Nov-12 12:52pm
   
I have just revisited this, and it would seem that it cannot be done without some text to click on. However, you could just use a PictureBox control and add your own functionality in its Click event to launch the web page.
Abhishek Pant at 3-Nov-12 13:31pm
   
I implemented this after you said about the term override and done this successfully. Overall,thanks again.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 840
1 OriginalGriff 437
2 Abhinav S 303
3 thatraja 215
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,122
1 OriginalGriff 4,520
2 Peter Leow 3,744
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 3 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid