|
-
Nov 9th, 2009, 12:01 PM
#1
Thread Starter
Member
Custom control as a class? *(Resolved)*
First I would like to again thank kleinma for assisting me with the below code.
What I would like to do now is well convert this somehow to a class. so I do not have to DirectCast the items. Is this possible?
Here is the original code that kleinma assisted me with:
Dim CtlLosArray(150) As ShieldLOSInfobox
CtlLosArray(0) = New ShieldLOSInfobox
CtlLosArray(0).Location = New Point(0, 0)
CtlLosArray(0).Visible = True
CtlLosArray(0).Show()
CtlLosArray(0).Name = "Label1"
Me.pnlLOS.Controls.Add(CtlLosArray(0))
DirectCast(Me.pnlLOS.Controls("Label1"), ShieldLOSInfobox).Textbox1.Text = "HELLO WORLD"
Now with this line right here:
DirectCast(Me.pnlLOS.Controls("Label1"), ShieldLOSInfobox).Textbox1.Text = "HELLO WORLD"
I would like to do something like this instead
CtlLosArray(1).Textbox1.text = "Hello World"
Is there a way to make this into a custom class so that I can make things easier to manipulate? at least that is how I think it would be done.
I appreciate everyone assistance.
Mythos
Last edited by Mythos44; Nov 9th, 2009 at 02:09 PM.
Reason: *Resolved*
-
Nov 9th, 2009, 12:34 PM
#2
Re: Custom control as a class?
What is pnlLOS?
Anyway, how do you expect this to work? If you do a 'search' in the Controls collection, then it's impossible to have it return the actual type of the control, simply because the Controls collection can contain any control. In order for it to return a TextBox as an item, it would have to be some kind of array, collection, whatever of TextBoxes. But then, it can only contain TextBoxes and nothing else.
So, you can get a collection of TextBoxes, or Buttons, or Panels, and they can return a single TextBox, Button or Panel object, but if you want one collection that holds them all, then you must choose a type that all of them inherit. In the case of controls, that class is the Control class, which is why the Controls collection returns items of type Control. If you then want to use a member (method, field, etc) that is specific to a certain control, then you must use casting.
-
Nov 9th, 2009, 12:51 PM
#3
Re: Custom control as a class?
If you declared your array of ShieldLOSInfobox controls at class level, then you could always access them the way you want - assuming you know the array index of the one you want to work with.
another way is to cast the control to the ShieldLOSInfobox class once as a variable and then just use that variable.
dim Box1 as ShieldLOSInfobox
Box1 = DirectCast(Me.pnlLOS.Controls("Label1"), ShieldLOSInfobox)
with Box1
.textbox.text = "blah"
.nextproperty = somevalue
...
...
end with
Something like that anyway.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Nov 9th, 2009, 02:08 PM
#4
Thread Starter
Member
Re: Custom control as a class?
Thank you dolot that worked great.
Mythos
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
|