B4J Question [B4X] B4XPages + B4XDrawer -- Setting the "Random Background" Color for the Entire Form [Solved]

JGParamo

Active Member
Licensed User
In Erel's B4X] B4XPages + B4XDrawer tutorial, the sample code does not completely set the "Random Background" color when the form is resized using the mouse. I have tried various code modifications in B4J but to no avail. How could I do it Erel or anyone? Thanks.

1716438961137.png
 
Last edited:
Solution
I got what you mean.
You just need to set the color of panel1.
In B4XPage3
B4X:
Sub B4XPage_MenuClick (Tag As String)
    Dim rc As Int= Rnd(xui.Color_Black, xui.Color_White)
    If Tag = "Random Background" Then
        Panel1.Color=rc
        cvs.DrawRect(cvs.TargetRect,rc, True, 0)
        cvs.Invalidate
    End If
End Sub
In B4XPage2
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    If Page3.Panel1.IsInitialized Then
        ImageView1.Parent.Color = Page3.Panel1.Color
        Drawer.Resize(Width, Height)
    End If
End Sub

Sub UpdateImage
    If Page3.Panel1.IsInitialized Then
        ImageView1.Parent.Color = Page3.Panel1.Color
        ImageView1.SetBitmap(Page3.cvs.CreateBitmap)
    End If
End Sub

JGParamo

Active Member
Licensed User
Upvote 0

JGParamo

Active Member
Licensed User
It does work here

java_UVPgnYGPVB.png

Did you tried resizing/increasing the form size? My observation occurs when increasing form size, particularly when aspect ratio is not maintained.
 
Upvote 0

JGParamo

Active Member
Licensed User
I can't figure-out why mine won't do despite no change was done with the code. Attaching clip.
 

Attachments

  • 2024-05-23-18-36-33.zip
    276.3 KB · Views: 96
Upvote 0

JGParamo

Active Member
Licensed User
Last edited:
Upvote 0

JGParamo

Active Member
Licensed User
Code improvement might be needed but I couldn't figure it out. Did some additional code at B4XPage2 similar with B4XPage3

B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
    ClearImage
    cvs.Resize(Width, Height)
End Sub

something like this

B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
    B4XPages.GetNativeParent(Me).BackColor  = xui.Color_Red
End Sub

but says type mismatch, can't find a way to do it.
 
Last edited:
Upvote 0

JGParamo

Active Member
Licensed User
My intention is to have the Page2 form background have the same color as the background color of cvs B4XCanvas of Page3.
 
Last edited:
Upvote 0

KiloBravo

Active Member
Licensed User
Yes, and after my Page2 form background color "was copied" from Page 3, but it does not resize as I resize page 2. I get the White Edges around the random color. So seems like I get the same result as you.
 
Upvote 0

JGParamo

Active Member
Licensed User
Yes, and after my Page2 form background color "was copied" from Page 3, but it does not resize as I resize page 2. I get the White Edges around the random color. So seems like I get the same result as you.
Thanks KiloBravo, probably Erel can help us on this.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
First, I believe the project is just an example.

Second, the issue is whether you have resized Page 3, after you closed it and you open it again, the window size is back to original size which is 600 X 600.

Third, Page 2 is using an ImageView to load the "saved" image "converted" from Page 3's Canvas.
 

Attachments

  • ThreePagesExample.zip
    192.1 KB · Views: 86
Upvote 0

JGParamo

Active Member
Licensed User
Thanks aeric, upon setting the canvas color randomly in Page3

B4X:
Sub B4XPage_MenuClick (Tag As String)
    If Tag = "Random Background" Then
        cvs.DrawRect(cvs.TargetRect, Rnd(xui.Color_Black, xui.Color_White), True, 0)
        cvs.Invalidate
    End If
End Sub

I intend to use that color as Page2 background color such that any Page2 form size would have that color.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
The example works well as DonManfred said, I wonder how you set the bg color of page2? you'd better post your project.

 
Upvote 0
Top