vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

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

VB.NET - Fortgeschrittene
Re: Übrigens...Teil II 
Autor: ModeratorDaveS (Moderator)
Datum: 12.03.04 10:33

   Private Sub MouseMove(ByVal sender As Object, ByVal e As _
     System.Windows.Forms.MouseEventArgs) Handles ctl.MouseMove
        If Drawing And Not Drawn Then
            Dim x As Integer = e.X
            Dim y As Integer = e.Y
            'bisheriges Rechteck löschen
            Remove()
            'Größe des neuen Rechtecks ermitteln
            If x < 0 Then x = 0
            If x > ctl.ClientSize.Width Then x = ctl.ClientSize.Width
            If y < 0 Then y = 0
            If y > ctl.ClientSize.Height Then y = ctl.ClientSize.Height
            'neues Rechteck zeichnen
            Size = New Size(x - OriginalPosition.X, y - OriginalPosition.Y)
            Draw()
        End If
    End Sub
 
    Private Sub MouseDown(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles ctl.MouseDown
        If Drawn Then
            Remove()
        Else
            If Drawing Then Return
            OriginalPosition = New Point(e.X, e.Y)
            Position = ctl.PointToScreen(OriginalPosition)
            Size = New Size(0, 0)
            'Startrechteck zeichnen
            Draw()
        End If
    End Sub
 
    Private Sub MouseUp(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles ctl.MouseUp
        Dim tmp As Integer
 
        If Drawing Then
            x0 = OriginalPosition.X
            x1 = x0 + Size.Width
            If x0 > x1 Then tmp = x0 : x0 = x1 : x1 = tmp
            y0 = OriginalPosition.Y
            y1 = y0 + Size.Height
            If y0 > y1 Then tmp = y0 : y0 = y1 : y1 = tmp
 
            Drawing = False
            Drawn = True
            If x1 - x0 = 0 Or y1 - y0 = 0 Then
                Remove()
            Else
                OnSelected(x0, y0, x1 - x0, y1 - y0)
            End If
            Return
        End If
 
    End Sub
 
    Private Sub Leave(ByVal sender As Object, ByVal e As EventArgs) Handles _
      ctl.MouseLeave
        Drawn = Drawn And True
        Drawing = False
        Remove()
    End Sub
 
    Protected Overridable Sub OnSelected(ByVal x As Integer, ByVal y As _
      Integer, ByVal width As Integer, ByVal height As Integer)
        RaiseEvent Selected(Me, New RubberBoxEventArgs(ctl, x, y, width, _
        height))
    End Sub
 
    <Description("Get the selected image portion from a supplied Image"), _
    EditorBrowsable(EditorBrowsableState.Always)> _
    Public Overridable Function CutSelection(ByVal img As Image, ByVal _
    isStretched As Boolean) As Image
        Dim gn As Graphics
        Dim go As Graphics
        Dim width As Integer = x1 - x0
        Dim height As Integer = y1 - y0
        Dim newImage As Bitmap
 
        If Not Drawn Then Return Nothing
 
        If isStretched Then
            Dim Ratio_Width As Double = img.Width / ctl.Width
            Dim Ratio_hight As Double = img.Height / ctl.Height
            x0 *= Ratio_Width
            x1 *= Ratio_Width
            y0 *= Ratio_hight
            y1 *= Ratio_hight
        End If
 
        Try
            go = ctl.CreateGraphics()
            newImage = New Bitmap(width, height, go)
            gn = Graphics.FromImage(newImage)
            gn.DrawImage(img, New Rectangle(0, 0, width, height), New Rectangle( _
              x0, y0, width, height), GraphicsUnit.Pixel)
            Return newImage
        Finally
            go.Dispose()
            gn.Dispose()
            Drawing = False
        End Try
    End Function
 
    <Description("Clear the rubber box"), _
    EditorBrowsable(EditorBrowsableState.Always)> _
    Public Sub Clear()
        If Drawn Or Drawing Then Remove()
        Drawing = False
    End Sub
 
End Class
Da fehlt dann nur noch:
Imports System.Windows.Forms
 
Public Class RubberBoxEventArgs
    Inherits System.EventArgs
    Public source As control
    Public x As Integer
    Public y As Integer
    Public width As Integer
    Public height As Integer
 
    Public Sub New(ByVal src As Control, ByVal px As Integer, ByVal py As _
      Integer, ByVal pwidth As Integer, ByVal pheight As Integer)
        source = src
        x = px
        y = py
        width = pwidth
        height = pheight
    End Sub
End Class
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Aus einer Grafik in einer Picture-Box ein Bereich auslesen3.063UR08.03.04 11:51
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.567WaldiMaywood08.03.04 12:14
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.452UR08.03.04 12:29
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.899ModeratorDaveS08.03.04 12:20
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.427UR08.03.04 12:26
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...3.277leth11.03.04 08:14
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.500UR11.03.04 11:17
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.552leth11.03.04 11:29
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.412UR11.03.04 13:23
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.416leth11.03.04 13:43
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.431UR11.03.04 14:22
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.382leth11.03.04 14:30
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.433UR11.03.04 14:51
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.475leth11.03.04 15:32
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.406UR12.03.04 00:39
Re: Aus einer Grafik in einer Picture-Box ein Bereich ausle...2.634leth12.03.04 08:18
Übrigens...2.469ModeratorDaveS11.03.04 22:36
Re: Übrigens...2.519UR11.03.04 22:44
Re: Übrigens...2.507leth12.03.04 08:03
Re: Übrigens...2.606WaldiMaywood12.03.04 08:38
Re: Übrigens...2.757ModeratorDaveS12.03.04 10:32
Re: Übrigens...2.499UR12.03.04 13:43
Re: Übrigens...2.412ModeratorDaveS12.03.04 14:08
Re: Übrigens...2.413UR12.03.04 14:24
Re: Übrigens...2.444ModeratorDaveS12.03.04 14:31
Re: Übrigens...2.426UR12.03.04 16:24
Re: Übrigens...2.394ModeratorDaveS12.03.04 16:35
Re: Übrigens...Teil II2.526ModeratorDaveS12.03.04 10:33
Danke!2.512leth12.03.04 10:37
Re: Übrigens...Teil II2.329leth12.03.04 10:44

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-2025 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