Tipp 0092 Hintergrund mit Grafik kacheln
Autor/Einsender:
Datum:
  Detlev Schubert
03.07.2001
Entwicklungsumgebung:   VB 5
Um eine Form nicht in dem "Einheits-Grau" anzuzeigen, bietet es sich an, die Form mit einer Grafik oder einem Muster zu füllen. Da komplette Grafiken je nach Bildschirmauflösung sehr speicherintensiv sind, bedienen wir uns der schnellen API-Funktion BitBlt, als eine speicherschonende Möglichkeit, mit der eine kleine Grafik auf die Form oder auch auf ein Steuerelement "gekachelt" werden kann.
Code im Codebereich des Moduls
 
Option Explicit

Public Const SRCCOPY = &HCC0020

Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
      ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
      ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc _
      As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
 
Code im Codebereich der Form
 
Private Sub Form_Load()
  Combo1.AddItem "(kein Bild)"
  Combo1.AddItem "Beispiel1.jpg"
  Combo1.AddItem "Beispiel2.jpg"
  Combo1.AddItem "Beispiel3.bmp"
  Combo1.ListIndex = 0
End Sub

Private Sub Form_Paint()
  Dim H As Integer
  Dim V As Integer

  For V = 0 To Form1.Height Step (pic1.Height - 5)
    For H = 0 To Form1.Width Step (pic1.Width - 5)
      BitBlt Me.hDC, H, V, pic1.ScaleWidth, pic1.ScaleHeight, _
             pic1.hDC, 0, 0, SRCCOPY
    Next H
  Next V
End Sub

Private Sub Combo1_Click()
  Dim D As String

  D$ = Combo1.List(Combo1.ListIndex)
  If D$ = "(kein Bild)" Then
     pic1.Picture = LoadPicture("")
  Else
     pic1 = LoadPicture(App.Path & "\" & D$)
  End If

  Me.AutoRedraw = False
  Form_Paint
End Sub
 
Weitere Links zum Thema
Skin-Effekt

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (11,6 kB) Downloads bisher: [ 1772 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Samstag, 13. August 2011