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
The example works well as DonManfred said, I wonder how you set the bg color of page2? you'd better post your project.

The project is from Erel's tutorial, no changes were made. After random color from Page 3, when Page2 is resized, the bitmap image holding the Page3 canvas didn't resize with the form thus other areas within the page has different color (https://www.b4x.com/android/forum/attachments/1716438961137-png.153966/)

B4X:
Sub UpdateImage
    If Page3.Panel1.IsInitialized Then
        ImageView1.SetBitmap(Page3.cvs.CreateBitmap)
    End If
End Sub
 
Upvote 0

teddybear

Well-Known 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.
Isn't the background color of cvs B4XCanvas of Page3 the bg color of the panel1 of the B4xpage3? what is the same color as the background color of cvs B4XCanvas of Page3 and how do you set it
 
Upvote 0

JGParamo

Active Member
Licensed User
Isn't the background color of cvs B4XCanvas of Page3 the bg color of the panel1 of the B4xpage3? what is the same color as the background color of cvs B4XCanvas of Page3 and how do you set it
Tried this code within Page2 but did not achieved the intended result
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    If Page3.Panel1.IsInitialized Then
'        ImageView1.Parent.Color = Page3.Panel1.Color
        ImageView1.Parent.SetColorAndBorder(Page3.Panel1.Color, 0, 0, 0)
    End If
End Sub

I am looking for a code snippet that could do it.
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Tried this code within Page2 but did not achieved the intended result
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    If Page3.Panel1.IsInitialized Then
'        ImageView1.Parent.Color = Page3.Panel1.Color
        ImageView1.Parent.SetColorAndBorder(Page3.Panel1.Color, 0, 0, 0)
    End If
End Sub

I am looking for a code snippet that could do it.
I don't know why you would like to add above code in sub B4XPage_Resize of Page2, isn't it the code below
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
       Drawer.Resize(Width, Height)
End Sub
You seem to omit Drawer.Resize(Width, Height)
 
Last edited:
Upvote 0

JGParamo

Active Member
Licensed User
I don't know why you would like to add above code in sub B4XPage_Resize of Page2
Page2 (and Page3) when resized (increased) has certain areas having no filled color similar to the ImageView1. One way I suppose to resolve this is to set the background color of the form to that of ImageView1, another is to make the size of ImageView1 similar to the size of the page.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
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
 

Attachments

  • Project.zip
    191.7 KB · Views: 84
Upvote 1
Solution

JGParamo

Active Member
Licensed User
You missed my message (and my second example).

Edit: if you are not intended to draw something then you don't need to use Canvas and Imageview.
I've tried your sample project aeric and I find teddybear's solution fits my intent. Thanks.
 
Last edited:
Upvote 0

JGParamo

Active Member
Licensed User
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

Great teddybear this does the job. Thank you.
 
Upvote 0
Top