?
Solved

location of control?

Posted on 2006-05-17
7
Medium Priority
?
222 Views
Last Modified: 2011-09-20
I am trying to set the location of this control and I'm getting an error. what am I doing wrong?

Me.Panel3.Controls("Label5").Location = 211
0
Comment
Question by:szx248
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 11

Accepted Solution

by:
anyoneis earned 200 total points
ID: 16706021
Location is not a scalar. It is a Point. So try, assuming you want to set X and keep Y:

Me.Panel3.Controls("Label5").Location = new Point(211, Me.Panel3.Controls("Label5").Location.Y);

David
0
 

Author Comment

by:szx248
ID: 16706058
it still gives me an error (Object reference not set to an instance of an object.)
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16706076
Use the immediate window and verify the assumptions: Evaluate:
Me.Panel3

then Me.Panel3.Controls
then Me.Panel3.Controls("Label5")

Do they all look correct?

David
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:broadbent
ID: 16706907
I presume you added the control?
Me.Panel3.Controls.Add"Label5"
0
 

Author Comment

by:szx248
ID: 16708464
well this line works, would'nt this mean that the panel3 and lable5 are valid?

            Me.Panel1.Controls("Label5").Text = "Customer Payments"
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16708760
You're using Panel1 in that code.

So that means that Label5 is in Panel1, not Panel3...thus the cause of your error before.  You were trying to find Label5 in the wrong place...

For future reference, you can find a control by name like this:  (doesn't matter where the control is located on the form)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ctl As Control = GetControlByName("Label5")
        If Not IsNothing(ctl) Then
            ctl.Location = New Point(211, ctl.Top)
        End If
    End Sub

    Private Function GetControlByName(ByVal ctlName As String) As Control
        Dim ctlReturn As Control = Nothing
        Dim matches() As Control = Me.Controls.Find(ctlName, True)
        If matches.Length > 0 Then
            ctlReturn = matches(0)
        End If
        Return ctlReturn
    End Function


0
 
LVL 4

Expert Comment

by:broadbent
ID: 16708775
Sorry, I misunderstood. You have presumably added the labels through the VS Editor.
in which case New Point(211,0) should at least put the control at the top of Panel1
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question