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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Resizing _Screen Graphic

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

Is there a way to dynamically stretch/resize a picture used as a background as in _screen.picture='my.jpg'?
I don't see anything can get the behavior of resizing the picture when _screen or _vfp is resized.

I guess one could attach a container with an image control embeded to _screen. Then set the image's stretch property to get the behavior?? OK, I don't see a way to do that either...

How would you do this?

Thanks, Stanley

 
Hi tbleken,

Thanks for the tip...

Yes, this appears to do what I want, except for resizing. I'm trying to use a bindevent and hook it to resize method without success. The resize needs to apply to the vfp desktop, or the _screen.

lcImage = gcScreenPhoto &&"Whatever.jpg"
* Center Image
*lcBgType = "CENTER"
* Stretch image
*lcBgType = "STRETCH"
* Stretch image while maintaining its original proportions
lcBgType = "ISOMETRIC"

IF NOT PEMSTATUS(_Screen, "oImg", 5)
_Screen.AddObject("oImg", "Image")
ENDIF

Bindevent(_Screen, "Resize", _Screen, "resize")
*Bindevent(_Screen, "Resize", This, "resize")

WITH _Screen.oImg


Any suggestions,
Thanks, Stanley
 
You can bind to _screen events with BINDEVENT(), bind you don't bind the event to itself. The second call you commented is correct, but it's not enough to bind the sreen resize event to THIS.Resize, yo nee toajut the image width and size in This.Resize (whatever THIS is) and obviuosly THIS has to still exist, when the screen resize event happens.

Bye, Olaf.
 
Hi Olaf,

A simplified version of the code doing isometric from the article referenced above is...

lcImage = "Whatever.jpg"
lcBgType = "ISOMETRIC"

IF NOT PEMSTATUS(_Screen, "oImg", 5)
_Screen.AddObject("oImg", "Image")
ENDIF

WITH _Screen.oImg
.Visible = .F.
.Picture = lcImage
.Stretch = 1
.Height = _Screen.Height
.Width = _Screen.Width
.Top = (_Screen.Height - .Height) / 2
.Left = (_Screen.Width - .Width) / 2
.Visible = .T.
ENDWITH

I put this code near the top of my main.prg. So where would I add the bind events command and to what? maybe the _Screen.oImg object and how? I've never used bind events before... First time for everything, so here goes...

Thanks,
Stanley

 
OK, that just might work... I'll try...

Thanks, Stanley


 
Hi Mike,

Well, it sort of works but not good as it is not applying the isometric property value reliably. It also comes and goes. You can see it by referenceing a small .jpg as the image. I'll have to tinker and test with it more.

Here is what I've tried so far, and its located in the main startup .prg...

gcScreenPhoto = Preference.screen_photo
*_Screen.Picture = gcScreenPhoto

lcImage = gcScreenPhoto &&"Whatever.jpg"

If Not Pemstatus(_Screen, "oImg", 5)
_Screen.AddObject("oImg", "Image")
Endif

*Bindevent(_Screen, "Resize", _Screen, "resize")
*Bindevent(_Screen, "Resize", This, "resize")

With _Screen.oImg
*.Visible = .F.
.Picture = lcImage
.Anchor = 15
.Stretch = 1
.Height = _Screen.Height
.Width = _Screen.Width
.Top = (_Screen.Height - .Height) / 2
.Left = (_Screen.Width - .Width) / 2
.Visible = .T.
Endwith


Any ideas?

Thanks,
Stanley

 
Isometrc Stretching will make a picture keep its proportions, but not enforce the outer form, ie the _screen, to do the same. Therefore you always will get a gap. You can't enforce an isometric stretching.

Bye, Olaf.
 
Also, you need to set the Anchor property after you set the image's Top and Left, not before, as you are doing.

To quote from the Help file:

VFP Help said:
Anchoring is based on the coordinates of the control at the time when the control's Anchor property is originally set, typically, when the control is instantiated. It is not based on the control's current position. Therefore, even after you move a control, anchoring applies to the control's original position.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

I would not do that at all! Leave_screen as it is.
Create a mainform which to be used as your main/screen form, put picture background, menu and all the other stuff you need in your mainform.

Rgds,
Jockey(2)
 
Hi Jockey2,

That would take a lot of effort, "I think??" as I'd be getting away from the native menuing system and normal vfp stuff?? But wait, what is normal anyway? I really don't want to get in an extensive redesign. This app has been running great since 2004 in a fixed size environment. I've just added some new features and wanted to make the whole thing resizable and I have it all working just fine except the _screen stuff, and here we go...

Using your method would use a top level form, correct? Something like a kiosk app with no standard menu, instead you would use command buttons on the top level form? How much trouble would it be to make the conversion, like menu conversions to buttons and how would you handle sub-menus and sub-sub menus? and things like "skip for"? I can see this thread could easily spin into an entirely different thread.

Thanks, Stanley
 
Thanks Mike for the tip, that should help... I'll try it later.

Thanks,
Stanley
 
Hi Olaf,

Yes I understand that isometric will not fully fill the screen whenever the aspect ratio is different. It should fill all the way to the edges one one of the dimensions and all edges when the window is resized to match the aspect ratio of the image.

Would you elaborate more on "not enforce the outer form"?

Thanks,
Stanley
 
>Would you elaborate more on "not enforce the outer form"?

From your description it seemed to me you expected the isometric stretching to enforce the form to only be resizable in the aspect ration of the image, and that is not the case.

Bye, Olaf.
 
Olaf,

>> "not enforce the outer form"
I quoted it from your previous reply... I'm asking you as to what you meant.

Yes I know how aspect ratios apply to isometric and stretched images.

Thanks,
Stanley
 
Well,

I said more

>Isometrc Stretching will ... not enforce the outer form, ie the _screen, to do the same.
Isometric stretching does not enforce the _screen to only resize in ways the image fills the background fully.

It was not your problem, I misunderstood your problem as the image not resizing as you liked it. Mike spotted the real prolem already, didn't he? The time you do the anchroning is of essence, you can't anchor and then init the size, you have to init the size and then anchor.

Bye, Olaf.
 
Jockey2 said:
I would not do that at all! Leave_screen as it is.
Create a mainform which to be used as your main/screen form, put picture background, menu and all the other stuff you need in your mainform.

I have to say that I agree with Stanley. Why go to the trouble of doing that? It's perfectly possible to display the image on the background screen - and also quite a usual thing to do.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>> Also, you need to set the Anchor property after you set the image's Top and Left, not before, as you are doing.

OK, this fixed the resizing correctly once I done this and setting it to stretch. I don't know what I was thinking when I was trying to use isometric here, when I know full well the difference.

Now a new issue happens as soon as you open a form the background dissappears and _screen turns all white. If you resize the main window the background returns. The appearance of the newly opened form causes _screen to go blank. Closing the form does NOT restore the background, you have to resize the main window and it is instantly restored.

When debugging, I added a set step on line 1 of the form's load event. All is well until it runs the "set status off" line located in the load's parent class and the background is gone... I commented out that line and now it works as expected.

Thanks to everyone...

Thanks,
Stanley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top