Link to home
Start Free TrialLog in
Avatar of K Feening
K FeeningFlag for Australia

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
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)

Open in new window

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)


Open in new window


Avatar of Kimputer
Kimputer

That's not gonna work well. You can't predict the length of the text, as text can't never uniformly calculated as three i's is smaller than 3 o's
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)
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
ASKER CERTIFIED SOLUTION
Avatar of K Feening
K Feening
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial