Using Designer I have a panel with coordinates defined by (left,top,width,height). I want to create a rectangle covering the panel. Unfortunately, the rectangle properties are defined differently as (left,top,right,bottom), and I am struggling to get the right values from the panel properties. How to get the rectangle properties from the panel properties?
Thanks, positrom2
Thanks, Mahares,
I had already done as you suggested, but it does not work (the panel color does not change to black).
The panel properties in designer are:
left=0, top=480,width=220,height=300.
The code looks like
B4X:
Dim pnlpeaks As Panel
Dim rect1 As Rect
cvspeaks.Initialize(pnlpeaks)
rect1.Initialize(0, 480, 220, 780)
cvspeaks.DrawRect(rect1, Colors.Black, True, 1)
Activity.invalidate
The color of the panel does not change.
With another rectangle, on a different canvas, painting the panel in black works. But there I had initialized the rectangle for a panel with coordinates
left=220,top=310,width=380,height=470 by
B4X:
rect2.Initialize(0, 0, 100%x, 100%y)
Is there a misunderstanding in the coordinate designations?
@positrom: I created on the designer a layout called Rectangle 480x800, with scale:1. I put a panel on it called: pnlPeaks. The panel has the same dimensions as yours: L=0, T=480, W=220 and H=300. See below code where I was able to overlap the rectangle to the panel background. I hope this is what you are looking to achieve.
B4X:
Dim Rect1 As Rect
Dim pnlPeaks As Panel
Dim cvspeaks As Canvas
Activity.LoadLayout("Rectangle")
cvspeaks.Initialize(pnlPeaks) 'Canvas is drawn on panel background
Rect1.Initialize(0,0,220dip,300dip)
cvspeaks.DrawRect(Rect1,Colors.Red,True,0dip)
Mahares,
Yes, that works. So what I learn is that rectangles drawn on a panel will have their origin in the left, top corner of the panel. Then R=W and B=H which is easy. Maybe I missed that rule when I searched on this issue.
Thanks, positrom2