Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > MarkupLabel Control
  New Posts New Posts RSS Feed - Creating MarkupRoutedEvent for Hyperlink in code
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Creating MarkupRoutedEvent for Hyperlink in code

 Post Reply Post Reply
Author
Message
Andrew666 View Drop Down
Groupie
Groupie


Joined: 15 October 2008
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote Andrew666 Quote  Post ReplyReply Direct Link To This Post Topic: Creating MarkupRoutedEvent for Hyperlink in code
    Posted: 24 June 2011 at 2:54pm
I'm trying to programmatically create and add a Hyperlink object with a named Click property to a TextBlock using the following pseudo code.  It doesn't work and fails when assigning the MarkupRoutedEvent object:
 
1. Find MarkupTextBlock object using MarkupUIElement.FindName method
2. Clear all the Inlines
3. Create the MarkupHyperlink, MarkupRun and MarkupRoutedEvent objects using MarkupContext.CreateObject
4. Set Run Text property
5. Set MarkupHyperlink Name property
6. Set MarkupRoutedEvent Name property [ fails here ]
7. Assign MarkupRoutedEvent to MarkupHyperlink ClickEvent property
8. Add Run to MarkupHyperlink Inlines
9. Add MarkupHyperlink to MarkupTextBlock Inlines
 
Everything works if I exclude the RoutedEvent steps 6 and 7.  Thanks.
 

Regards
 
--Andrew
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 24 June 2011 at 5:43pm
Here's how I create Hyperlinks with a ClickEvent:


Option Explicit

Public Sub HyperlinkClicked(po_Source As Object, po_Args As Object)
   Dim lo_Hyperlink As MarkupHyperlink
  
   If TypeOf po_Source Is MarkupHyperlink Then
      Set lo_Hyperlink = po_Source
     
      MsgBox lo_Hyperlink.Tag
   End If
End Sub

Private Sub Form_Load()
   Dim lo_Hyperlink As MarkupHyperlink
   Dim lo_TextBlock As MarkupTextBlock
   Dim lo_Run As MarkupRun
  
   With Me.MarkupLabel1
      With .MarkupContext
         Set lo_Run = .CreateObject("Run")
         With lo_Run
            .Text = "This is a link"
         End With
        
         Set lo_Hyperlink = .CreateObject("Hyperlink")
         With lo_Hyperlink
            .Inlines.Add lo_Run
            .Tag = "http://www.codejock.com"
            .AddHandler .ClickEvent, "HyperlinkClicked"
         End With
        
         Set lo_TextBlock = .CreateObject("TextBlock")
         With lo_TextBlock
            .Inlines.Add lo_Hyperlink
         End With
      End With
  
      .MarkupContext.SetHandler Me
      Set .MarkupUIElement = lo_TextBlock
  
   End With
End Sub


Is that helpful? If not, can you post a small sample of what you are trying to do, and I will take a look at it to see if I can understand your problem better through code instead of pseudo-code.

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
Andrew666 View Drop Down
Groupie
Groupie


Joined: 15 October 2008
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote Andrew666 Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2011 at 11:25am
Thanks, that worked a treat.  I wasn't using the "AddHandler" method.  As usual the controls do what I want - if only I can work out how ;)
 
--A
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.