Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and drop on VCL components

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
0
16
I want to build an application that shows images like a flow chart. Which component would be the best choice to draw the pictures.
I mean a TImage has a canvas on which I can draw, but it does not have scroll bars. A TScrollBox does have the bars but no canvas.
Does anybody know of a VCL component which has horizontal and vertical scroll bars, a canvas, and drag&drop events?
 
You can place a TImage on a TScrollBox and set the Top and Left properties of the TImage to zero. I like to remove all trace of the border of the TScrollBox so the TScrollBox 'blends' into the background. That way the TImage appears to have the scroll bars.

Steve.
 
I tried tis code:

Code:
    TGraphic *g = Image1->Picture->Graphic;
    Image2->AutoSize = true;
    Image2->Canvas->Draw(100,100,g);
    Image2->Canvas->Draw(10000,10000,g);

I expected Image2 to expand to the size needed to fit the expanded image. Image2, width 700, height 500, fits snug inside the ScrollBox.
No Scrollbars appear.
 
Perhaps you need to size at run-time Image2 to be big enough to hold the two copies of Image1. From what I see in your code, two copies of Image1 should be placed at 100, 100 and 10000, 10000.

If you are wanting to place two copies of Image1 on Image2 at different X - Y locations, consider the following code:

Code:
	int iTopMost = 1000, iLeftMost = 1000;

	Image2->Height = iTopMost + Image1->Height;
	Image2->Width = iLeftMost + Image1->Width;
	Image2->Canvas->Draw(iLeftMost, iTopMost, Image1->Picture->Graphic);
	Image2->Canvas->Draw(100, 100, Image1->Picture->Graphic);

This code will place both images at the correct spots on your Image1 and scroll bars will appear on the TScrollBox. Since you are drawing Image1 onto the TCanvas of Image2, I don't think AutoSize is what you want.

I hope this helps.

Steve.
 
I hoped that I could do the job without calculating the size of Image2 and expected that AutoSize would do this for me.
So I have to create a new control. A descendant of TScrollBox and TImage.
If you might find another control that's more suitable, please let me know before I finish my own :)

thanks for your help.
 
Your code does not always work. Once you have written a small inmage in the top-left corner, you cannot resize the image anymore.
Please try this:
Code:
    int iTopMost = 1000, iLeftMost = 1000;

    Image2->Canvas->Draw(100, 100, Image1->Picture->Graphic);
    //Once you have written to the canvas
    //Resizing is no longer pssible

    Image2->Height = iTopMost + Image1->Height;
    Image2->Width = iLeftMost + Image1->Width;

    Image2->Canvas->Draw(100, 100, Image1->Picture->Graphic);
    Image2->Canvas->Draw(iLeftMost, iTopMost, Image1->Picture->Graphic);
 
Hello Hennep,

Don't you need to resize the bitmap as well.

int iTopMost = 1000, iLeftMost = 1000;

Image2->Canvas->Draw(100, 100, Image1->Picture->Graphic);

// Extra code to change bitmap size.
Image2->Picture->Bitmap->Width= iLeftMost + Image1->Width;
Image2->Picture->Bitmap->Height= iTopMost + Image1->Height;

Image2->Height = iTopMost + Image1->Height;
Image2->Width = iLeftMost + Image1->Width;

Image2->Canvas->Draw(100, 100, Image1->Picture->Graphic);
Image2->Canvas->Draw(iLeftMost, iTopMost, Image1->Picture->Graphic);

Hope that helps you friend.

Regards
Blue.
 
You've solved it, thanks alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top