Board index » cppbuilder » Drawing lines
Michele Santucci
CBuilder Developer |
Michele Santucci
CBuilder Developer |
Drawing lines2004-06-21 08:21:23 PM cppbuilder65 I have to draw interactively lines and shapes over a form . What's the most indicate kind of component? TPaintBox? -- ================================ Michele Santucci Software Development Manager Celin Avio S.r.l. Via Fontevivo, 21/M 19100 La Spezia tel. +39-0187564080 ================================ |
JD
CBuilder Developer |
2004-06-21 08:46:46 PM
Re:Drawing lines
"Michele Santucci" < XXXX@XXXXX.COM >wrote:
QuoteI have to draw interactively lines and shapes over a form . What's the most In the mean time, look at TShape and TChart. ~ JD |
Michele Santucci
CBuilder Developer |
2004-06-21 09:14:36 PM
Re:Drawing lines
I've to write a simple application where the user can draw a poly line
interactively (i.e. drawing the first segment, then the second one ... whit a simple point, click & draw mechanism ) every node of the line (the junction between two different segments) then should then become editable/moveable. For what I can see the TShape object doesn't support user inputs since is a nonwindowed control. "JD" < XXXX@XXXXX.COM >ha scritto nel messaggio Quote
{smallsort} |
Steve Aletto
CBuilder Developer |
2004-06-21 11:16:39 PM
Re:Drawing linesQuoteI've to write a simple application where the user can draw a poly this is really a bad-written code and surely it needs to be checked in deep, but I hope it could be helpful. It works on a form canvas direcly. Clicking on the form the polygon is draw, instead if you hold Ctrl and drag a point, the point is moved and the polygon entirely redraw. Remember, this really isn't the best solution at all (but it took only 5 mins, as well). Suggestions are welcome :-). //-------------------------------------------------------------------- ------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <vector> //-------------------------------------------------------------------- ------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //-------------------------------------------------------------------- ------- std::vector<Windows::TPoint>Points; int MovingPoint = -1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //-------------------------------------------------------------------- ------- void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssCtrl)) { std::vector<Windows::TPoint>::iterator iter; for (iter = Points.begin(); iter < Points.end(); iter++) { if ((abs(iter->x - X) < 3) && (abs(iter->y - Y) < 3)) { MovingPoint = iter - Points.begin(); break; } } } else { MovingPoint = -1; Points.push_back(Point(X, Y)); DrawAll(); } } //-------------------------------------------------------------------- ------- void __fastcall TForm1::DrawAll(void) { if (Points.size()>1) { Form1->Canvas->FillRect(Form1->ClientRect); std::vector<Windows::TPoint>::iterator iter = Points.begin(); Form1->Canvas->MoveTo(iter->x, iter->y); Form1->Canvas->Ellipse(iter->x - 2, iter->y - 2, iter->x + 2, iter->y + 2); iter++; for (; iter < Points.end(); iter++) { Form1->Canvas->LineTo(iter->x, iter->y); Form1->Canvas->Ellipse(iter->x - 2, iter->y - 2, iter->x + 2, iter->y + 2); } } } //-------------------------------------------------------------------- ------- void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssCtrl)) { if (MovingPoint != -1) { Points[MovingPoint].x = X; Points[MovingPoint].y = Y; DrawAll(); } } else MovingPoint = -1; } //-------------------------------------------------------------------- ------- void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MovingPoint = -1; } //-------------------------------------------------------------------- ------- HTH, Steve. |
Kelly J. Burke
CBuilder Developer |
2005-10-15 12:43:38 AM
Re:Drawing lines
Hello,
I am running Turbo Pascal 1.5 for Windows and constructing a program that needs to be able to draw lines at various angles. To accomplish this I am either going to try and import a bitmap that I created in an outside program, such as Paint, and display it in pascal, or create a bitmap inside of pascal and use the polyline function to draw lines, with the default pen. Which one of these are easier? I have read the manual, and the help section of Pascal and found the information there to be insufficent. Would it be possible for someone to make a simple program that utilizes one of these functions, so that I can analyze it? Please foward all answers to burnedfaceless_at_gmail_dot_com. Thank you, Brian Abbott |
kbarthelmess
CBuilder Developer |
2005-10-15 08:04:44 PM
Re:Drawing lines
"Kelly J. Burke" < XXXX@XXXXX.COM >wrote:
QuoteI am running Turbo Pascal 1.5 for Windows and constructing a program that the starting and ending coordinates and simply draw directly to the display. Good luck. Kurt |
george
CBuilder Developer |
2007-09-25 12:34:52 AM
Re:Drawing lines
I am new to drawing and have the following problem;
Canvas->MoveTo(sx,sy); // memo2 left,top,height,width ex=Memo3->Left+(Memo3->Width)/2; ey=Memo3->Top+(Memo3->Height)/2; Canvas->LineTo(ex,ey); //memo3 If the Memos are contained in a richedit the line does not show until I make the RE invisible. How else can I make the line appear on top? |
Remy Lebeau (TeamB)
CBuilder Developer |
2007-09-25 02:18:27 AM
Re:Drawing lines
"george" < XXXX@XXXXX.COM >wrote in message
QuoteCanvas->MoveTo(sx,sy); // memo2 left,top,height,width QuoteIf the Memos are contained in a richedit the line does not show until I then of course it is going to appear behind the controls. That is what it is supposed to do. QuoteHow else can I make the line appear on top? on top of everything). Gambit |
George
CBuilder Developer |
2007-09-25 09:09:22 PM
Re:Drawing lines
OK, that looks good; I will experiment with what you have written.
Thanks a lot, George "Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote: Quote
|
george
CBuilder Developer |
2007-09-25 10:03:30 PM
Re:Drawing lines
How do I specify which Canvas I want to use? I am new to canvases and none of the examples seem to set the canvas; they just go straight in. How can I do either of the suggestions? Use the control's canvas or the screen's?
George. "Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote: Quote
|
Remy Lebeau (TeamB)
CBuilder Developer |
2007-09-26 12:48:14 AM
Re:Drawing lines
"george" < XXXX@XXXXX.COM >wrote in message
QuoteHow do I specify which Canvas I want to use? QuoteHow can I do either of the suggestions? Quoteor the screen's? to get the HDC for the screen. If you wan, you can instantiate an instance of TCanvas and assign the HDC to the Canvas's Handle property. Gambit |
george
CBuilder Developer |
2007-09-26 02:53:40 AM
Re:Drawing lines
Yes I looked at TControlCanvas but it doesn't tell me how to link to the control.
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote: Quote
|
Remy Lebeau (TeamB)
CBuilder Developer |
2007-09-26 04:19:09 AM
Re:Drawing lines
"george" < XXXX@XXXXX.COM >wrote in message
QuoteYes I looked at TControlCanvas but it doesn't Gambit |
george
CBuilder Developer |
2007-09-27 07:14:54 PM
Re:Drawing lines
Thank you, Remy, for all that. I can now draw lines where I want. I was looking for a Canvas property under TControl.
George. "Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote: Quote
|