Stretchable and movable line
-
hi i am working on a project which has a few capabilities of circuit maker can someone help me making a line in c# such that it can be stretched and compressed, can be deletd, moved,etc thanks in advance Sameer Sood
If the line is persistent, you need to draw it in your OnPaint. IF you want to draw a drag line that will disappear, you can use CreateGraphics to do it. You're going to have to handle all your mouse events, and call Invalidate() to force a paint event, if you're going to draw in OnPaint.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
If the line is persistent, you need to draw it in your OnPaint. IF you want to draw a drag line that will disappear, you can use CreateGraphics to do it. You're going to have to handle all your mouse events, and call Invalidate() to force a paint event, if you're going to draw in OnPaint.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
tnx for the reply bt i also understand that some events have to be handled, bt the question is how, and wat role does onpaint play here Sameer Sood :-O
Well, onpaint is where drawing happens, and you want to draw a line, right ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Well, onpaint is where drawing happens, and you want to draw a line, right ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Well, onpaint is where drawing happens, and you want to draw a line, right ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
since this is not a graphic-only problem, you will have to do more than just override some controls onpaint method. you also will have to handle the "physics" of the line. If you even are not familiar with drawing, you should start reading some GDI+ tutorials - there you will learn to create basic (and more advanced) shapes and how to handle the whole drawing stuff. when you got familiar with it, you will have a basic knowledge about drawing and you also will get an idea on how to realize what you want to do. to sum it up - there is no qnd solution for your problem i would know of - start learning to draw with gdi+ :) // edit: some strategies ;) you could do it like this: you have a lineclass which has some properties - XStart, YStart (Maybe a point object called start? :), XEnd, YEnd. Now you will have to put add an eventlistener to the click event. when the mousebutton is clicked, you will have to check whether its near the line or not. if it is near the line, you will have to remember the mousecursor position and add a eventlistener to the mouseup event. when this happens, you will have a difference between the old and the new cursor position. you can take this value to modify your line object which is drawn by the onpaint method. sounds a bit complicated but it isn't that difficulty at all...
-
ok that is clear bt how to move it and give it funstion like press delete key to delte it and enable selection on it and make it stretchable there are lots of questions, tell me the methods and strategies , i have no idea.
Sameer Sood :-O
Sounds to me like you want my rates to write it for you :-) First, you need to store your lines in a collection and draw them in your paint method. Then you need to write code to draw lines as you drag the mouse and add them to your collection when you lift the mouse. If you want to select lines by drawing on them, you need to write code that works out if a pixel is close enough to a line to select it, probably first by working out if it's in the bounds of the box the line defines, then by walking the line if need be. Once you can select a line, you delete it by removing it from your collection, and calling Invalidate() ( which will redraw all the lines bar the one no longer there ). If you want to be able to click and drag it, then you basically want to draw focus points on the ends of the selected image, if you click inside one, you remove it from the collection, but make it the line being drawn, then your code to add lines will also allow you to move it. Lots to do. In the first instance, make sure you understand the way Windows draws stuff, and crack a good GDI+ book.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
since this is not a graphic-only problem, you will have to do more than just override some controls onpaint method. you also will have to handle the "physics" of the line. If you even are not familiar with drawing, you should start reading some GDI+ tutorials - there you will learn to create basic (and more advanced) shapes and how to handle the whole drawing stuff. when you got familiar with it, you will have a basic knowledge about drawing and you also will get an idea on how to realize what you want to do. to sum it up - there is no qnd solution for your problem i would know of - start learning to draw with gdi+ :) // edit: some strategies ;) you could do it like this: you have a lineclass which has some properties - XStart, YStart (Maybe a point object called start? :), XEnd, YEnd. Now you will have to put add an eventlistener to the click event. when the mousebutton is clicked, you will have to check whether its near the line or not. if it is near the line, you will have to remember the mousecursor position and add a eventlistener to the mouseup event. when this happens, you will have a difference between the old and the new cursor position. you can take this value to modify your line object which is drawn by the onpaint method. sounds a bit complicated but it isn't that difficulty at all...
now that's like a professional Tnx for the replies, i 'll learn gdi+ , bt mikone u must knw that there will be not one but many lines in my case as i am going to make a tool that will make Data flow diagrams like smartdraw, its a college assignment. i 'll try and post again if i have more such problems tnx again
Sameer Sood :-O