PDA

View Full Version : سوال: Form Scroll



morika
چهارشنبه 08 مهر 1388, 21:29 عصر
سلام

چجوری میشه واسه فرم اسکرول بار گذاشت؟

ممنون

alireza_s_84
چهارشنبه 08 مهر 1388, 21:39 عصر
سلام دوست عزیز
شما یک پانل به فرمتون اضافه کنید و اونو به فرم Doc کنید بعد خاصیت MaxWidth پانل رو بر روی عددی ست کنید که میخواهید اگر فرم بزگتر شد اسکرول شود.
موفق باشید

Hossis
چهارشنبه 08 مهر 1388, 21:45 عصر
این کد رو یک جائی دیدم یک امتحان بکنید البته مربوط به vb6 هست فکر کنم با دات نت فرقی نداره!

'ابتدا کنترل هاي ذکر شده در کد را وارد کنيد


Option Explicit
Dim cLast As Control
Private Sub Form_Load()
Set cLast = txt(0)
End Sub
Private Sub Form_Resize()
On Error Resume Next
picMainPanel.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
VScroll1.Move picMainPanel.ScaleWidth - VScroll1.Width, 0, VScroll1.Width, picMainPanel.ScaleHeight - IIf(HScroll1.Visible, HScroll1.Height, 0)
HScroll1.Move 0, picMainPanel.ScaleHeight - HScroll1.Height, picMainPanel.ScaleWidth - IIf(VScroll1.Visible, VScroll1.Width, 0), HScroll1.Height
picScrollPanel.Move picScrollPanel.Left, picScrollPanel.Top, picScrollPanel.Width, picScrollPanel.Height
If picScrollPanel.Width < picMainPanel.ScaleWidth Then
HScroll1.Visible = False
VScroll1.Height = picMainPanel.ScaleHeight
Else
VScroll1.Height = picMainPanel.ScaleHeight - HScroll1.Height
HScroll1.Visible = True
End If
If picScrollPanel.Height < picMainPanel.ScaleHeight Then
VScroll1.Visible = False
HScroll1.Width = picMainPanel.ScaleWidth
Else
HScroll1.Width = picMainPanel.ScaleWidth - VScroll1.Width
VScroll1.Visible = True
End If
VScroll1.Max = picScrollPanel.Height - (picMainPanel.ScaleHeight - IIf(HScroll1.Visible, HScroll1.Height, 0))
VScroll1.LargeChange = picMainPanel.ScaleHeight + IIf(HScroll1.Visible, HScroll1.Height, 0)
HScroll1.Max = picScrollPanel.Width - (picMainPanel.ScaleWidth - IIf(VScroll1.Visible, VScroll1.Width, 0))
HScroll1.LargeChange = picMainPanel.ScaleWidth + IIf(VScroll1.Visible, VScroll1.Width, 0)
Call ScrollToFocusedControl(cLast)
End Sub
Private Sub HighLightText(myTextBox As TextBox)
With myTextBox
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Private Sub HScroll1_Change()
picScrollPanel.Left = -HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
picScrollPanel.Left = -HScroll1.Value
End Sub
Private Sub txt_GotFocus(Index As Integer)
Call HighLightText(txt(Index))
Set cLast = txt(Index)
Call ScrollToFocusedControl(txt(Index))
End Sub
Private Sub VScroll1_Change()
picScrollPanel.Top = -VScroll1.Value
End Sub
Private Sub VScroll1_Scroll()
picScrollPanel.Top = -VScroll1.Value
End Sub
Private Sub ScrollToFocusedControl(myControl As Control)
Dim lHNeeded As Long
Dim lWNeeded As Long
Dim lHLimit As Long
Dim lWLimit As Long
'lHNeeded value is the top and height of the control combined
'that has focus + an additional padding of 1000 twips
'the padding is completly optional but it does make it nicer
lHNeeded = myControl.Top + myControl.Height + 1000
'lHLimit value is the current height limit of the scrollpanel that is
'currently visible in the viewport
lHLimit = Abs(picScrollPanel.Top) + picMainPanel.ScaleHeight - IIf(HScroll1.Visible, HScroll1.Height, 0)
'lWNeeded is just like lHNeeded but this time it's the left and
'width combined + an addittional 1000 twips of padding
lWNeeded = myControl.Left + myControl.Width + 1000
'lWLimit is just like lHLimit but tells us how much width of the
'scrollpanel is currently visible in the viewport.
lWLimit = Abs(picScrollPanel.Left) + picMainPanel.ScaleWidth - IIf(VScroll1.Visible, VScroll1.Width, 0)
'now to do some comparing to see if we need to adjust the scrolling panel's
'top setting in order for the control to be seen
'at the same time adjusting the scollbar value to match the new position
'we adjust it to. First check is for move the scroll panel up
If lHNeeded > lHLimit Then
picScrollPanel.Top = picScrollPanel.Top - (lHNeeded - lHLimit)
VScroll1.Value = Abs(picScrollPanel.Top)
Else
'now check to see if we need to move the panel down
If lHNeeded < picMainPanel.Height Then
picScrollPanel.Top = 0
VScroll1.Value = 0
Else
If lHNeeded < lHLimit - picMainPanel.Height Then
picScrollPanel.Top = picScrollPanel.Top - (lHNeeded - lHLimit)
VScroll1.Value = Abs(picScrollPanel.Top)
End If
End If
End If
'now we will do the same thing but this time working with the width and
'and horizontal movement of the scroll panel
If lWNeeded > lWLimit Then
picScrollPanel.Left = picScrollPanel.Left - (lWNeeded - lWLimit)
HScroll1.Value = Abs(picScrollPanel.Left)
Else
If lWNeeded < picMainPanel.Width Then
picScrollPanel.Left = 0
HScroll1.Value = 0
Else
If lWNeeded < lWLimit - picMainPanel.Width Then
picScrollPanel.Left = picScrollPanel.Left - (lWNeeded - lWLimit)
HScroll1.Value = Abs(picScrollPanel.Left)
End If
End If
End If
End Sub

anooshiran
چهارشنبه 08 مهر 1388, 22:10 عصر
ُلام دوست عزيز

فرم يك property به نام AutoScroll داره كه اگر آن را معادل true قرار دهي، هرگاه ابعاد كنترلي كه در فرمت تعريف شده باعث بيرون شدن قسمتي از آن از فرم گردد ، scroll نمايان مي گردد