|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How to resize an ImageCtrl to fit the Image?
How to resize an ImageCtrl to fit the Image? [message #5549] |
Mon, 02 October 2006 16:17 |
James Thomas
Messages: 26 Registered: June 2006
|
Promising Member |
|
|
I'd like to be able to load an arbitary image into an ImageCtrl and set the size of control (inc. frames) to match the size of the image. I'd really like to do this while preserving the auto-layout set with the designer, so that if it's position was set with HLeftPos or HRightPos it keeps this behaviour.
Setting the Image is easy but I've tried resizing it using all of the obvious functions accessible in Ctrl but without any success. Is this possible? Am I missing something obvious?
Thanks in advance.
[Updated on: Mon, 02 October 2006 16:19] Report message to a moderator
|
|
|
|
Re: How to resize an ImageCtrl to fit the Image? [message #5625 is a reply to message #5550] |
Fri, 06 October 2006 11:07 |
James Thomas
Messages: 26 Registered: June 2006
|
Promising Member |
|
|
Sorry it's taken a while to reply, I've been away all week.
SetRect was the first thing I tried, but using it causes strange behaviour in my app which I assumed was normal until I read your post.
The problem is that if I run the following two lines in the constructor (after CtrlLayout of course)
Rect r = _imgLogo.GetRect();
_imgLogo.SetRect(r);
the control moves to a different place in the window. If you then call GetRect again the returned rectangle is exactly as you would expect (ie no change). Perhaps something else has changed?
Unfortunately I have been unable to reproduce this in a simple example, but clearly this is the wrong behaviour. If you have any suggestions as to how I might fix/trace this they would be greatly appreciated, though I understand this is difficult until I can reproduce it.
Cheers.
EDIT: This happens with both 605 and dev-2 versions.
[Updated on: Fri, 06 October 2006 11:18] Report message to a moderator
|
|
|
|
|
|
Re: How to resize an ImageCtrl to fit the Image? [message #5695 is a reply to message #5691] |
Tue, 10 October 2006 12:41 |
James Thomas
Messages: 26 Registered: June 2006
|
Promising Member |
|
|
Ah ha! I don't think I'd quite understood how logical positions worked. LogC members a & b are similar to position and size but relative to the anchor, except when SizePos is used, correct?
Basically the code I was looking for is this:
Size sz = ctrl.AddFrameSize(img->GetSize());
// Resize ctrl
Ctrl::LogPos p = ctrl.GetPos();
p.x.SetB(sz.cx);
p.y.SetB(sz.cy);
ctrl.SetPos(p);
I realise this won't work for all cases, but it's good enough for now.
I really should have seen this straight away but I haven't written a GUI in anything that does layouts like this before so it took a while for me to clock it. It's always the simple things in U++ that get me stuck.
Thanks for your patience
[Updated on: Tue, 10 October 2006 13:53] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sat May 11 12:03:21 CEST 2024
Total time taken to generate the page: 0.02051 seconds
|
|
|