P positrom2 Active Member Licensed User Longtime User Aug 11, 2012 #1 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
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
M Mahares Expert Licensed User Longtime User Aug 11, 2012 #2 I think this is what you are looking for. If not, forgive me: Code: Copy Rectangle.left=Panel.Left Rectangle.Top=Panel.Top Rectangle.Right=Panel.Left + Panel.Width Rectangle.Bottom=Panel.Top + Panel.Height Upvote 0
I think this is what you are looking for. If not, forgive me: Code: Copy Rectangle.left=Panel.Left Rectangle.Top=Panel.Top Rectangle.Right=Panel.Left + Panel.Width Rectangle.Bottom=Panel.Top + Panel.Height
P positrom2 Active Member Licensed User Longtime User Aug 11, 2012 #3 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 Code: Copy 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 Code: Copy rect2.Initialize(0, 0, 100%x, 100%y) Is there a misunderstanding in the coordinate designations? Thanks, positrom2 Upvote 0
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 Code: Copy 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 Code: Copy rect2.Initialize(0, 0, 100%x, 100%y) Is there a misunderstanding in the coordinate designations? Thanks, positrom2
Erel B4X founder Staff member Licensed User Longtime User Aug 11, 2012 #4 You should always use dip units when specifying pixel measurements. You should invalidate the panel not the activity. Upvote 0
You should always use dip units when specifying pixel measurements. You should invalidate the panel not the activity.
P positrom2 Active Member Licensed User Longtime User Aug 12, 2012 #5 Erel, thanks, but: You should always use dip units when specifying pixel measurements. Click to expand... but: The beginner's guide tells that The values for the Left, Top, Width and Height properties in the Designer are considered as dip values. Click to expand... I also tried Code: Copy rect1.Initialize(0, 480dip, 220dip, 780dip) with the rect coordinates read out from designer, but it does not give the expected result, whereas (0,0,100%x,100%y) is allright! So it is unclear to me how the coordinate system for rectangle definition is defined and what dip means in the rectangle definition. Thanks, positrom2 Upvote 0
Erel, thanks, but: You should always use dip units when specifying pixel measurements. Click to expand... but: The beginner's guide tells that The values for the Left, Top, Width and Height properties in the Designer are considered as dip values. Click to expand... I also tried Code: Copy rect1.Initialize(0, 480dip, 220dip, 780dip) with the rect coordinates read out from designer, but it does not give the expected result, whereas (0,0,100%x,100%y) is allright! So it is unclear to me how the coordinate system for rectangle definition is defined and what dip means in the rectangle definition. Thanks, positrom2
M Mahares Expert Licensed User Longtime User Aug 12, 2012 #6 @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. Code: Copy 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) Upvote 0
@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. Code: Copy 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)
P positrom2 Active Member Licensed User Longtime User Aug 12, 2012 #7 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 Upvote 0
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