I'm making a screenshot program that lets me position a secondary form and press a button in the main form to take a screenshot where the second form is located. I have the second form set to have no border (so no title bar), and to be transparent so I can see what I'm taking a screenshot of. I've set a panel in the middle that uses the SizeAll cursor, to indicate that you click and drag there to move the area around.
I've got the moving working, using this code:
The problem is that the movement happens from the top-left corner of the panel (which is centered in the form,) and not from where I actually click within the panel. Essentially I want to click at, say, 6x6 in the panel and have my mouse be locked to that position while I'm moving the form around. What happens is I'll click at 6x6 and as soon as I move my mouse a single pixel, the form will snap so that the cursor is at the top-left corner of the panel. How can I make is so that it won't do that snapping to the top-left corner?
I can't for the life of me figure it out. Any help would be greatly appreciated.
As a side note, I'm also going to be doing this for resizing the form, and it's gonna do the same thing, snapping the size box (set into the corners of the form) so that the mouse is at the top-left of the size handle.
Edit: I found a way to make this work, but I'd still like other suggestions. Basically I created a second panel, exactly the same as the main movement panel, and in the same position, but hidden. When I mouse down on the main panel, it gets moved the the x,y coordinates of my mouse then sized down to 0x0, and the secondary panel is made visible. Since I'm moving based on the position of the main panel, and since no matter where I click it'll always be 0x0 (the top-left corner) since I resized, and the secondary panel behind it shows in the exact same place as the original, it looks as though you're grabbing the handle from wherever you clicked it at. Of course, this is a hack and I'd rather do it the right way, if there is such a way, so I'd still love some suggestions.
I've got the moving working, using this code:
Code:
this.Location = new Point((this.Location.X + e.Location.X), (this.Location.Y + e.Location.Y));
I can't for the life of me figure it out. Any help would be greatly appreciated.
As a side note, I'm also going to be doing this for resizing the form, and it's gonna do the same thing, snapping the size box (set into the corners of the form) so that the mouse is at the top-left of the size handle.
Edit: I found a way to make this work, but I'd still like other suggestions. Basically I created a second panel, exactly the same as the main movement panel, and in the same position, but hidden. When I mouse down on the main panel, it gets moved the the x,y coordinates of my mouse then sized down to 0x0, and the secondary panel is made visible. Since I'm moving based on the position of the main panel, and since no matter where I click it'll always be 0x0 (the top-left corner) since I resized, and the secondary panel behind it shows in the exact same place as the original, it looks as though you're grabbing the handle from wherever you clicked it at. Of course, this is a hack and I'd rather do it the right way, if there is such a way, so I'd still love some suggestions.
Comment