花花公子滚动条
Dude with ScrollBar
我对 VB6
中的 ScrollBar
有疑问。观看下一个 gif:
我该如何解决?
这是我的全部代码:
Option Explicit
Private old Post As Integer
Dim index As Integer
Dim indicee As Integer
Public Disclaimer
Private Sub btnAdd_Click ()
index = index + 1 'we increase the index
indicee = indicee + 0 'we start it at 0
pic1 (indicee) .Visible = True
'Label and TextBox type
lblType (indicee) .Visible = True
cmbAddType (indicee) .Visible = True
'Label and TextBox prefix
lblAddPrefix (indicee) .Visible = True
txtAddPrefix (indicee) .Visible = True
'Number Label and TextBox
lblAddNum (indicee) .Visible = True
txtAddNumber (indicee) .Visible = True
chkAddPrincipal (indicee) .Visible = True
'Label and TextBox link
lblAddVin (indicee) .Visible = True
cmbAdd Link (indicee) .Visible = True
'uc1
Load pic1 (index) 'we create the control
pic1 (index) .Visible = True 'we make it visible
pic1 (index) .Top = pic1 (index - 1) .Top + pic1 (index - 1) .Height + 20
'lblType
Load lblType (index)
Set lblType (index) .Container = pic1 (index)
lblType (index) .Visible = True
lblType (index) .Top = lblType (index - 1) .Top
'cmbAddType
Load cmbAddType (index)
Set cmbAddType (index) .Container = pic1 (index)
cmbAddType (index) .Visible = True
cmbAddType (index) .Top = cmbAddTipo (index - 1) .Top
'lblAddPrefix
Load lblAddPrefix (index)
Set lblAddPrefix (index) .Container = pic1 (index)
lblAddPrefix (index) .Visible = True
lblAddPrefix (index) .Top = lblAddPrefix (index - 1) .Top
'txtAddPrefix
Load txtAddPrefix (index)
Set txtAddPrefix (index) .Container = pic1 (index)
txtAddPrefix (index) .Visible = True
txtAddPrefix (index) .Top = txtAddPrefix (index - 1) .Top
'lblAddNum
Load lblAddNum (index)
Set lblAddNum (index) .Container = pic1 (index)
lblAddNum (index) .Visible = True
lblAddNum (index) .Top = lblAddNum (index - 1) .Top
'txtAddNumber
Load txtAddNumber (index)
Set txtAddNumber (index) .Container = pic1 (index)
txtAddNumber (index) .Visible = True
txtAddNumber (index) .Top = txtAddNumber (index - 1) .Top
'checkAddPrincipal
Load chkAddPrincipal (index)
Set chkAddPrincipal (index) .Container = pic1 (index)
chkAddPrincipal (index) .Visible = True
chkAddPrincipal (index) .Top = chkAddPrincipal (index - 1) .Top
'lblAddVin
Load lblAddVin (index)
Set lblAddVin (index) .Container = pic1 (index)
lblAddVin (index) .Visible = True
lblAddVin (index) .Top = lblAddVin (index - 1) .Top
'cmbAdd Link
Load cmbAdd Link (index)
Set cmbAdd Link (index) .Container = pic1 (index)
cmbAdd Link (index) .Visible = True
cmbAddLink (index) .Top = cmbAddLink (index - 1) .Top
End Sub
Private Sub Form_Load ()
scrollAdd.Min = 0
scrollAdd.Max = 1000
scrollAdd.SmallChange = Screen.TwipsPerPixelX * 10
scrollAdd.LargeChange = scrollAdd.SmallChange
End Sub
Private Sub scrollAdd_Change ()
ScrollPictureBox
End Sub
Private Sub scrollAdd_Scroll ()
ScrollPictureBox
End Sub
Private Sub ScrollPictureBox ()
Dim c As Control
For Each c In Me.Controls
If c.Container.Name = "pic1" And Not TypeOf c Is VScrollBar Then
c.Top = c.Top + (oldPos - scrollAdd.Value)
End if
Next
oldPos = scrollAdd.Value
End Sub
谁能帮帮我?
我需要用 ScrollBar 解决这个问题。
我需要它正确移动,我该怎么做?
~我加了gif你可以看懂我的"bug/error"
我的英语不好,但我希望你能理解
我希望滚动条正确移动而不移动 gif 中看到的表单。这个想法是,当按下按钮时,将添加字段,并且可以通过 ScrollBar 看到它们,但是正如您将看到整个表单移动,包括 ScrollBar~
我需要的是有一个ScrollBar,允许滚动查看每次按下按钮时添加的所有元素。
由于这是您关于此主题的第三个问题,我将提供一个完整且简单得多的解决方案。第一步是使用设计器可视化地创建一个 UserControl。结果应如下所示:
然后您开始构建主窗体。您可以将 UserControl 用于顶部部分和您需要的任何其他实例。表格最终看起来像这样:
红色圆圈显示名为 uc1
的 UserControl,其 Index
为 0。蓝色圆圈显示名为 Picture1
的 PictureBox 内的 VScrollBar 控件。所有附加的 UserControl 也将放置在 PictureBox 中。现在进入代码:
Option Explicit
Private index As Integer
Private oldPos As Integer
Private Sub Form_Load()
scrollAdd.Min = 0
scrollAdd.Max = 3000
scrollAdd.SmallChange = Screen.TwipsPerPixelX * 10
scrollAdd.LargeChange = scrollAdd.SmallChange
Picture1.Visible = False
End Sub
Private Sub scrollAdd_Change()
ScrollControls
End Sub
Private Sub scrollAdd_Scroll()
ScrollControls
End Sub
Private Sub btnAdd_Click()
index = index + 1
Load uc1(index)
Set uc1(index).Container = Picture1 'place the control inside the PictureBox
uc1(index).Visible = True
uc1(index).Top = IIf(index = 1, 0, uc1(index - 1).Top + uc1(index - 1).Height + 20)
Picture1.Visible = True
End Sub
Private Sub ScrollControls()
Dim c As Control
For Each c In Me.Controls
If c.Container.Name = "Picture1" And Not TypeOf c Is VScrollBar Then
c.Top = c.Top + (oldPos - scrollAdd.Value)
End If
Next
oldPos = scrollAdd.Value
End Sub
请注意代码变得多么简单,尤其是 Add
事件处理程序。它也可以按照您需要的方式工作。在某些时候,您将需要访问 UserControl 的状态。我通常做的是为 UserControl 定义属性:
Option Explicit
Public Property Get AddType() As String
AddType = cmbAddType.Text
End Property
Public Property Let AddType(ByVal Value As String)
cmbAddType.Text = Value
End Property
Public Property Get AddPrefix() As String
AddPrefix = txtAddPrefix.Text
End Property
Public Property Let AddPrefix(ByVal Value As String)
txtAddPrefix.Text = Value
End Property
Public Property Get AddNumber() As String
AddNumber = txtAddNumber.Text
End Property
Public Property Let AddNumber(ByVal Value As String)
txtAddNumber.Text = Value
End Property
Public Property Get AddPrincipal() As Integer
AddPrincipal = chkAddPrincipal.Value
End Property
Public Property Let AddPrincipal(ByVal Value As Integer)
chkAddPrincipal.Value = Value
End Property
Public Property Get AddLink() As String
AddLink = cmbAddLink.Text
End Property
Public Property Let AddLink(ByVal Value As String)
cmbAddLink.Text = Value
End Property
有了这些属性,您现在可以使用任何有效索引设置和获取 UserControl 的状态:
Private Sub TestTheScreen()
'you can initialize the controls as needed
uc1(0).AddPrefix = "My Prefix"
uc1(0).AddPrincipal = vbChecked
'and at some point retrieve the state
Dim ap As Integer
ap = uc1(0).AddPrincipal
End Sub
我对 VB6
中的 ScrollBar
有疑问。观看下一个 gif:
我该如何解决?
这是我的全部代码:
Option Explicit
Private old Post As Integer
Dim index As Integer
Dim indicee As Integer
Public Disclaimer
Private Sub btnAdd_Click ()
index = index + 1 'we increase the index
indicee = indicee + 0 'we start it at 0
pic1 (indicee) .Visible = True
'Label and TextBox type
lblType (indicee) .Visible = True
cmbAddType (indicee) .Visible = True
'Label and TextBox prefix
lblAddPrefix (indicee) .Visible = True
txtAddPrefix (indicee) .Visible = True
'Number Label and TextBox
lblAddNum (indicee) .Visible = True
txtAddNumber (indicee) .Visible = True
chkAddPrincipal (indicee) .Visible = True
'Label and TextBox link
lblAddVin (indicee) .Visible = True
cmbAdd Link (indicee) .Visible = True
'uc1
Load pic1 (index) 'we create the control
pic1 (index) .Visible = True 'we make it visible
pic1 (index) .Top = pic1 (index - 1) .Top + pic1 (index - 1) .Height + 20
'lblType
Load lblType (index)
Set lblType (index) .Container = pic1 (index)
lblType (index) .Visible = True
lblType (index) .Top = lblType (index - 1) .Top
'cmbAddType
Load cmbAddType (index)
Set cmbAddType (index) .Container = pic1 (index)
cmbAddType (index) .Visible = True
cmbAddType (index) .Top = cmbAddTipo (index - 1) .Top
'lblAddPrefix
Load lblAddPrefix (index)
Set lblAddPrefix (index) .Container = pic1 (index)
lblAddPrefix (index) .Visible = True
lblAddPrefix (index) .Top = lblAddPrefix (index - 1) .Top
'txtAddPrefix
Load txtAddPrefix (index)
Set txtAddPrefix (index) .Container = pic1 (index)
txtAddPrefix (index) .Visible = True
txtAddPrefix (index) .Top = txtAddPrefix (index - 1) .Top
'lblAddNum
Load lblAddNum (index)
Set lblAddNum (index) .Container = pic1 (index)
lblAddNum (index) .Visible = True
lblAddNum (index) .Top = lblAddNum (index - 1) .Top
'txtAddNumber
Load txtAddNumber (index)
Set txtAddNumber (index) .Container = pic1 (index)
txtAddNumber (index) .Visible = True
txtAddNumber (index) .Top = txtAddNumber (index - 1) .Top
'checkAddPrincipal
Load chkAddPrincipal (index)
Set chkAddPrincipal (index) .Container = pic1 (index)
chkAddPrincipal (index) .Visible = True
chkAddPrincipal (index) .Top = chkAddPrincipal (index - 1) .Top
'lblAddVin
Load lblAddVin (index)
Set lblAddVin (index) .Container = pic1 (index)
lblAddVin (index) .Visible = True
lblAddVin (index) .Top = lblAddVin (index - 1) .Top
'cmbAdd Link
Load cmbAdd Link (index)
Set cmbAdd Link (index) .Container = pic1 (index)
cmbAdd Link (index) .Visible = True
cmbAddLink (index) .Top = cmbAddLink (index - 1) .Top
End Sub
Private Sub Form_Load ()
scrollAdd.Min = 0
scrollAdd.Max = 1000
scrollAdd.SmallChange = Screen.TwipsPerPixelX * 10
scrollAdd.LargeChange = scrollAdd.SmallChange
End Sub
Private Sub scrollAdd_Change ()
ScrollPictureBox
End Sub
Private Sub scrollAdd_Scroll ()
ScrollPictureBox
End Sub
Private Sub ScrollPictureBox ()
Dim c As Control
For Each c In Me.Controls
If c.Container.Name = "pic1" And Not TypeOf c Is VScrollBar Then
c.Top = c.Top + (oldPos - scrollAdd.Value)
End if
Next
oldPos = scrollAdd.Value
End Sub
谁能帮帮我? 我需要用 ScrollBar 解决这个问题。 我需要它正确移动,我该怎么做?
~我加了gif你可以看懂我的"bug/error" 我的英语不好,但我希望你能理解 我希望滚动条正确移动而不移动 gif 中看到的表单。这个想法是,当按下按钮时,将添加字段,并且可以通过 ScrollBar 看到它们,但是正如您将看到整个表单移动,包括 ScrollBar~
我需要的是有一个ScrollBar,允许滚动查看每次按下按钮时添加的所有元素。
由于这是您关于此主题的第三个问题,我将提供一个完整且简单得多的解决方案。第一步是使用设计器可视化地创建一个 UserControl。结果应如下所示:
然后您开始构建主窗体。您可以将 UserControl 用于顶部部分和您需要的任何其他实例。表格最终看起来像这样:
红色圆圈显示名为 uc1
的 UserControl,其 Index
为 0。蓝色圆圈显示名为 Picture1
的 PictureBox 内的 VScrollBar 控件。所有附加的 UserControl 也将放置在 PictureBox 中。现在进入代码:
Option Explicit
Private index As Integer
Private oldPos As Integer
Private Sub Form_Load()
scrollAdd.Min = 0
scrollAdd.Max = 3000
scrollAdd.SmallChange = Screen.TwipsPerPixelX * 10
scrollAdd.LargeChange = scrollAdd.SmallChange
Picture1.Visible = False
End Sub
Private Sub scrollAdd_Change()
ScrollControls
End Sub
Private Sub scrollAdd_Scroll()
ScrollControls
End Sub
Private Sub btnAdd_Click()
index = index + 1
Load uc1(index)
Set uc1(index).Container = Picture1 'place the control inside the PictureBox
uc1(index).Visible = True
uc1(index).Top = IIf(index = 1, 0, uc1(index - 1).Top + uc1(index - 1).Height + 20)
Picture1.Visible = True
End Sub
Private Sub ScrollControls()
Dim c As Control
For Each c In Me.Controls
If c.Container.Name = "Picture1" And Not TypeOf c Is VScrollBar Then
c.Top = c.Top + (oldPos - scrollAdd.Value)
End If
Next
oldPos = scrollAdd.Value
End Sub
请注意代码变得多么简单,尤其是 Add
事件处理程序。它也可以按照您需要的方式工作。在某些时候,您将需要访问 UserControl 的状态。我通常做的是为 UserControl 定义属性:
Option Explicit
Public Property Get AddType() As String
AddType = cmbAddType.Text
End Property
Public Property Let AddType(ByVal Value As String)
cmbAddType.Text = Value
End Property
Public Property Get AddPrefix() As String
AddPrefix = txtAddPrefix.Text
End Property
Public Property Let AddPrefix(ByVal Value As String)
txtAddPrefix.Text = Value
End Property
Public Property Get AddNumber() As String
AddNumber = txtAddNumber.Text
End Property
Public Property Let AddNumber(ByVal Value As String)
txtAddNumber.Text = Value
End Property
Public Property Get AddPrincipal() As Integer
AddPrincipal = chkAddPrincipal.Value
End Property
Public Property Let AddPrincipal(ByVal Value As Integer)
chkAddPrincipal.Value = Value
End Property
Public Property Get AddLink() As String
AddLink = cmbAddLink.Text
End Property
Public Property Let AddLink(ByVal Value As String)
cmbAddLink.Text = Value
End Property
有了这些属性,您现在可以使用任何有效索引设置和获取 UserControl 的状态:
Private Sub TestTheScreen()
'you can initialize the controls as needed
uc1(0).AddPrefix = "My Prefix"
uc1(0).AddPrincipal = vbChecked
'and at some point retrieve the state
Dim ap As Integer
ap = uc1(0).AddPrincipal
End Sub