By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

vb-web form - change label location at run-time

P: 5
i got this from the msdn but not really sure how to use it:

Visual Basic (Declaration)
Public Overridable Property Left As Single

Visual Basic (Usage)
Dim instance As Label
Dim value As Single

value = instance.Left

instance.Left = value


would it go like this?

dim lblName as label
dim value as single = 100

lblName.left = value

honestly im have no idea!
please help

and how exactly do i declare it?
just as it is?

Public Overridable Property Left As Single
Apr 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: 1
studentGrammer

You need to use the Left property in conjunction with the Top property to position the object on the parent container:

lblName as Label
lblName.Left = 5
lblName.Top = 10

will position the label 5 pixels across and 10 pixels down from the top left of the parent.

Hope this helps

-=Kombat
Mar 15 '10 #2

Frinavale
Expert Mod 5K+
P: 9,731
Web Form...does that mean you're working with an ASP.NET Label?

In that case you should set either CssClass property or the Style property of for the ASP.NET Label to indicate how it should be displayed in the browser.

Labels are rendered an HTML <span> tag.
These tags have a display:inline style.
This means that you cannot position them left or right unless you either set the position style to absolute and use the top/bottom/left/right style to position the label.....or you could change the display style to block and then use float to position the element...


I don't even know if you know what I'm talking about...but here's an example using the Label's Style property:
Expand|Select|Wrap|Line Numbers
  1. myLabel.Style.Add("display","block")
  2.  
  3. If shouldBeDisplayedOnLeft Then
  4.   myLabel.Style.Add("float","left")
  5. Else
  6.   myLabel.Style.Add("float","right")
  7. End If
  8.  
Here's an example of how to set the CssClass for the Label:
Expand|Select|Wrap|Line Numbers
  1. If shouldBeDisplayedOnLeft Then
  2.   myLabel.CssClass = "displayOnLeft"
  3. Else
  4.   myLabel.CssClass = "displayOnRight"
  5. End If
Where in your CSS you would have the following styles defined:
Expand|Select|Wrap|Line Numbers
  1. .displayOnLeft{
  2.   display: block;
  3.   float: left;
  4. }
  5. .displayOnRight{
  6.   display: block;
  7.   float: right;
  8. }
-Frinny
Mar 17 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.