Displaying custom context menu after document resize OR scroll

4 posts, 0 answers
  1. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 15 Mar 2012 Link to this post

    We display a context menu when the user clicks on a field in the document

    We use the code

    synopticPopup = new RadContextMenu();
    synopticPopup.PlacementRectangle = plcRect;
    synopticPopup.Placement = PlacementMode.RelativePoint;
    synopticPopup.PlacementTarget = this.documenteditor.document;
    synopticPopup.IconColumnWidth = 0;

    to try and ensure the conext menu appears in the correct place but if we scroll the document OR we resize the window this does not work

    is there a way to ensure it takes into account these things?
    many thanks

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 20 Mar 2012 Link to this post

    Hello Cameron,
    You can set the PlacementTarget to the instance of RadRichTextBox and then get the proper coordinates from the event arguments, for example:

    this.radRichTextBox1.MouseRightButtonDown += radRichTextBox1_MouseRightButtonDown;
     
    void radRichTextBox1_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                Point p = e.GetPosition(this.radRichTextBox1);
                RadContextMenu synopticPopup = new RadContextMenu();
     
                synopticPopup.Placement = PlacementMode.RelativePoint;
                synopticPopup.PlacementTarget = this.radRichTextBox1;
                synopticPopup.IconColumnWidth = 0;
                synopticPopup.HorizontalOffset = p.X;
                synopticPopup.VerticalOffset = p.Y;
                synopticPopup.IsOpen = true;
                TextBlock block = new TextBlock();
                block.Text = "work";
                synopticPopup.Items.Add(block);
            }

    Don't hesitate to contact us if you have other questions.


    Greetings,
    Martin
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 20 Mar 2012 Link to this post

    unfortnately this doesnt help as this is based on where i click my mouse

    I need to place the popup at the same place as the field (but I do not want to insert anything into the document as this gave us other problems)

    So basically i need to find the field under the cursor and get the top X and Y for the field to place the pop up there

    The reason for this is when I hit return in the text box I have displayed .. I want to move to the next field and the popup to move there also

    This is proving very difficult to do!  maybe i'm missing something
  5. Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 23 Mar 2012 Link to this post

    Hello Cameron,
    You can create a document position, move it to the wanted inline element and then use the ActiveEditorPresenter to get the view point for this position, for example:
    Inline elementUnderMouse = this.radRichTextBox1.Document.CaretPosition.GetCurrentInlineBox().AssociatedInline;
                if (elementUnderMouse.FieldStart == null)
                {
                    return;
                }
                RadContextMenu synopticPopup = new RadContextMenu();
     
                DocumentPosition position = new DocumentPosition(this.radRichTextBox1.Document);
                position.MoveToInline(elementUnderMouse.GetAssociatedLayoutBoxes().First() as InlineLayoutBox, 0);
                Point p = this.radRichTextBox1.ActiveEditorPresenter.GetViewPointFromDocumentPosition(position);
     
                synopticPopup.Placement = PlacementMode.RelativePoint;
                synopticPopup.PlacementTarget = this.radRichTextBox1;
                synopticPopup.IconColumnWidth = 0;
                synopticPopup.HorizontalOffset = p.X;
                synopticPopup.VerticalOffset = p.Y;
                synopticPopup.IsOpen = true;
    You can obtain the InlineLayoutBox from the current caret position or from the current field.
    If you have any issues contact us back. Greetings,
    Martin
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top