Results 1 to 13 of 13

Thread: Hyperlink in Label

  1. #1

    Thread Starter
    Addicted Member suva's Avatar
    Join Date
    Apr 2002
    Location
    India
    Posts
    181

    Hyperlink in Label

    How can I create a hyperlink in a Label?

    Note: I am using Label of Microsoft Form 2.0 Library

    Any HELP is welcomed ................
    Last edited by suva; Apr 12th, 2003 at 02:00 AM.
    Suva --> The great VB 6.0 Programmer


    Note :
    If problem is Resolved dont forget to edit your first post and add RESOLVED to your subject

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If you don't want the address as the caption of the label put it in the Tag property. For example:
    VB Code:
    1. Label1.Caption = "Visit the VB Forums"
    2. Label1.Tag = "http://www.vbforums.com"
    Now use ShellExecute in the Click event.
    VB Code:
    1. Private Declare Function ShellExecute _
    2.  Lib "shell32.dll" Alias "ShellExecuteA" ( _
    3.  ByVal hwnd As Long, _
    4.  ByVal lpOperation As String, _
    5.  ByVal lpFile As String, _
    6.  ByVal lpParameters As String, _
    7.  ByVal lpDirectory As String, _
    8.  ByVal nShowCmd As Long) As Long
    9.  
    10. Private Sub Label1_Click()
    11.     ShellExecute 0, "Open", Label1.Tag, "", "", vbNormalFocus
    12. End Sub
    Best regards

  3. #3

    Thread Starter
    Addicted Member suva's Avatar
    Join Date
    Apr 2002
    Location
    India
    Posts
    181
    Joacim Andersson,

    The problem for me is that I cannot bring the hand that comes over a hyperlink when the mousepointer hovers over the hyperlinked text. I want the hand. The rest like making it blue or underlining the text or on clicking go to the required web page ..... all is happenning. Even I have brought hand , though its not similar to the normal one, anyway still the problem remaining is that the hand is coming whenever its hovering over the whole label. But I want the hand to appear only when the mouse hovers over the hyperlink text and not the rest unwanted part of the label. Its not necessity for me to use label. If there are some other controls please suggest.

    Thanx,
    Suva.

    Suva --> The great VB 6.0 Programmer


    Note :
    If problem is Resolved dont forget to edit your first post and add RESOLVED to your subject

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Simply set the MousePointer to 99 then load a hand cursor in the MouseIcon property. Attached is a zip file containing hand cursors in both *.cur and *.ico format.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member suva's Avatar
    Join Date
    Apr 2002
    Location
    India
    Posts
    181
    Joacim Andersson,

    Thankx for the Hand Cursor.

    But still I think u havent read the whole. The cursor is being displayed whenever on the label. But I want to restrict it to the hyperlinked text.

    Anyway thanx again for your cooperations.
    Suva --> The great VB 6.0 Programmer


    Note :
    If problem is Resolved dont forget to edit your first post and add RESOLVED to your subject

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I don't understand. Do you have regular text mixed with the hyperlink text in the same label? In that case how do you make just a part of the label blue with an underscore?

  7. #7
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    You can't make just part of the label have a certain mouse cursor, the propertie covers the entire label.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well you could change the MousePointer value between Default and Custom during run-time, the question would then be how to know when the mouse pointer is over the link part. I still want to know if one label is used for both states, otherwise you could simply set the AutoSize property to True so the label isn't larger then the text it contains.

  9. #9
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Yah you could. But the truth is, if they click anywhere on that label it's going to open the link so it may as well be treated like a link. I got the impressions that it was just a label with a hyper link on it but i assume it could be a very large label with jsut a small link in the middle of it.

    In this case you could change the mouse cursor depending on the coordinates of the mouse using the getcursorpos API. But if it's just a small label with a link on it i wouldn't bother.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You must of course check the state of the Mouse Pointer in the Click event. But I'm still confused since he said that the hyperlink is blue and underscored. You can't have different colors and font style in one label can you?

  11. #11

    Thread Starter
    Addicted Member suva's Avatar
    Join Date
    Apr 2002
    Location
    India
    Posts
    181
    Yeas Arc ,
    U have got it correct its a large label which may contain a small Hyperlink or even a large one. But I have to fix the size of the label during design time to make the design look clear.

    I had thought of your suggestion earlier but how will I know which parts of the label is occupied by the text? That was the problem I faced when thinking of ur idea to get the mouse position and work accordingly.

    Can u solve this problem for me?
    Suva --> The great VB 6.0 Programmer


    Note :
    If problem is Resolved dont forget to edit your first post and add RESOLVED to your subject

  12. #12
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    No i can't because i have no idea where your link is going to be either
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  13. #13

    Thread Starter
    Addicted Member suva's Avatar
    Join Date
    Apr 2002
    Location
    India
    Posts
    181
    I know the position of the form , the label and as the text in the label i.e. the hyperlink text is just a caption( I am assigning in the following way say for eg label1.caption="http://mail.yahoo.com/") it starts from the top most line and leftmost position. The problem with me is I dont know the final height of the text within the label and the length of the text in each line. Now can u help me?
    Suva --> The great VB 6.0 Programmer


    Note :
    If problem is Resolved dont forget to edit your first post and add RESOLVED to your subject

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width