Image gets lost with orientation change

Discussion in 'Questions (Windows Mobile)' started by HARRY, May 11, 2007.

  1. HARRY

    HARRY Active Member Licensed User

    Erel,

    I create a form on the desk top in landscape orientation; before running the program (A) on the device I set, manually, the screen orientation to landscape. I show an image by some click. It works fine.

    Now I change the orientation either manually or I start in addition another program which also changes the orientation. Returning to program A the image ist lost and also cannot be shown again.

    It sounds complicated, therefore I have attached a small program to illustrate the problem.

    Can you explain these strange things and do you see a solution?

    Harry
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Using the FormLib library you can catch the Resize event.
    You must add a FormLib object to your form if you want to handle screen orientations.
     
  3. HARRY

    HARRY Active Member Licensed User

    Erel,

    As you can see in the test program I sent with the post, there is a FormLib object and the screen orientation change event is caught.

    Harry
     
  4. Cableguy

    Cableguy Expert Licensed User

    Hi,

    Im not an expert in this isue, if any, but in the resize event you should test the witdh and height of the form and re-position it in the form.
    The resize event alone doe not change the form item position, it only allows you to execute code on the resize event...
     
  5. HARRY

    HARRY Active Member Licensed User

    Paulo,

    In the test program I just have one small image positioned in the middel of the screen. Whatever the orientation is, it should be visible without repositioning.

    I worked with and without the resize event. Using the resize event I refreshed the destination rectangel.

    But even loading the image again does't show the image.

    Harry
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    As Cableguy wrote you should use the Resize event to draw (not refresh) the image again.
    All the previous drawings are erased when the user changes the screen orientation.
     
  7. HARRY

    HARRY Active Member Licensed User

    Hi,

    Use of the DrawImage method does not improve the situation. I have attached a somewhat more elaborated test program. Running it you will see the problem. The image cannot be made visible again by (re)drawing it in the resize event nor on a second click on the form. Worst is that I don't see a work around.

    Harry
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You are right there is an issue when you combine a Drawer object and the resize event.
    When the resize event fires a new bitmap is created for the form.
    The solution is to recreate the drawer object again:
    Code:
    Sub Globals

    End Sub

    Sub App_Start
        Form1.Show
        flb1.New1(
    "Form1",B4PObject(1))
        bm1.New1(Apppath & 
    "\Dummy2.bmp")
        drawer1.New1(
    "Form1",false)
        rectsrc.New1(
    0,0,320,240)    
        rectdes.New1(
    100,125,80,60)
        flb1.FullScreen(
    false'this will remove the menu bar and raise the resize event (the screen size changes).
    End Sub

    Sub flb1_resize
        
    if Form1.Width > Form1.Height then
            
    msgbox("Landscape")
        
    else
            
    msgbox("Portrait")
        
    end if
        drawer1.New1(
    "form1",false)
        drawer1.DrawImage1(bm1.Value,rectsrc.Value,rectdes.Value,
    true)
        drawer1.Refresh2(rectdes.Value)
    End Sub    
        

    Sub Form1_MouseUp (x,y)
        
    msgbox ("Form clicked")
        drawer1.DrawImage1(bm1.Value,rectsrc.Value,rectdes.Value,
    true)
        drawer1.Refresh2(rectdes.Value)
    End Sub
     
Loading...