-
May 8th, 2015, 08:10 AM
#1
Thread Starter
Hyperactive Member
-
May 8th, 2015, 08:31 AM
#2
Re: I've some problems calculating and putting controls in the correct coordinates
Without going to far into the code you posted why not use a different method for locating the picture box
Simply use the Top of the picturebox above it + the height of the picturebox above it + the distance of separation you want
Code:
NewPB.Top=OldPB.Top+OldPB.Height+DesiredSpacing
-
May 8th, 2015, 09:29 AM
#3
Thread Starter
Hyperactive Member
Re: I've some problems calculating and putting controls in the correct coordinates
Originally Posted by DataMiser
Without going to far into the code you posted why not use a different method for locating the picture box
Simply use the Top of the picturebox above it + the height of the picturebox above it + the distance of separation you want
Code:
NewPB.Top=OldPB.Top+OldPB.Height+DesiredSpacing
It works good to keep always 1 pixel of distance between the picturebox controls. I'm performing more test to see more details, but with your code the distance is always good.
-
May 8th, 2015, 09:51 AM
#4
Thread Starter
Hyperactive Member
Re: I've some problems calculating and putting controls in the correct coordinates
I've performed more tests and the separation problem (one pixel between the picturebox controls) is perfect.
Now, the problem remains in the part where I said that the last PicBoxAux (the lower one) wasn't always the same height. The height varies a few pixels depending the size of the form. I think I've to add some code to calculate the correct height only in the case of the last PicBoxAux control. The other ones are the same, but the only one that is slightly different is the one in the lower part, because the height is not constant in comparation with the form size.
-
May 8th, 2015, 10:11 AM
#5
Thread Starter
Hyperactive Member
Re: I've some problems calculating and putting controls in the correct coordinates
After writting some modifications in the code, I've the version that works ok.
For that, I've given 3 conditions depending the amount of PicBoxAux present in the form:
Condition 1: 1 PicBoxAux
Condition 2: More than one and 1 unit less than the total
Condition 3: The last PicBoxAux
In the case of the last PicBoxAux I've modified the code that calculates the height of the last picturebox control, adapting it to Me.ScaleHeight - 23. The other PicBoxAux have the same .Height.
-
May 8th, 2015, 10:15 AM
#6
Thread Starter
Hyperactive Member
Re: I've some problems calculating and putting controls in the correct coordinates
The next code represents the updated final version of the code. Note that I've implemented also some code to draw a small group of small vertical lines in the lower picturebox control (whatever picturebox) to see if the whole code was working according to the description.
Code:
Option Explicit
Dim CantidadDeIndicadores As Integer
Dim AlturaTotalPBDatos As Long 'altura en pixeles que ocuparia si solo hubiera la ventana PBDatos
Dim CantidadSectoresFormulario As Integer 'cantidad en que se divide el formulario para hacer los calculos para el posicionamiento
' de las ventanas. Formula: CantidadDeIndicadores + 2
Dim CantidadMinilineasFecha As Integer
Private Sub Form_Load()
PicBoxFondo.Top = 0
PicBoxFondo.Left = 0
PicBoxDatos.Top = 2
PicBoxDatos.Left = 2
Dim Contador1A As Integer
For Contador1A = 2 To 22
Load MiniLineaFecha(Contador1A)
Next
MiniLineaFecha(1).X1 = 3
MiniLineaFecha(1).X2 = 3
Dim Contador1B As Integer
For Contador1B = 2 To 22
With MiniLineaFecha(Contador1B)
.X1 = MiniLineaFecha(Contador1B - 1).X1 + 64
.X2 = MiniLineaFecha(Contador1B - 1).X2 + 64
End With
Next
Dim Contador1 As Integer
For Contador1 = 2 To 15 '15 es la cantidad maxima de indicadores soportada en esta version
Load PicBoxIndicador(Contador1)
Next
Dim Contador2 As Integer
For Contador2 = 1 To 15
PicBoxIndicador(Contador2).Left = 2
Next Contador2
'Modificar esta linea para modificar el numero de indicadores que se muestran en pantalla
CantidadDeIndicadores = 0
Call Form_Resize
End Sub
Private Sub Form_Resize()
AlturaTotalPBDatos = Me.ScaleHeight - 25 '(Me.ScaleHeight - 23 - 2)
CantidadSectoresFormulario = CantidadDeIndicadores + 2
PicBoxFondo.Height = Me.ScaleHeight
PicBoxFondo.Width = Me.ScaleWidth
PicBoxDatos.Width = Me.ScaleWidth - 48
PicBoxIndicador(1).Width = Me.ScaleWidth - 48
'MiniLineasFecha
Dim Contador1A As Integer
For Contador1A = 1 To (Int((PicBoxDatos.Width - 2) / 64) + 1)
With MiniLineaFecha(Contador1A)
.Y1 = Me.ScaleHeight - 21
.Y2 = Me.ScaleHeight - 18
.Visible = True
End With
Next
Dim Contador1B As Integer
For Contador1B = (Int((PicBoxDatos.Width - 2) / 64) + 2) To 22
With MiniLineaFecha(Contador1B)
.Visible = False
End With
Next
If CantidadDeIndicadores = 0 Then
PicBoxDatos.Height = Me.ScaleHeight - 23
Else 'Altura del PBDatos dependiendo de la cantidad de indicadores que se esten mostrando actualmente
PicBoxDatos.Height = (2 * (Int(AlturaTotalPBDatos / CantidadSectoresFormulario))) + 1
Dim Contador1 As Integer
For Contador1 = 1 To CantidadDeIndicadores
If Contador1 = 1 Then
PicBoxIndicador(1).Top = PicBoxDatos.Height + PicBoxDatos.Top + 1 ' + 3 'espacio de 1 pixel entre ventana y ventana: 2 pixeles de separacion del PicBoxDatos y 1 pixel de separacion de ese formulario
If CantidadDeIndicadores = 1 Then PicBoxIndicador(1).Height = Me.ScaleHeight - PicBoxDatos.Height - 23 - 1
If CantidadDeIndicadores > 1 Then PicBoxIndicador(1).Height = Int(AlturaTotalPBDatos / CantidadSectoresFormulario)
PicBoxIndicador(1).Visible = True
ElseIf Contador1 > 1 And Contador1 < (CantidadDeIndicadores) Then 'contador1 es mayor que 1 la ultima ventana hay que modificar el alto, las restantes ventanas de indicadores se calculan igual
PicBoxIndicador(Contador1).Top = PicBoxIndicador(Contador1 - 1).Top + PicBoxIndicador(Contador1 - 1).Height + 1 '(Contador1 - 1) * (AlturaTotalPBDatos / CantidadSectoresFormulario) + PicBoxDatos.Height + 2 + Contador1
PicBoxIndicador(Contador1).Height = Int(AlturaTotalPBDatos / CantidadSectoresFormulario) 'Me.ScaleHeight - PicBoxIndicador(Contador1 - 1) - 23
PicBoxIndicador(Contador1).Width = Me.ScaleWidth - 48
PicBoxIndicador(Contador1).Visible = True
ElseIf Contador1 = CantidadDeIndicadores Then
PicBoxIndicador(Contador1).Top = PicBoxIndicador(Contador1 - 1).Top + PicBoxIndicador(Contador1 - 1).Height + 1
PicBoxIndicador(Contador1).Height = (Me.ScaleHeight - 23) - (PicBoxIndicador(1).Height * (CantidadDeIndicadores - 1)) - PicBoxDatos.Height - CantidadDeIndicadores
'Explicacion de la anterior linea ^
'-cantidad de indicadores porque tenemos que restar por cada indicador 1 pixel de separacion, por lo tanto CantidadDePixelesDeSeparacion = CantidadDeIndicadores
PicBoxIndicador(Contador1).Width = Me.ScaleWidth - 48
PicBoxIndicador(Contador1).Visible = True
End If
Next
' Dim Contador2 As Integer
' For Contador2 = CantidadDeIndicadores + 5 To 15
PicBoxIndicador(CantidadDeIndicadores + 1).Visible = False
' Next
End If
End Sub
Private Sub mnuAgregarVentanaIndicador_Click()
CantidadDeIndicadores = CantidadDeIndicadores + 1
Call Form_Resize
End Sub
Private Sub mnuEliminarVentanaIndicador_Click()
If CantidadDeIndicadores <> 0 Then CantidadDeIndicadores = CantidadDeIndicadores - 1
Call Form_Resize
End Sub
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
|