ScintillaNet - figure out what line the mouse is hovering - scintillanet

I can't figure how to find a line index from a (x,y) coordonate. My goal is to change the selection when I selecting lines by dragging in the margin. There is a MarginClick event that allows me to find the line corresponding to the click with this :
var line = this.Lines[this.LineFromPosition(e.Position)];
Here the e.Position corresponds to the char position in the text. The problem is that the MouseMove event does not expose such position. It exposes a (x,y) coordinate in the control.

Related

How Scaling will affect position of element in canvas

I am having one canvas. I have added one text box to it using canvas.left and canvas.right property.And already there is a image inside that container. And am applying some matrix transform to my text box and image in order to zoom it.
tb.RenderTransform = new MatrixTransform(m);
But now the text box is getting moved to different position. But It should get zoomed along with the image. How to achieve that.?

Highlighting text in a Winforms textbox

For a Winforms textbox, when you click and drag over the text, it highlights it. Is there a way to determine which direction the user dragged over?
There is no way to get this info using the Windows TextBox selection API. For example, the EM_GETSEL message defines the starting and ending character positions of the selection, but in a predefined (sorted) order.
However you could get this info by handling the control's MouseMove event. For example:
textBox1.MouseMove += new MouseEventHandler(textBox1_MouseMove);
void textBox1_MouseMove(object sender, MouseEventArgs e)
{
Control tbCtrl = sender as Control;
// the mouse coordinate values here are relative to the coordinates of the control that raised the event
int mouseX = e.X;
...
}
By applying some logic to mouseX you could potentially discover the average direction the cursor is moving. It would work best if the user is making a linear motion. You could also handle the textbox's drag-and-drop event for similar mouse information if you only wanted the event raised while the user was dragging the mouse.

How to move elements within picturebox?

Is there any simple way to move picture parts (any stuff created with DrawImage or DrawString)?
My smart idea:
Override DrawImage(DrawString) method adding ability to store width, height, left, top, of drawn image (and may be boolean variable 'sizable' if I use DrawImage method) to a list of objects. Attach function "WhatToMove" to PictureBox's MouseMove event, which walks through a list of stored rectangle objects, detects what rectangle cursor is over, in case of resizeable rectangle detect if cursor is over any of rectangle's borders and pass this stuff as parameters to the MouseDown function, when I click. Then MouseDown function will attach new function "MoverResizer" to MouseMove event, which redraws picture box with moved or resized parts of image, updates proper rectangle object in list, and also detachs "WhatToMove" from MouseMove. On MouseUp and Leave events of PictureBox detach "MoverResizer" and attach "WhatToMove".
If you think this idea can live you will really help me if tell me how to override DrawImage.
My dumb idea:
Create Labels without text and with borders and locate them over PictureBox right over proper image parts. Then make them draggable and sizeable with their own events. Then translate positions of labels to positions of parts of picture and redraw picturebox. This is simply but I think not so perfect as method above.

Canvas.GetTop not updated after Element drag

I have a Rectangle nested within a Canvas. The rectangle has a MouseDragElementBehavior attached to it, so it can move freely in the canvas.
I need to calculate the position of the rectangle after each drag. The problem is that the
Canvas.GetTop(rectangle1)
only works for the first time, i.e. before the rectangle is dragged. After the drag, the method call returns the initial position.
Those behaviors usually work by applying a RenderTransform, if it uses a TranslateTransform you can get the offset value from that and add it to the canvas position.
Alternatively you might just want to implement your own dragging logic.

How do I get the co-ordinates of a mouse click on a transformed WPF control?

I'm playing with a simple WPF application. One part of it includes a grid containing several controls. The grid is rotated using a LayoutTransform and a RotateTransform. I need to get the co-ordinates of a mouse-click relative to the top-left of the grid, taking the rotation into account.
To be clear, let's say I have a single drawing surface within the grid and no transform had been applied. I then click at location X = 20, Y = 10 and put a dot on the drawing surface at that point. If the grid is now rotated by 30 degrees and I click on the dot (which is also moved by the rotation), the click position should still be X = 20, Y = 10.
MouseEventArgs has a GetPosition method that takes a UIElement. It returns the position of the mouse event relative to the specified element. So if you want to transform a mouse click into coordinates of a grid, pass that grid to the GetPosition method.

Resources