Print Page | Close Window

Creating MarkupRoutedEvent for Hyperlink in code

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: MarkupLabel Control
Forum Description: Topics Related to Codejock MarkupLabel Control
URL: http://forum.codejock.com/forum_posts.asp?TID=18588
Printed Date: 14 May 2024 at 11:34am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Creating MarkupRoutedEvent for Hyperlink in code
Posted By: Andrew666
Subject: Creating MarkupRoutedEvent for Hyperlink in code
Date 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



Replies:
Posted By: jpbro
Date 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



Posted By: Andrew666
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net