unfortunately your code already contains a lot of details, making it hard to pinpoint what exactly is the problem. IMHO one should always work on smaller pieces and get them to run satisfactorily before adding to them.
So I will limit my reply to a number of comments, which taken together really indicate I'm not so happy with the current code:
It seems you want a hovering mouse to show what would happen if the mouse were clicked in its current position; that should consist of:
- deciding which if any rectangle is hovered over;
- deciding how it is hit (i.e. in the size handles or in the body).
As size handles overlap the actual rectangle, one must be careful in what order the Contains() logic is applied. I would probably use a slightly larger rectangle and check that first, assuming a move is intended, and on a hit then check whether any of the size handles is hit (which would overrule the move).
Once the mouse goes down, the decision (from #1) should be frozen, and data should be set up to initiate the actual move/resize.
Back in the mouse move handler, the actual action should happen until mouse up is reached.
As a consequence:
- the MouseMove handler should have two completely distinct halves, one for the decision process (mouse still up), one for the execution (mouse down); a single bool (set/cleared by MouseDown/MouseUp) would decide between the halves.
- the MouseDown handler shouldn't do much at all.
If I were creating something like this, I would start from scratch, and initially keep it as simple as possible.
I would also choose variable and method names carefully, e.g. DrawResizableRectNode isn't OK as it does not draw at all.
Added later, two smaller issues I forgot to mention:
There is no need to create a Graphics object explicitly; you get it for free as one of the properties of the PaintEventArgs in a Paint handler.
You should keep Paint handlers as lean as possible, in particular you should create the drawing objects (Pens, Fonts, ...) you need only once, and save them in class level variables for reuse. In your case, that applies to rectPen.
And if you fail to keep them around, it is your duty to dispose of them (by calling their Dispose method or applying a using statement), in order to avoid Windows problems such as handle shortages.
Hope this helps,
modified 27-Apr-20 20:15pm.