|
-
Oct 26th, 2015, 09:00 PM
#1
Thread Starter
Junior Member
VB.NET Nothing Value
I have a code that splits the design of my form.
But when I add this control programmatically the value of m_splitBar is always nothing.
I want this object not to be nothing because I'm performing some manipulations there like,
(bar.FindForm.Width),
In VB6 the equivalent of this is (bar.parent.Width).
The "parent object" in createSplitBar function is the Main Form. i just passing it.
Can someone lend me a hand? I hope you guys understand. Thanks In Advance =)
Private WithEvents m_splitBar As PictureBox
Public Sub createSplitBar(ByVal name As String, ByVal parent As Object)
m_splitBar = parent.Controls.Add(m_splitBar)
setSplitterProperties(m_splitBar)
m_imp.setSplitterProperties(CType(m_splitBar, Control))
End Sub
ANOTHER CLASS:
Public Sub setSplitterProperties(ByRef bar As System.Windows.Forms.Control) 'dito
bar = New System.Windows.Forms.Control
With bar
'.Width = VB6.TwipsToPixelsX(75)
.Cursor = System.Windows.Forms.Cursors.SizeWE
.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(bar.FindForm.Width) / 2)
End With
End Sub
-
Oct 26th, 2015, 09:18 PM
#2
Re: VB.NET Nothing Value
The only place that you assign anything to that variable is here:
Code:
m_splitBar = parent.Controls.Add(m_splitBar)
That line of code makes no sense and, even if it did, it wouldn't help. That Add method is a Sub, not a Function, so it doesn't return anything that you can assign to a variable. Apart from that, what you're adding is the value of the same variable, which has not had anything assigned to it at that point. If you want the variable not to be Nothing then you have to actually assign something to it. Create a PictureBox object and assign it to the variable.
-
Oct 26th, 2015, 09:38 PM
#3
Re: VB.NET Nothing Value
Did you perhaps intend to do this with that line of code:
Code:
m_splitBar = parent.Controls("m_splitBar")
i.e. get a control from the parent by name and assign that to your variable? That's a pretty dodgy thing to do but, as long as the parent has a control with that name, it would work.
-
Oct 26th, 2015, 10:04 PM
#4
Thread Starter
Junior Member
Re: VB.NET Nothing Value
Thanks Sir JM ^_^, but the name of the m_splitBar is equal to "".
In VB6 (when adding a controls):
parent.Controls.add("VB.PictureBox", name, parent) which name is the name of the picturebox and parent is the form.
While in VB.NET, it is just
parent.Controls.Add(m_splitBar) thats why the m_splitbar has a name = "". No Value..
So therefore, we cannot access the picturebox in that form.
Is there a way to access it? Hope you understand.
I really appreciate it.
-
Oct 26th, 2015, 10:21 PM
#5
Re: VB.NET Nothing Value
If a control has no Name it's because you didn't give it one. If you want a control to have a Name then, unless you're adding it in the designer, you have to give it a Name.
That said, there should be no need. The control should be being pushed in from the outside, not pulled in from the inside.
-
Oct 28th, 2015, 07:55 PM
#6
Thread Starter
Junior Member
Re: VB.NET Nothing Value
Hi Sir JM,
Can't figure the meaning of this "The control should be being pushed in from the outside, not pulled in from the inside.".
Can you elaborate it for us?
Thanks,
Les
Last edited by lesterluma; Oct 28th, 2015 at 07:56 PM.
Reason: mispelled
-
Oct 28th, 2015, 09:43 PM
#7
Re: VB.NET Nothing Value
 Originally Posted by lesterluma
Hi Sir JM,
Can't figure the meaning of this "The control should be being pushed in from the outside, not pulled in from the inside.".
Can you elaborate it for us?
Thanks,
Les
It appears to me that you have a user control on a form and that user control needs to make use of another control on the same form. Is that correct? If so then it should be the responsibility of the form to pass the user control a reference to the other control, not the responsibility of the user control to go to the form and get it. The user control should not assume anything about the form it's on other than that it's a form. It should have a property or method that can be accessed from outside, by the form, to pass in a reference to the other control.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|