Hyperlink Click

15 posts, 0 answers
  1. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 26 Jun 2014 Link to this post

    Hi,

    Is it possible that if user click the hyperlink a form will be open?
    Thanks.
  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 01 Jul 2014 Link to this post

    Hi Saif,

    Thank you for writing.

    Please note that the main purpose of this functionality is to display a hyperlink. Nevertheless you can intercept a link click and execute any code you want. To achieve this you can subscribe to the MouseDown event of the ContentElement and check if the mouse is over a link:
    void ContentElement_MouseDown(object sender, MouseEventArgs e)
    {
        FieldInfo pi = this.radDesktopAlert1.Popup.AlertElement.ContentElement.GetType().GetField("textPrimitiveImpl", BindingFlags.Instance | BindingFlags.SetProperty |BindingFlags.NonPublic);
        TextPrimitiveHtmlImpl text = (TextPrimitiveHtmlImpl)pi.GetValue(this.radDesktopAlert1.Popup.AlertElement.ContentElement);
     
        FormattedTextBlock textBlock = text.TextBlock;
        FormattedText clickedLink = IsMouseOverBlock(textBlock, e);
     
        if (clickedLink != null)
        {
            MessageBox.Show(clickedLink.Text + " pressed");
            //here you can execute any code you want
        }
    }
     
    private FormattedText IsMouseOverBlock(FormattedTextBlock textBlock, MouseEventArgs e)
    {
        Point elementAtPoint = this.radDesktopAlert1.Popup.AlertElement.ContentElement.PointFromControl(e.Location);
        int linesCount = textBlock.Lines.Count;
        for (int i = 0; i < linesCount; ++i)
        {
            TextLine textLine = textBlock.Lines[i];
            int textLineCount = textLine.List.Count;
            for (int j = 0; j < textLineCount; ++j)
            {
                FormattedText formattedText = textLine.List[j];
                if (!string.IsNullOrEmpty(formattedText.Link) && formattedText.DrawingRectangle.Contains(elementAtPoint))
                {
                    return formattedText;//found link under mouse
                }
            }
        }
     
        return null;//not found
    }

    The subscription to the event can be made as follows:
    this.radDesktopAlert1.Popup.AlertElement.ContentElement.MouseDown += ContentElement_MouseDown;

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 02 Jul 2014 Link to this post

    Hi Dimitar

    Thanks a lot on this one.
    It really help me a lot.
  5. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 02 Nov 2014 in reply to Dimitar Link to this post

    Hi

    I'm having exception error on TextPrimitiveHtmlImpl

    FieldInfo pi = this.radDesktopAlert1.Popup.AlertElement.ContentElement.GetType().GetField("textPrimitiveImpl", BindingFlags.Instance | BindingFlags.SetProperty |BindingFlags.NonPublic);

    pi always null

    TextPrimitiveHtmlImpl text = (TextPrimitiveHtmlImpl)pi.GetValue(this.desktopAlert.Popup.AlertElement.ContentElement);

    NullReferenceException was unhandled
  6. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 02 Nov 2014 in reply to Saif Link to this post

    Sorry for double post

    typographical error on radDesktopAlert1, im using desktioAlert

    I'm trying to edit the post to change the control name.
  7. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 05 Nov 2014 Link to this post

    Hi Saif,

    Thank you for writing back.

    We have exposed a property for this and now you can access the text block without using a reflection:
    void ContentElement_MouseDown(object sender, MouseEventArgs e)
    {
        FormattedTextBlock textBlock = this.radDesktopAlert1.Popup.AlertElement.ContentElement.TextBlock;
        FormattedText clickedLink = IsMouseOverBlock(textBlock, e);
     
        if (clickedLink != null)
        {
            MessageBox.Show(clickedLink.Text + " pressed");
            //here you can execute any code you want
        }
    }

    I hope this information helps. 

    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  8. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 03 Feb 2015 Link to this post

    Hi again.

    Can you help me on converting this syntax into VB.Net.
    I'm having problem with the adding of the event MouseDown.
    Thanks.
  9. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 03 Feb 2015 Link to this post

    I got it now.

    AddHandler Me.RadDesktopAlert1.Popup.AlertElement.ContentElement.MouseDown, AddressOf ContentElement_MouseDown

    Thanks.
  10. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 05 Feb 2015 Link to this post

    Hi Saif,

    Thank you for writing back.

    Indeed I forgot to add the event subscription code. Nevertheless I am glad that you have found the solution yourself. 

    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  11. VLADISLAV
    VLADISLAV avatar
    32 posts
    Member since:
    Oct 2015

    Posted 12 Nov 2015 Link to this post

    Using this solution and getting exception "An unhandled exception of type 'System.NullReferenceException' occurred in Telerik.WinControls.dll" After click on the link in alert window.
  12. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 12 Nov 2015 Link to this post

    Hello Viktor,

    Thank you for writing.

    You should change the MouseDown event as follows:
    void ContentElement_MouseDown(object sender, MouseEventArgs e)
    {
         
        FieldInfo pi = typeof(LightVisualElement).GetField("textPrimitiveImpl", BindingFlags.Instance | BindingFlags.NonPublic);
        TextPrimitiveHtmlImpl text = (TextPrimitiveHtmlImpl)pi.GetValue(this.radDesktopAlert1.Popup.AlertElement.ContentElement);
     
        FormattedTextBlock textBlock = text.TextBlock;
        FormattedText clickedLink = IsMouseOverBlock(textBlock, e);
     
        if (clickedLink != null)
        {
            MessageBox.Show(clickedLink.Text + " pressed");
            //here you can execute any code you want
        }
    }

    I hope this helps.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  13. VLADISLAV
    VLADISLAV avatar
    32 posts
    Member since:
    Oct 2015

    Posted 12 Nov 2015 Link to this post

    Vladislav
  14. VLADISLAV
    VLADISLAV avatar
    32 posts
    Member since:
    Oct 2015

    Posted 12 Nov 2015 in reply to VLADISLAV Link to this post

    base.Dispose(disposing); here this exception throws still.
  15. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 12 Nov 2015 Link to this post

    Hi Vladislav,

    Thank you for writing back.

    I just tested this and there is no exception on my side. This is why I have attached my test project. Could you please check it and let me know how it differs from your real setup? 

    I am looking forward to your reply.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  16. VLADISLAV
    VLADISLAV avatar
    32 posts
    Member since:
    Oct 2015

    Posted 12 Nov 2015 Link to this post

    Thanks alot , all the problem was in format i thought al i need just link but u also need this thingy "<html><a href=\"#\">link</a></html>" .After adding tags everything warks well.
Back to Top
UI for WinForms is Visual Studio 2017 Ready