Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > MarkupLabel Control
  New Posts New Posts RSS Feed - SOLVED: MarkupContext.SetHandler method in VB.net
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SOLVED: MarkupContext.SetHandler method in VB.net

 Post Reply Post Reply
Author
Message
gibrael View Drop Down
Groupie
Groupie
Avatar

Joined: 17 March 2009
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote gibrael Quote  Post ReplyReply Direct Link To This Post Topic: SOLVED: MarkupContext.SetHandler method in VB.net
    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
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post 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");
            }
        }
}
Back to Top
gibrael View Drop Down
Groupie
Groupie
Avatar

Joined: 17 March 2009
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote gibrael Quote  Post ReplyReply Direct Link To This Post 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
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.125 seconds.