Le 29 janv. 2016 à 16:18, Jean-Luc Arnaud <[email protected]> a écrit:

> Hi all,
> 
> I would like to manage a selection rectangle in a canvas, with handles 
> to modify its width and height, and the possibility to move it around 
> the canvas.
> I know how to draw such a rectangle, but I don't know how to create 
> active handles (I mean something reacting when the cursor moves in) or 
> active borders, nor how to code the resizing of the selection rectangle.
> 
> I'm sure there is something in the MBS plugin, but I don't know what 
> looking for: selection rectangle? Highlighted rectangle? Highlighted 
> selection?

Hello Jean-Luc,

Making your own is really simple. I'm going to give you some tracks. I 
recommend making a distinct class (based on canvas) so the properties won't end 
up in the window itself.

I've written this from hand, I hope I've not made a mistake.
In you canvas (where everything will be done, unless stated), add these 
properties: Selection() as integer, ClickedCorner As Integer=-1
When Selection is an empty array, it means there's no selection; else, we 
expect it to have a size of 7 (0-7), with x and y for each bound.
ClickedCorner is meant to know what the user has clicked.

First part, the selection:
In the MouseDown event:
Selection=Array(x,y,x,y,x,y,x,y) //All bounds default to the origin
Return True

In the MouseDrag:
Selection(2)=x 'New x for the right-top corner
Selection(5)=y 'New y for the left-bottom corner
Selection(6)=x 'New x for the right-bottom corner
Selection(7)=y 'New y for the right-bottom corner
me.refresh false

In the paint event, near the end:
if UBound(Selection)>=7 then
g.ForeColor=HighlightColor
g.DrawRect 
Selection(0),Selection(1),Selection(2)-Selection(0),Selection(3),Selection(4),Selection(5)-Selection(1),Selection(6)-Selection(0),Selection(7)-Selection(1)
end if

Now, add a method like this:
Function GetCornerForXAndY(x as integer,y as integer)
if UBound(selection)<7 then return -1 //No corner exists

if abs(x-selection(0))<5 then 'We're at the left line
if abs(y-selection(1))<5 then Return 0 //Left-Top
if abs(y-selection(7)<5 then Return 2 //Left-Bottom
elseif abs(x-selection(2)<5 then 'We're at the right line
if abs(y-selection(1))<5 then Return 1 //Right-Top
if abs(y-selection(7)<5 then Return 3 //Right-Bottom
end if

(I'll post the remaining later, as I have to go; sorry)
_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
[email protected]
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Reply via email to