From: Nobody on
"Webbiz" <nospam(a)forme.thanks.com> wrote in message
news:djk0b51hhiqigu164gs54cmjq08tgaapf3(a)4ax.com...
> Nobody,
>
> I'm a tad baffled here.
>
> I cannot find where in the UC that you named this puppy UserControl11.
>
> When I put the mouse over the UC icon, it's UserControl1.
>
> When I go to the UC code itself, it's UserControl1.
>
> I even looked at the properties and nothing.
>
> Why is it calling itself UserControl11?

I left the default name as is, and it looks confusing, but it works. You can
change it to anything you like. VB always adds "1" to the first control
name, so you get "11" in this case. Here are the same instructions with a
better name. The only changes is the control name and I added a 3rd step
below, otherwise, everything is the same:

- Start a new Standard EXE Project.
- Go to Project-->Add User Control, and click Open.
- In the properties window, change "UserControl1" to "UC".
- Close the UserControl designer window.
- Place the UserControl on Form1, and set Index property for the UserControl
to 0.
- Add Form1 and UserControl code below.

This example will draw 12 user controls on a 4x3 grid, and it auto resizes
them when the form is resized. It also shows on the form's Caption which
control the mouse is over.

' Form1 code

Option Explicit

Const MAX_CHARTS_COUNT As Long = 12 ' 4 Columns x 3 Rows

Private Sub Form_Load()
Dim i As Long

For i = 1 To MAX_CHARTS_COUNT - 1
Load UC1(i)
UC1(i).Visible = True
Next

End Sub

Private Sub Form_Resize()
Dim i As Long
Dim X As Long, Y As Long
Dim w As Long, h As Long

If Me.WindowState = vbMinimized Then
Exit Sub
End If

w = Me.ScaleWidth / 4
h = Me.ScaleHeight / 3
For i = 0 To MAX_CHARTS_COUNT - 1
X = (i Mod 4) * w
Y = (i \ 4) * h
UC1(i).Move X, Y, w, h
Next
End Sub

Private Sub UC1_MouseMove(Index As Integer, Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Me.Caption = "Mouse is over UserControl " & UC1( _
Index).Index & "(" & X & "," & Y & ")"
End Sub




' UserControl code

Option Explicit

Event MouseMove(Button As Integer, Shift As Integer, X As Single, _
Y As Single)

Private Sub UserControl_Paint()
RedrawMe
End Sub

Private Sub UserControl_Resize()
RedrawMe
End Sub

Private Sub RedrawMe()
UserControl.Cls
UserControl.Line (0, 0)-(UserControl.Width, UserControl.Height)
UserControl.Line (0, UserControl.Height)-(UserControl.Width, 0)
End Sub

Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub



For improvement, you could put the code that is in "Form_Load" and
"Form_Resize" in a class(CChartsManager). This class could have a reference
to the form and do what is needed to create and manage the charts. Example:

' New Form1 code

Option Explicit

Private oChartsManager As New CChartsManager

Private Sub Form_Load()
oChartsManager.SetForm Me
oChartsManager.SetChartsCount 12
End Sub

Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
oChartsManager.Resize
End If
End Sub

Private Sub UC1_MouseMove(Index As Integer, Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Me.Caption = "Mouse is over UserControl " & UC1(Index).Index
End Sub



' CChartsManager code

Option Explicit

Private frm As Form

Public Enum ChartTypes
ctBar
ctLine
ctPie
End Enum

Private Type TCharts
ChartType As ChartTypes
Width As Single
Height As Single
End Type

Private Charts() As TCharts
Private ChartsCount As Long

Public Sub SetForm(f As Form)
Set frm = f
End Sub

Public Sub SetChartsCount(ByVal Count As Long)
Dim i As Long

ChartsCount = Count
ReDim Charts(1 To ChartsCount) As TCharts

For i = 1 To ChartsCount - 1
Load frm.UC1(i)
frm.UC1(i).Visible = True
Next

End Sub

Public Sub Resize()
Dim i As Long
Dim X As Long, Y As Long
Dim w As Long, h As Long

w = frm.ScaleWidth / 4
h = frm.ScaleHeight / 3
For i = 0 To ChartsCount - 1
X = (i Mod 4) * w
Y = (i \ 4) * h
frm.UC1(i).Move X, Y, w, h
Next
End Sub

Private Sub Class_Terminate()
Set frm = Nothing
End Sub


From: Webbiz on
On Wed, 16 Sep 2009 00:04:50 -0400, "Nobody" <nobody(a)nobody.com>
wrote:

>"Webbiz" <nospam(a)forme.thanks.com> wrote in message
>news:djk0b51hhiqigu164gs54cmjq08tgaapf3(a)4ax.com...
>> Nobody,
>>
>> I'm a tad baffled here.
>>
>> I cannot find where in the UC that you named this puppy UserControl11.
>>
>> When I put the mouse over the UC icon, it's UserControl1.
>>
>> When I go to the UC code itself, it's UserControl1.
>>
>> I even looked at the properties and nothing.
>>
>> Why is it calling itself UserControl11?
>
>I left the default name as is, and it looks confusing, but it works. You can
>change it to anything you like. VB always adds "1" to the first control
>name, so you get "11" in this case. Here are the same instructions with a
>better name. The only changes is the control name and I added a 3rd step
>below, otherwise, everything is the same:
>
>- Start a new Standard EXE Project.
>- Go to Project-->Add User Control, and click Open.
>- In the properties window, change "UserControl1" to "UC".
>- Close the UserControl designer window.
>- Place the UserControl on Form1, and set Index property for the UserControl
>to 0.
>- Add Form1 and UserControl code below.
>
>This example will draw 12 user controls on a 4x3 grid, and it auto resizes
>them when the form is resized. It also shows on the form's Caption which
>control the mouse is over.
>
>' Form1 code
>
>Option Explicit
>
>Const MAX_CHARTS_COUNT As Long = 12 ' 4 Columns x 3 Rows
>
>Private Sub Form_Load()
> Dim i As Long
>
> For i = 1 To MAX_CHARTS_COUNT - 1
> Load UC1(i)
> UC1(i).Visible = True
> Next
>
>End Sub
>
>Private Sub Form_Resize()
> Dim i As Long
> Dim X As Long, Y As Long
> Dim w As Long, h As Long
>
> If Me.WindowState = vbMinimized Then
> Exit Sub
> End If
>
> w = Me.ScaleWidth / 4
> h = Me.ScaleHeight / 3
> For i = 0 To MAX_CHARTS_COUNT - 1
> X = (i Mod 4) * w
> Y = (i \ 4) * h
> UC1(i).Move X, Y, w, h
> Next
>End Sub
>
>Private Sub UC1_MouseMove(Index As Integer, Button As Integer, _
> Shift As Integer, X As Single, Y As Single)
> Me.Caption = "Mouse is over UserControl " & UC1( _
> Index).Index & "(" & X & "," & Y & ")"
>End Sub
>
>
>
>
>' UserControl code
>
>Option Explicit
>
>Event MouseMove(Button As Integer, Shift As Integer, X As Single, _
> Y As Single)
>
>Private Sub UserControl_Paint()
> RedrawMe
>End Sub
>
>Private Sub UserControl_Resize()
> RedrawMe
>End Sub
>
>Private Sub RedrawMe()
> UserControl.Cls
> UserControl.Line (0, 0)-(UserControl.Width, UserControl.Height)
> UserControl.Line (0, UserControl.Height)-(UserControl.Width, 0)
>End Sub
>
>Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, _
> X As Single, Y As Single)
> RaiseEvent MouseMove(Button, Shift, X, Y)
>End Sub
>
>
>
>For improvement, you could put the code that is in "Form_Load" and
>"Form_Resize" in a class(CChartsManager). This class could have a reference
>to the form and do what is needed to create and manage the charts. Example:
>
>' New Form1 code
>
>Option Explicit
>
>Private oChartsManager As New CChartsManager
>
>Private Sub Form_Load()
> oChartsManager.SetForm Me
> oChartsManager.SetChartsCount 12
>End Sub
>
>Private Sub Form_Resize()
> If Me.WindowState <> vbMinimized Then
> oChartsManager.Resize
> End If
>End Sub
>
>Private Sub UC1_MouseMove(Index As Integer, Button As Integer, _
> Shift As Integer, X As Single, Y As Single)
> Me.Caption = "Mouse is over UserControl " & UC1(Index).Index
>End Sub
>
>
>
>' CChartsManager code
>
>Option Explicit
>
>Private frm As Form
>
>Public Enum ChartTypes
> ctBar
> ctLine
> ctPie
>End Enum
>
>Private Type TCharts
> ChartType As ChartTypes
> Width As Single
> Height As Single
>End Type
>
>Private Charts() As TCharts
>Private ChartsCount As Long
>
>Public Sub SetForm(f As Form)
> Set frm = f
>End Sub
>
>Public Sub SetChartsCount(ByVal Count As Long)
> Dim i As Long
>
> ChartsCount = Count
> ReDim Charts(1 To ChartsCount) As TCharts
>
> For i = 1 To ChartsCount - 1
> Load frm.UC1(i)
> frm.UC1(i).Visible = True
> Next
>
>End Sub
>
>Public Sub Resize()
> Dim i As Long
> Dim X As Long, Y As Long
> Dim w As Long, h As Long
>
> w = frm.ScaleWidth / 4
> h = frm.ScaleHeight / 3
> For i = 0 To ChartsCount - 1
> X = (i Mod 4) * w
> Y = (i \ 4) * h
> frm.UC1(i).Move X, Y, w, h
> Next
>End Sub
>
>Private Sub Class_Terminate()
> Set frm = Nothing
>End Sub
>


Appreciate the code Nobody. Was playing with it yesterday.

I just didn't understand why VB named it the way it did. You didn't
need to rename it as I didn't have a problem following it. Just
curious.

In playing with this code, I was thinking on how it would apply to my
chart/indicator scenario. What appears to me to be the likely outcome
is that if you create this control array, if the user wants to remove
one from the middle of the array, it would not really be removed but
made not visible. Then when another is added later, the array would
have to be looped through to find one that is simply not visible and
make it visible before looking to add another to the array.

Is that how you see it?

Thx.

Webbiz
From: Nobody on
"Webbiz" <nospam(a)forme.thanks.com> wrote in message
news:nb42b5ht2d6hgl7act2vmhdn8pcnp1fjei(a)4ax.com...
> In playing with this code, I was thinking on how it would apply to my
> chart/indicator scenario. What appears to me to be the likely outcome
> is that if you create this control array, if the user wants to remove
> one from the middle of the array, it would not really be removed but
> made not visible. Then when another is added later, the array would
> have to be looped through to find one that is simply not visible and
> make it visible before looking to add another to the array.
>
> Is that how you see it?

Yes.