vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevAniGif - als kostenlose Vollversion auf unserer vb@rchiv CD Vol.5  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Re: Transparente Bilder 
Autor: GPM
Datum: 19.02.18 23:56

Hier eine Demo mit 4 Eckhandler + Cursor (Ein-Aus: Maustaste rechts)
Imports System.Drawing.Drawing2D
Public Class Form1
    Dim Fo As New Font("Arial", 12, FontStyle.Bold)
    Dim WithEvents Pb As New PictureBox With {.Dock = DockStyle.Fill, .Parent = _
      Me}
    Dim hgrund As Bitmap = SystemIcons.Shield.ToBitmap
    Dim picList As New List(Of MyPicture)  'Bilderliste
    Dim hrList As New List(Of Rectangle)   'Handler-Rechtecke
    Dim loc As Point, rec, rec2 As Rectangle
    Dim hp As Int32 = 0, handler, movh As Boolean
    Dim cur As New List(Of Cursor)({Cursors.SizeAll, Cursors.PanNW, _
      Cursors.PanNE, Cursors.PanSW, Cursors.PanSE})
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ClientSize = New Size(800, 800)
        For y = 200 To 400 Step 100
            picList.Add(New MyPicture With {.Img = _
              SystemIcons.Warning.ToBitmap, .Bounds = New Rectangle(225, y, 64, _
              64)})
            picList.Add(New MyPicture With {.Img = SystemIcons.Error.ToBitmap, _
            .Bounds = New Rectangle(375, y, 64, 64)})
            picList.Add(New MyPicture With {.Img = Me.Icon.ToBitmap, .Bounds = _
            New Rectangle(525, y, 64, 64)})
        Next
    End Sub
 
    Private Sub Pb_MouseDown(sender As Object, e As MouseEventArgs) Handles _
      Pb.MouseDown
        For i = picList.Count - 1 To 0 Step -1
            rec = picList(i).Bounds
            If rec.Contains(e.Location) Then
                loc = e.Location
                picList.Add(picList(i)) 'Auswahl auf Top setzen
                picList.RemoveAt(i)
                SetHandler()
                Exit For
            End If
        Next
        If handler Then
            Pb.Cursor = Cursors.SizeAll
            For i = hrList.Count - 1 To 0 Step -1
                If hrList(i).Contains(e.Location) Then
                    loc = e.Location
                    Pb.Cursor = cur(i)
                    hp = i
                    movh = True
                    rec = picList(picList.Count - 1).Bounds
                    rec2 = rec
                    Exit Sub
                End If
            Next
        End If
        movh = False
    End Sub
 
    Private Sub SetHandler()
        Dim re As Rectangle = picList(picList.Count - 1).Bounds
        hrList.Clear()
        hrList.Add(re)
        hrList.Add(New Rectangle(re.X - 15, re.Y - 15, 15, 15))
        hrList.Add(New Rectangle(re.Right, re.Y - 15, 15, 15))
        hrList.Add(New Rectangle(re.X - 15, re.Bottom, 15, 15))
        hrList.Add(New Rectangle(re.Right, re.Bottom, 15, 15))
    End Sub
 
    Private Sub Pb_MouseUp(sender As Object, e As MouseEventArgs) Handles _
      Pb.MouseUp
        If e.Button = MouseButtons.Right Then
            handler = Not handler
            Pb.Invalidate()
        End If
        movh = False
        Pb.Cursor = Cursors.Default
    End Sub
 
    Private Sub Pb_MouseMove(sender As Object, e As MouseEventArgs) Handles _
      Pb.MouseMove
        If movh AndAlso e.Button = MouseButtons.Left Then
            Select Case hp
                Case 0 : picList(picList.Count - 1).Bounds = New Rectangle(New _
                  Point(rec.X + (e.X - loc.X), rec.Y + e.Y - loc.Y), rec.Size)
                Case 1
                    rec.X = rec2.X + (e.X - loc.X) : rec.Width = rec2.Width + ( _
                      loc.X - e.X)
                    rec.Y = rec2.Y + (e.Y - loc.Y) : rec.Height = rec2.Height + _
                    (loc.Y - e.Y)
                Case 2
                    rec.Width = rec2.Width - (loc.X - e.X) : rec.Height = _
                      rec2.Height + (loc.Y - e.Y)
                    rec.Y = rec2.Y - (loc.Y - e.Y)
                Case 3
                    rec.X = rec2.X + (e.X - loc.X) : rec.Width = rec2.Width + ( _
                      loc.X - e.X)
                    rec.Height = rec2.Height + (e.Y - loc.Y)
                Case 4
                    rec.Width = rec2.Width + (e.X - loc.X)
                    rec.Height = rec2.Height + (e.Y - loc.Y)
            End Select
            If hp > 0 Then picList(picList.Count - 1).Bounds = rec
            SetHandler()
            Pb.Invalidate()
        End If
    End Sub
 
    Private Sub Pb_Paint(sender As Object, e As PaintEventArgs) Handles Pb.Paint
        e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor
        e.Graphics.DrawImage(hgrund, 0, 0, Pb.Width, Pb.Height)
        For Each pic In picList
            e.Graphics.DrawImage(pic.Img, pic.Bounds)
        Next
        If handler Then
            Using p As New Pen(Brushes.White, 3)
                For i = 0 To hrList.Count - 1
                    e.Graphics.DrawRectangle(p, hrList(i))
                    e.Graphics.DrawRectangle(Pens.Black, hrList(i))
                Next
            End Using
        End If
    End Sub
 
    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Pb.Invalidate()
    End Sub
End Class
 
Public Class MyPicture
    Public Img As Bitmap
    Public Bounds As Rectangle
End Class
MfG GPM
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Transparente Bilder1.935dm148515.02.18 09:03
Re: Transparente Bilder1.027Manfred X15.02.18 11:52
Re: Transparente Bilder1.130dm148515.02.18 13:27
Re: Transparente Bilder990Manfred X15.02.18 18:06
Re: Transparente Bilder1.004dm148516.02.18 10:07
Re: Transparente Bilder1.012Manfred X16.02.18 11:53
Re: Transparente Bilder983dm148516.02.18 13:44
Re: Transparente Bilder999Manfred X16.02.18 15:16
Re: Transparente Bilder1.002dm148516.02.18 15:29
Re: Transparente Bilder1.085dm148516.02.18 13:54
Re: Transparente Bilder960dm148516.02.18 14:44
Re: Transparente Bilder982Kuno6016.02.18 22:26
Re: Transparente Bilder951GPM17.02.18 15:43
Re: Transparente Bilder987dm148519.02.18 12:01
Re: Transparente Bilder1.028GPM19.02.18 23:56
Re: Transparente Bilder1.035dm148520.02.18 09:17
Re: Transparente Bilder988GPM20.02.18 11:08
Re: Transparente Bilder1.099dm148520.02.18 11:18
Re: Transparente Bilder983GPM20.02.18 22:26
Re: Transparente Bilder1.059dm148520.02.18 22:55
Re: Transparente Bilder980dm148521.02.18 08:50
Re: Transparente Bilder918GPM21.02.18 14:39
Re: Transparente Bilder888dm148521.02.18 21:18
Re: Transparente Bilder880dm148524.02.18 21:15

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel