|Thanks for your reply.
Try and try at the end I've found a solution that I'll show you, but I have some questions before.
Eddy Vluggen wrote:"NUD1", the name-property of the
UpDown control, must be unique within the form. It'll generate a variable with that name, and that's what "NUD1" points to; it's not a property of the tabpage, it's the name of a single control.
...and that was the problem: I put a NumericUpDown control in a UserControl and I give it an unique name (NUD1). When, at runtime, I create 10 instances of the UserControl, what are the unique names of the 10 NumericUpDown controls originated from NUD1?
If I make the value of the NumericUpDown available over a property like this (if I'm not wrong):
Public Property NUDVal() As Int32
Set(ByVal value As Int32)
NUD1.Value = value
also this property has a unique name... until the UserControl is one, but when I create 10 instances of the UserControl?
So I thought to lists of objects... and that is my solution.
In the UserControl I created my two NumericUpDown controls at runtime, not in the designer, and I added them to an ArrayList. I also added a CheckBox, in the designer, to use the event "Click" for calculations that serve.
In Form1, the main form, when I create the 10 instances of the UserControl, I also add the ArrayList of controls of every UserControl to another ArrayList declared in the form... here is the code:
Public Class base
Public Objs As ArrayList = New ArrayList
Private n1, n2 As NumericUpDown
Dim pos As Point
n1 = New NumericUpDown
pos.X = 209
pos.Y = 90
n1.Location = pos
n2 = New NumericUpDown
pos.X = 209
pos.Y = 132
n2.Location = pos
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CType(Parent.Parent, TabControl).SelectedIndex += 1
Private Sub CheckBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
Dim val1, val2, id, curid As Int32
id = CType(Parent.Parent, TabControl).SelectedIndex
curid = id - 1
If curid > 0 Then
val1 = CType(CType(Form1.ObjsUC.Item(curid - 1), ArrayList).Item(0), NumericUpDown).Value
val2 = CType(CType(Form1.ObjsUC.Item(curid - 1), ArrayList).Item(1), NumericUpDown).Value
n1.Value = val1 + val2
Public Class Form1
Public ObjsUC As ArrayList = New ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mypag As TabPage
Dim myuc As base
For i As Int32 = 0 To 10
mypag = New TabPage
myuc = New base
myuc.Parent = mypag
mypag.Text = "Pag" & i.ToString
mypag.Name = "Pag" & i.ToString
TabControl1.TabPages.Insert(1 + i, mypag)
In this way all the controls I need are inside a list, and I know what kind of object is every element of the list because I put them in the list, I don't need to loop in the list and check each element.
So in the "Click" event of the CheckBox I can "reach" the values of the NumericUpDown controls of the previous page (or of other pages) pointing to them in the list.
Well... it works... although I have some difficulty in evaluate the elegance of this code...
What do you think about this solution?
And I have another question about the pages of the TabControl, but for this I open another topic...