This is a migrated thread and some comments may be shown as answers.

Displaying custom context menu after document resize OR scroll

3 Answers 100 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cameron Molyneux
Top achievements
Rank 1
Cameron Molyneux asked on 15 Mar 2012, 01:43 PM

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

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 20 Mar 2012, 01:32 PM
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 >>
0
Cameron Molyneux
Top achievements
Rank 1
answered on 20 Mar 2012, 03:15 PM
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
0
Martin Ivanov
Telerik team
answered on 23 Mar 2012, 04:16 PM
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 >>
Tags
RichTextBox
Asked by
Cameron Molyneux
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Cameron Molyneux
Top achievements
Rank 1
Share this question
or