K Feening
asked on
VB.NET
Hi I am Dynamically in VB.NET creating a label with text I Need to find the width of the label created so I can position a dropdownlist to the right of the label using the same top position
Thanks
Thanks
Dim lbl As New Label
lbl.Style("Position") = "Absolute"
lbl.Style("Top") = "10px"
lbl.Style("Left") = "10px"
lbl.Font.Size = 16
lbl.Text = "This is the text of the label"
lbl.ID = "lbl1"
pBuild.Controls.Add(lbl)
Dim dl As New DropDownList
dl.Style("Position") = "Absolute"
dl.Style("Top") = lbl.Top
dl.Style("Left") = ???????
dl.ID = "ddList1"
dl.Font.Size = 16
pBuild.Controls.Add(dl)
MyControls.Add(dl)
Don't use absolute, change it to relative instead. This will handle the placement for you (also has added benefits like adjusting to a wide screen versus a phone).
https://leannezhang.medium.com/difference-between-css-position-absolute-versus-relative-35f064384c6
https://leannezhang.medium.com/difference-between-css-position-absolute-versus-relative-35f064384c6
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Either calculate it, but it will be wildly different from short to long text. (In your case, you could calculate the text length * 8.2, but the spacing will be bigger, the longer the text. You can't make 8.2 smaller either, because if the text is short, it overlaps)
Or just design your page properly with divs (add controls accordingly)