hey everyone. can anyone tell me how to reference a control's properties (like a textbox width) that is placed on a tabcontrols tabpage
thanks
Printable View
hey everyone. can anyone tell me how to reference a control's properties (like a textbox width) that is placed on a tabcontrols tabpage
thanks
The fact that it's on a TabPage makes no difference if it was added at design time. You access the control via the same member variable regardless of its parent. Me.TextBox1 is the first TextBox you added to the form regardless of whether it's on the form, a TabPage, or in a GroupBox within a Panel.
That said, you can always access any containers child controls via its Controls collection. All the controls added directly to the form are in the form's Controls collection. All the controls added to a TabPage are in the TabPage's Controls collection. You can index any container's Controls collection by the ordinal (numeric index) or key (name) of the child control.
i guess is should have more specific. the control i want to reference is created at run time. the code is below
PHP Code:Function GetTop(ByRef GetPageName, ByRef GetQName)
On Error GoTo errorhandler
Dim NewTop
Dim QTop
QTop = Form1.TabControl1.TabPages(GetPageName).controls(GetQName).top
'where GetPageName is the name of the page the control is on
'and GetQName is the name of the control i want to reference
MsgBox(QTop)
Return QTop
errorhandler:
If Err.Number = 0 Then
Else
MsgBox(Err.Description)
End If
End Function
if get the error: Object variable or with block variable not set
Yes, you should have been more specific. You should always give the full story from the start.
Any time you get a NullReferenceException, the first thing to do is to establish which reference is null. In your case you need to determine whether this:is Nothing or this:vb.net Code:
Form1.TabControl1.TabPages(GetPageName)is Nothing. If you don't actually know what problem you're trying to solve then it can make it difficult to solve it.vb.net Code:
Form1.TabControl1.TabPages(GetPageName).controls(GetQName)
On an unrelated note, you're doing something there which, while legal, is very poor practice. NEVER, EVER declare anything without a type. What are these supposed to be:If they're supposed to be Integers then declare tham as such. Otherwise they're both type Object regardless of what you assign to them. You obviously have Option Strict Off, which I suggest you set to On immediately. Option Strict On would not allow you to do things like declare variables without types.Code:Dim NewTop
Dim QTop
thanks. still kind of new to this. as it turns out one of my values coming in from the function call was null. it works fine now
That person last posted in 2009, so you're unlikely to get a response. It's generally a bad idea to resurrect ancient threads. Basically, if what you are doing is not working then you're doing it wrong. As you haven't bothered to show us what you're doing, we can't tell you what's wrong with it. You should start your own thread and do as everyone should do, i.e. provide a FULL and CLEAR explanation of the problem. Explain exactly what you're trying to achieve, how you're trying to achieve it and what happens when you try. You can provide a link to this thread if you think that doing so would add value. You will have a much better chance of getting help from a range of people with a new thread than one that's over a decade old and marked Resolved. I would have ignored your post, except that I was already subscribed to this thread and got a notification. Everyone else who didn't is unlikely to see your post.