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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

drawing a line between two points on a tpanel

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


    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, Registered Users 2 Posts: 2,152 ✭✭✭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