.net - Draggable text or shapes on an image in C# or VB.NET -
i'm trying create winforms application using either c# or vb.net allow me place text or shape on top of existing image inside picturebox , have text or shape draggable mouse. example, if want place 90x90 square on image, enter 90 in 'width' textbox, 90 in 'height' textbox , click on image , drawn on top of existing image. can position moving mouse want exactly. there other steps if required (like clicking 'insert rectangle' button starts process). i've tried few ideas calling routine resets picturebox it's original image , draws shape when 'mouse move' event raised, slow. should done in paint event of picturebox, , if so, point me in right direction of how it? possible, or oversimplifying idea?
thanks in advance help.
below naive example of how paint draggable rectangle inside parent control.
public class draggable : picturebox { rectangle shapebounds; bool isdragging; point dragpoint; public draggable() { initializecomponent(); shapebounds = new rectangle(10, 10, 30, 30); } protected override void onmousedown(mouseeventargs e) { base.onmousedown(e); if (shapebounds.contains(e.location)) { isdragging = true; dragpoint = new point( e.location.x - shapebounds.location.x, e.location.y - shapebounds.location.y); } } protected override void onmouseup(mouseeventargs e) { base.onmouseup(e); isdragging = false; } protected override void onmousemove(mouseeventargs e) { base.onmousemove(e); if (isdragging) { point p = new point( e.location.x - dragpoint.x, e.location.y - dragpoint.y); shapebounds = new rectangle(p, shapebounds.size); invalidate(); } } protected override void onpaint(painteventargs e) { base.onpaint(e); e.graphics.fillrectangle(brushes.red, shapebounds); } }
Comments
Post a Comment