sylvrynne
asked on
Can I resize a TImage by dragging ?
I have dynamically created TImage objects that I want to be able to resize. At the moment I am doing it by a mouse click event eg if R_Mouse_Button clicked double in size ... but this is pretty cruddy. I want to be able to grab a handle and resize it to any size. I notice that there is no OnResize() function for a TImage in BCB 4 if you create them at design time.
ASKER
some sample code would be great !!!!!! if you have the time
thankyou so much .... if i give you the points can you still post comments so I can get the code?
thankyou so much .... if i give you the points can you still post comments so I can get the code?
The answer is yes you can, but here's the code now...
You need to create a new Package and then a new component based on TImage (which is what I did), then do something like the following. I did this pretty quick so it's not the most efficient code ever, but it works.
If you want to resize in other directions etc you'll have to extend obviously...
I'll put the code in two separate comments, the first is the cpp and the second the header.
You need to create a new Package and then a new component based on TImage (which is what I did), then do something like the following. I did this pretty quick so it's not the most efficient code ever, but it works.
If you want to resize in other directions etc you'll have to extend obviously...
I'll put the code in two separate comments, the first is the cpp and the second the header.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//------------------------ ---------- ---------- ---------- ---------- ---------- -
#ifndef ResizeImageH
#define ResizeImageH
//------------------------ ---------- ---------- ---------- ---------- ---------- -
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//------------------------ ---------- ---------- ---------- ---------- ---------- -
class PACKAGE TResizeImage : public TImage
{
private:
void __fastcall mMouseMove(TMessage &Message);
void __fastcall mLButtonDown(TMessage &Message);
void __fastcall mLButtonUp(TMessage &Message);
void __fastcall DrawSize();
protected:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MOUSEMO VE, TMessage, mMouseMove)
MESSAGE_HANDLER(WM_LBUTTON DOWN, TMessage, mLButtonDown)
MESSAGE_HANDLER(WM_LBUTTON UP, TMessage, mLButtonUp)
END_MESSAGE_MAP(TImage)
public:
__fastcall TResizeImage(TComponent* Owner);
bool resizing;
int sw, sh;
__published:
__property OnResize;
};
//------------------------ ---------- ---------- ---------- ---------- ---------- -
#endif
#ifndef ResizeImageH
#define ResizeImageH
//------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//------------------------
class PACKAGE TResizeImage : public TImage
{
private:
void __fastcall mMouseMove(TMessage &Message);
void __fastcall mLButtonDown(TMessage &Message);
void __fastcall mLButtonUp(TMessage &Message);
void __fastcall DrawSize();
protected:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MOUSEMO
MESSAGE_HANDLER(WM_LBUTTON
MESSAGE_HANDLER(WM_LBUTTON
END_MESSAGE_MAP(TImage)
public:
__fastcall TResizeImage(TComponent* Owner);
bool resizing;
int sw, sh;
__published:
__property OnResize;
};
//------------------------
#endif
ASKER
Thats great ... thanx
I'd recommend creating a descendant of TImage, say TResizImage or the like, then you can publish the OnResize event (as it does exist just hasn't been made available) and write the code to allow the user to resize it.
You'd have to write all the code for resizing it - not too hard, just use the OnMouseMove to check if the cursor is at the edge of the control, if it is change the mousepointer to the appropraite resizer cursor. Then OnMouseDown you capture the cursor and wait till they release it (drawing whatever you like as they move the cursor) and then when they let go, resize it.
If you'd like some sample code just say... I can throw some together.