home *** CD-ROM | disk | FTP | other *** search
- '************************************************
- ' File: Viewer.vb
- ' Autor: G. Born www.borncity.de
- '
- ' Anzeige von Bilddateien in einem Formular.
- '
- ' ▄bersetzen mit: vbc Viewer.vb /t:winexe /win32Icon:name
- ' /r:system.dll /r:dll
- ' /r:system.drawing.dll
- '************************************************
- Option Strict
- Imports Microsoft.VisualBasic ' fⁿr vbCrLf
- Imports System.Windows.Forms ' tⁿr Forms-Klasse
- Imports System.Drawing
-
- Imports System.Reflection ' fⁿr Tools-Klasse
- Imports System
-
- Public Class Text
- Shared Sub Main () ' Stub zum Aufruf des Formulars
- Dim oForm As Form1 = New Form1()
- oForm.ShowDialog()
- oForm.Dispose()
- End Sub
- End Class
-
- Public Class Tools
- Shared Function GetPath() As String
- ' Extrahiere den Pfad der laufenden Anwendung
- Dim oMod As System.Reflection.Module = _
- [Assembly].GetExecutingAssembly().GetModules()(0)
- Dim pfad As String
- Dim len1 As Integer
-
- len1 = oMod.Name.Length ' LΣnge Dateiname
- pfad = oMod.FullyQualifiedName ' Pfad mit Dateiname
- pfad = pfad.Remove(pfad.Length - len1, len1)
- Return pfad
- End Function
- End Class
-
- Public Class Form1
- Inherits Form
-
- Dim file () As String = _
- { "Blume.jpg","Blume1.jpg", "Blume2.jpg", "Blume3.jpg", "Abend.jpg"}
- Dim idx As Integer = 0 ' Bildindex
-
-
- Public Function GetBmp (file As String) As Bitmap
- ' ermittele BMP aus Datei
- Dim bmp As Bitmap
- Try
- bmp = New Bitmap(file) ' Bild zuweisen
- Catch Err As Exception
- MsgBox("Fehler Datei" & file & " nicht gefunden")
- Exit Function ' Abbrechen
- End Try
- Return bmp
- End Function
-
- ' Klassen und Ereignisbehandlung deklarieren
- Friend WithEvents PictureBox1 As PictureBox
- Friend WithEvents ButtonDown As Button
- Friend WithEvents ButtonUp As Button
-
-
- Public Sub New() ' Konstruktor fⁿr Objektinstanz
- MyBase.New() ' neues Formular
-
- With Me
- .ButtonUp = New Button() ' Objektinstanz Formularelemente
- .ButtonDown = New Button()
- .PictureBox1 = New PictureBox()
-
- '
- 'ButtonUp
- '
- .ButtonUp.Location = New System.Drawing.Point(224, 256)
- .ButtonUp.Name = "ButtonUp"
- .ButtonUp.Size = New System.Drawing.Size(80, 32)
- .ButtonUp.TabIndex = 2
- .ButtonUp.Text = "VorwΣrts >>"
- '
- 'ButtonDown
- '
- .ButtonDown.Location = New System.Drawing.Point(24, 256)
- .ButtonDown.Name = "ButtonDown"
- .ButtonDown.Size = New System.Drawing.Size(72, 32)
- .ButtonDown.TabIndex = 1
- .ButtonDown.Text = "<< Zurⁿck"
- '
- 'PictureBox1
- '
- .PictureBox1.Location = New System.Drawing.Point(16, 16)
- .PictureBox1.Name = "PictureBox1"
- .PictureBox1.Size = New System.Drawing.Size(304, 224)
- .PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
- .PictureBox1.TabIndex = 0
- .PictureBox1.TabStop = False
-
- '
- 'Form1
- '
- .AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- .ClientSize = New System.Drawing.Size(340, 320)
- .FormBorderStyle = FormBorderStyle.Fixed3D
- .Controls.AddRange(New Control() _
- {.PictureBox1, .ButtonDown, .ButtonUp})
- .MaximizeBox = False
- .Name = "Form1"
- .Text = ".NET-Bildbetrachter V 1.0 by G. Born"
- End With
- End Sub
-
-
- Private Sub ButtonDown_Click(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles ButtonDown.Click
- ' Zurⁿck
- With Me
- idx -= 1
- If idx <= 0 Then ' an Grenze 0 festhalten
- idx = 0
- .ButtonDown.Enabled = False ' SchaltflΣche sperren
- End If
- .PictureBox1.Image = GetBmp (Tools.GetPath() & file(idx))
- .ButtonUp.Enabled = True ' SchaltflΣche Weiter freigeben
- End With
-
- End Sub
-
- Private Sub ButtonUp_Click(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles ButtonUp.Click
- ' VorwΣrts
- With Me
- idx += 1
- If idx >= file.Length - 1 Then
- idx = file.Length - 1
- .ButtonUp.Enabled = False ' SchaltflΣche Weiter freigeben
- End If
- .PictureBox1.Image = GetBmp (Tools.GetPath() & file(idx))
- .ButtonDown.Enabled = True ' SchaltflΣche Zurⁿck freigeben
- End With
- End Sub
-
- Private Sub Form1_Load(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles MyBase.Load
- idx = 3 ' Initialisiere Bild-Index
- With Me
- .PictureBox1.Image = GetBmp (Tools.GetPath() & file(idx))
- .ButtonDown.Enabled = True ' SchaltflΣche Zurⁿck freigeben
- .ButtonUp.Enabled = True ' SchaltflΣche VorwΣrts freigeben
- End With
- End Sub
- End Class
-