Print Page | Close Window

SOLVED: MarkupContext.SetHandler method in VB.net

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=19666
Printed Date: 02 May 2024 at 5:47am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: SOLVED: MarkupContext.SetHandler method in VB.net
Posted By: gibrael
Subject: SOLVED: MarkupContext.SetHandler method in VB.net
Date Posted: 19 April 2012 at 6:31am
Hi,

How would we use the Sethandler method in VB.net?

In VB6, it's simply

Dim markup as MarkupLabel
markup.MarkupContext.SetHandler Me

How do we do this in .NET?
It's always throwing an InvalidCastException.

Thanks.


-------------
--
Codejock Xtreme Suite Pro 15.2
VisualStudio 2010
Windows 7



Replies:
Posted By: SuperMario
Date Posted: 19 April 2012 at 8:59am
I don't have a VB.Net sample handy, but here is some C# code.  I assume you are wanting SetHandler to use events in Markup:

/*
Your class needs to implement the IDispatch interface.

You need to add "using System.Runtime.InteropServices;" at the top of your file and "[ComVisible(true), ClassInterface(ClassInterfaceType. AutoDispatch)]" above your class declaration.

Please note that you need to set the event handler in Markup, i.e. <Hyperlink Click='Hyperlink_Click'>
*/

//Need to include this
using System.Runtime.InteropServices;

namespace MarkupSample
{
        public Form1()
        {
            InitializeComponent();
        }

    //Need this line
    [ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch)]
    public partial class Form1 : Form
    {
            Label1.Caption = "<TextBlock>Click <Hyperlink Tag='This!' Click='Hyperlink_Click'>this</Hyperlink> or <Hyperlink Tag='That!' Click='Hyperlink_Click'>that</Hyperlink> link.  (Shows how to handle Markup Events)</TextBlock>";
            Label1.MarkupContext.SetHandler(this);
    }

//Then need this
        [ComVisible(true)]
        public void Hyperlink_Click(XtremeMarkup.MarkupObject Sender, XtremeMarkup.MarkupRoutedEventArgs Args)
        {
            try
            {
                XtremeMarkup.MarkupHyperlink Element;
                Element = (XtremeMarkup.MarkupHyperlink)Sender;

                MessageBox.Show("Clicked: " + Element.Tag);
            }
            catch
            {
                MessageBox.Show("Clicked");
            }
        }
}


Posted By: gibrael
Date Posted: 19 April 2012 at 10:13am
Clap Wow!
Thanks a lot! I've been wracking my brains whole afternoon looking for a solution! This worked perfectly! 

Thanks again!


-------------
--
Codejock Xtreme Suite Pro 15.2
VisualStudio 2010
Windows 7



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