Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

drawing a line between two points on a tpanel

Options
  • 30-01-2003 1:07pm
    #1
    Registered Users Posts: 2,593 ✭✭✭


    i want to draw a line between startx,starty which are the start positions of the mouse and the current position of the mouse
    this is a snippet of the code that i using but this code will only draw a line on the form that tpanel belongs to not the actual panel itself
    void __fastcall TForm1::mainFrameMouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
    {

    Canvas->MoveTo(startx,starty);
    Canvas->LineTo(X,Y);
    }
    any tips on how to do this would be extremely helpfull
    thanking you
    tommycahir


Comments

  • Registered Users Posts: 2,150 ✭✭✭dazberry


    TPanel does not expose a canvas member (its actually protected in TWinControl).
    In your example the default canvas is that of the form, so by specifying canvas, you are telling it to draw on the form.
    If TPanel.canvas was exposed, you would need to do something like this (sorry its in Delphi, but its would be similar)

    procedure TForm1.mainFrameMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    TPanel(Sender).Canvas.MoveTo(startx,starty);
    etc.
    or
    mainFrame.Canvas.MoveTo
    etc.

    But because as I said the canvas property is not exposed, that won't work.

    You choices are either
    [1] Inherited TPanel into a new component (say TmyPanel) and expose the canvas property (or better yet include the functionality you want in the derived panel.

    [2] Put a TImage inside the canvas and paint on that instead - it will work as my example above TImage(Sender).Canvas.MoveTo() - use the OnMouseDown event from the TImage instead.

    One thing of note: The way you are trying to do this will result in the "drawing" being wiped when the panel is repainted. If you need to keep the drawing there, you will need to use a TImage.

    HTH

    D.


Advertisement