home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2003 January / PCpro_2003_01.ISO / born / Beisp / Viewer.vb < prev   
Encoding:
Text File  |  2002-10-15  |  5.0 KB  |  156 lines

  1. '************************************************
  2. ' File:  Viewer.vb 
  3. ' Autor: G. Born www.borncity.de
  4. '
  5. ' Anzeige von Bilddateien in einem Formular.
  6. '
  7. ' ▄bersetzen mit: vbc Viewer.vb /t:winexe /win32Icon:name
  8. ' /r:system.dll /r:dll 
  9. ' /r:system.drawing.dll 
  10. '************************************************
  11. Option Strict
  12. Imports Microsoft.VisualBasic  ' fⁿr vbCrLf
  13. Imports System.Windows.Forms   ' tⁿr Forms-Klasse
  14. Imports System.Drawing
  15.  
  16. Imports System.Reflection      ' fⁿr Tools-Klasse 
  17. Imports System
  18.  
  19. Public Class Text
  20.  Shared Sub Main ()    ' Stub zum Aufruf des Formulars
  21.   Dim oForm As Form1 = New Form1()
  22.   oForm.ShowDialog()
  23.   oForm.Dispose()
  24.  End Sub 
  25. End Class
  26.  
  27. Public Class Tools
  28.     Shared Function GetPath() As String
  29.         ' Extrahiere den Pfad der laufenden Anwendung
  30.         Dim oMod As System.Reflection.Module = _
  31.            [Assembly].GetExecutingAssembly().GetModules()(0)
  32.         Dim pfad As String
  33.         Dim len1 As Integer
  34.  
  35.         len1 = oMod.Name.Length          ' LΣnge Dateiname
  36.         pfad = oMod.FullyQualifiedName   ' Pfad mit Dateiname
  37.         pfad = pfad.Remove(pfad.Length - len1, len1)
  38.         Return pfad
  39.     End Function
  40. End Class
  41.  
  42. Public Class Form1
  43.     Inherits Form
  44.  
  45.     Dim file () As String = _
  46.      { "Blume.jpg","Blume1.jpg", "Blume2.jpg", "Blume3.jpg", "Abend.jpg"}
  47.     Dim idx As Integer = 0          ' Bildindex
  48.  
  49.  
  50.     Public Function GetBmp (file As String) As Bitmap
  51.      ' ermittele BMP aus Datei
  52.        Dim bmp As Bitmap
  53.         Try
  54.             bmp = New Bitmap(file)      ' Bild zuweisen
  55.         Catch Err As Exception
  56.             MsgBox("Fehler Datei" & file & " nicht gefunden")
  57.             Exit Function              ' Abbrechen
  58.         End Try
  59.       Return bmp
  60.     End Function
  61.  
  62. ' Klassen und Ereignisbehandlung deklarieren
  63.    Friend WithEvents PictureBox1 As PictureBox
  64.    Friend WithEvents ButtonDown As Button
  65.    Friend WithEvents ButtonUp As Button
  66.  
  67.  
  68.    Public Sub New()   ' Konstruktor fⁿr Objektinstanz
  69.        MyBase.New()                      ' neues Formular
  70.  
  71.        With Me
  72.         .ButtonUp = New Button()         ' Objektinstanz Formularelemente
  73.         .ButtonDown = New Button()
  74.         .PictureBox1 = New PictureBox()
  75.  
  76.         '
  77.         'ButtonUp
  78.         '
  79.         .ButtonUp.Location = New System.Drawing.Point(224, 256)
  80.         .ButtonUp.Name = "ButtonUp"
  81.         .ButtonUp.Size = New System.Drawing.Size(80, 32)
  82.         .ButtonUp.TabIndex = 2
  83.         .ButtonUp.Text = "VorwΣrts >>"
  84.         '
  85.         'ButtonDown
  86.         '
  87.         .ButtonDown.Location = New System.Drawing.Point(24, 256)
  88.         .ButtonDown.Name = "ButtonDown"
  89.         .ButtonDown.Size = New System.Drawing.Size(72, 32)
  90.         .ButtonDown.TabIndex = 1
  91.         .ButtonDown.Text = "<< Zurⁿck"
  92.         '
  93.         'PictureBox1
  94.         '
  95.         .PictureBox1.Location = New System.Drawing.Point(16, 16)
  96.         .PictureBox1.Name = "PictureBox1"
  97.         .PictureBox1.Size = New System.Drawing.Size(304, 224)
  98.         .PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
  99.         .PictureBox1.TabIndex = 0
  100.         .PictureBox1.TabStop = False
  101.  
  102.         '
  103.         'Form1
  104.         '
  105.         .AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  106.         .ClientSize = New System.Drawing.Size(340, 320)
  107.         .FormBorderStyle = FormBorderStyle.Fixed3D
  108.         .Controls.AddRange(New Control() _
  109.           {.PictureBox1, .ButtonDown, .ButtonUp})
  110.         .MaximizeBox = False
  111.         .Name = "Form1"
  112.         .Text = ".NET-Bildbetrachter V 1.0 by G. Born"
  113.        End With
  114.     End Sub
  115.  
  116.  
  117.     Private Sub ButtonDown_Click(ByVal sender As System.Object, _
  118.         ByVal e As System.EventArgs) Handles ButtonDown.Click
  119.         ' Zurⁿck
  120.         With Me
  121.             idx -= 1
  122.             If idx <= 0 Then ' an Grenze 0 festhalten
  123.                 idx = 0
  124.                 .ButtonDown.Enabled = False ' SchaltflΣche sperren
  125.             End If
  126.             .PictureBox1.Image = GetBmp (Tools.GetPath() & file(idx))
  127.             .ButtonUp.Enabled = True ' SchaltflΣche Weiter freigeben
  128.         End With
  129.  
  130.     End Sub
  131.  
  132.     Private Sub ButtonUp_Click(ByVal sender As System.Object, _
  133.      ByVal e As System.EventArgs) Handles ButtonUp.Click
  134.         ' VorwΣrts
  135.         With Me
  136.             idx += 1
  137.             If idx >= file.Length - 1 Then
  138.                 idx = file.Length - 1
  139.                 .ButtonUp.Enabled = False ' SchaltflΣche Weiter freigeben
  140.             End If
  141.             .PictureBox1.Image = GetBmp (Tools.GetPath() & file(idx))
  142.             .ButtonDown.Enabled = True ' SchaltflΣche Zurⁿck freigeben
  143.         End With
  144.     End Sub
  145.  
  146.     Private Sub Form1_Load(ByVal sender As System.Object, _
  147.         ByVal e As System.EventArgs) Handles MyBase.Load
  148.         idx = 3     ' Initialisiere Bild-Index
  149.         With Me
  150.          .PictureBox1.Image = GetBmp (Tools.GetPath() & file(idx))
  151.          .ButtonDown.Enabled = True ' SchaltflΣche Zurⁿck freigeben
  152.          .ButtonUp.Enabled = True ' SchaltflΣche VorwΣrts freigeben
  153.         End With
  154.     End Sub
  155. End Class
  156.