Вывод графических файлов на компонент Image - VB (59944)
Формулировка задачи:
Вывод графических файлов на компонент Image. Файлы выбираются из списка. Список файлов формируется в диалоге открытия файлов (компонент CommonDialog). Картинка масштабируется по размеру компонента Image, который занимает всю форму и изменяет размеры при изменении размеров формы. Смена файлов происходит при щелчке по изображению в зависимости от выбора кнопки на панели инструментов (следующий, предыдущий).
Очень нужна помощь с написание этой программы.
Решение задачи: «Вывод графических файлов на компонент Image»
textual
Листинг программы
Option Explicit
Dim WithEvents Img As Image
Dim WithEvents Tbr As VBControlExtender
Dim WithEvents Lst As ListBox
Dim Cdlg As Object
Dim a As Single
Private Const tbrButtonGroup = 2, tbrDefault = 0, tbrPressed = 1
Private Sub Form_Load()
Licenses.Add "MSComctlLib.ToolBar"
Licenses.Add "MSComDlg.CommonDialog"
Set Tbr = Me.Controls.Add("MSComctlLib.ToolBar", "tbr")
Set Img = Me.Controls.Add("VB.Image", "img")
Set Lst = Me.Controls.Add("VB.ListBox", "lst")
Set Cdlg = Me.Controls.Add("MSComDlg.CommonDialog", "cdlg")
Tbr.object.Buttons.Add(, , "Ïðåäûäóùèé", tbrButtonGroup).Value = tbrPressed
Tbr.object.Buttons.Add , , "Cëåäóþùèé", tbrButtonGroup
Tbr.object.Buttons.Add , , "ÄîáГ*ГўГЁГІГј", tbrDefault
Tbr.object.BorderStyle = vbFixedSingle
Img.Stretch = True
Tbr.Visible = True: Img.Visible = True: Lst.Visible = True
Cdlg.object.CancelError = True: Cdlg.object.DialogTitle = "ÄîáГ*ГўГЁГІГј èçîáðГ*æåГ*ГЁГҐ"
Cdlg.object.Filter = "ÈçîáðГ*æåГ*ГЁГї|*.bmp;*.jpg;*.jpeg;*.gif"
End Sub
Private Sub Update()
On Error GoTo ErrorImg
If Lst.ListIndex < 0 Then Exit Sub
Set Img.Picture = LoadPicture(Lst.List(Lst.ListIndex))
a = Img.Picture.Width / Img.Picture.Height
Call Form_Resize
Exit Sub
ErrorImg:
MsgBox "ГЋГёГЁГЎГЄГ* îòêðûòèÿ èçîáðГ*æåГ*ГЁГї", vbExclamation
Lst.RemoveItem Lst.ListIndex
End Sub
Private Sub Form_Resize()
Dim w As Long, h As Long
If Me.ScaleWidth < 1000 Or (Me.ScaleHeight - Tbr.Height) < 1000 Then Exit Sub
Lst.Move Me.ScaleWidth - Me.ScaleWidth / 4, Tbr.Height, Me.ScaleWidth / 4, Me.ScaleHeight - Tbr.Height
If Not Img.Picture Is Nothing Then
If a > 1 Then w = Me.ScaleWidth - Lst.Width: h = w / a Else h = Me.ScaleHeight - Tbr.Height: w = h * a
Img.Move (Me.ScaleWidth - Lst.Width - w) \ 2, (Me.ScaleHeight - Tbr.Height - h) \ 2 + Tbr.Height, w, h
End If
End Sub
Private Sub Img_Click()
If Lst.ListCount Then
If Tbr.object.Buttons(1).Value Then
If Lst.ListIndex Then Lst.ListIndex = Lst.ListIndex - 1
Else
If Lst.ListIndex < Lst.ListCount - 1 Then Lst.ListIndex = Lst.ListIndex + 1
End If
End If
End Sub
Private Sub Lst_Click()
Update
End Sub
Private Sub Tbr_ObjectEvent(Info As EventInfo)
If Info.Name = "ButtonClick" Then
If Info.EventParameters.Item(0).Value.Index = 3 Then
On Error GoTo CancelDlg
Cdlg.object.ShowOpen
Lst.AddItem Cdlg.object.FileName
If Lst.ListCount = 1 Then Lst.ListIndex = 0
CancelDlg:
End If
End If
End Sub