|
| |

VB.NET - Fortgeschrittene| Der Beweis: | |  | | Autor: GröVBaZ | | Datum: 16.12.02 09:30 |
| Hier ein kleines Beispiel. Code einfach einfügen und compillieren.
Public Class Form1
Inherits System.Windows.Forms.Form
Dim bHaveMouse As Boolean
Dim ptOriginal As Point
Dim ptLast As Point
Dim lastRc As Rectangle
Dim obj As Button
Dim pic As PictureBox
#Region " Vom Windows Form Designer generierter Code "
..................................
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pic = New PictureBox()
pic.BackColor = Color.White
pic.Size = New Size(Width - 40, Height - 40)
pic.Location = New Point(20, 20)
Me.Controls.Add(pic)
AddHandler pic.MouseDown, AddressOf MyMouseDown
AddHandler pic.MouseMove, AddressOf MyMouseMove
AddHandler pic.MouseUp, AddressOf MyMouseUp
obj = New Button()
obj.FlatStyle = FlatStyle.Flat
obj.BackColor = Color.Gray
obj.Size = New Size(60, 20)
obj.Location = New Point(80, 80)
pic.Controls.Add(obj)
bHaveMouse = False
End Sub
' Convert and Normalize the points and draw the reversible frame.
Private Sub MyDrawReversibleRectangle(ByVal p1 As Point, ByVal p2 As Point)
Dim rc As Rectangle
' Convert the points to screen coordinates.
p1 = PointToScreen(p1)
p2 = PointToScreen(p2)
' Normalize the rectangle.
If (p1.X < p2.X) Then
rc.X = p1.X
rc.Width = p2.X - p1.X
Else
rc.X = p2.X
rc.Width = p1.X - p2.X
End If
If (p1.Y < p2.Y) Then
rc.Y = p1.Y
rc.Height = p2.Y - p1.Y
Else
rc.Y = p2.Y
rc.Height = p1.Y - p2.Y
End If
lastRc = rc
' Draw the reversible frame.
ControlPaint.DrawReversibleFrame(rc, Color.Black, FrameStyle.Dashed)
End Sub
' Called when the left mouse button is pressed down.
Public Sub MyMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
' Make a note that we "have the mouse".
bHaveMouse = True
' Store the "starting point" for this rubber-band rectangle.
ptOriginal.X = e.X + pic.Location.X
ptOriginal.Y = e.Y + pic.Location.Y
' Special value lets us know that no previous
' rectangle needs to be erased.
ptLast.X = -1
ptLast.Y = -1
End Sub
' called when the left mouse button is released
Public Sub MyMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
' Set internal flag to know we no longer "have the mouse".
bHaveMouse = False
' If we have drawn previously, draw again in that spot
' to remove the lines.
If (ptLast.X <> -1) Then
Dim ptCurrent As Point
ptCurrent.X = e.X + pic.Location.X
ptCurrent.Y = e.Y + pic.Location.Y
MyDrawReversibleRectangle(ptOriginal, ptLast)
End If
' Set flags to know that there is no "previous" line to reverse.
ptLast.X = -1
ptLast.Y = -1
ptOriginal.X = -1
ptOriginal.Y = -1
End Sub
' Called when the mouse is moved.
Public Sub MyMouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim ptCurrent As Point
ptCurrent.X = e.X + pic.Location.X
ptCurrent.Y = e.Y + pic.Location.Y
' If we "have the mouse", then we draw our lines.
If (bHaveMouse) Then
' If we have drawn previously, draw again in
' that spot to remove the lines.
If (ptLast.X <> -1) Then
MyDrawReversibleRectangle(ptOriginal, ptLast)
End If
' Update last point.
ptLast = ptCurrent
' Draw new lines.
MyDrawReversibleRectangle(ptOriginal, ptCurrent)
End If
For Each obj In pic.Controls
If Me.Location.X + pic.Location.X + 4 + obj.Location.X + obj.Width > lastRc.Location.X And Me.Location.X + 4 + pic.Location.X + obj.Location.X < lastRc.Location.X + lastRc.Width And _
lastRc.Location.Y + lastRc.Height > Me.Location.Y + pic.Location.Y + obj.Location.Y + 50 - obj.Height And _
lastRc.Location.Y < Me.Location.Y + pic.Location.Y + obj.Location.Y + 50 Then
obj.BackColor = Color.Red
Else
obj.BackColor = Color.Gray
End If
Next
End Sub
End Class |  |
 | 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 |
  |
|
sevZIP40 Pro DLL 
Zippen und Unzippen wie die Profis!
Mit nur wenigen Zeilen Code statten Sie Ihre Anwendungen ab sofort mit schnellen Zip- und Unzip-Funktionen aus. Hierbei lassen sich entweder einzelnen Dateien oder auch gesamte Ordner zippen bzw. entpacken. Weitere InfosTipp des Monats TOP Entwickler-Paket 
TOP-Preis!!
Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1866.50 EUR...
Jetzt nur 979,00 EURWeitere Infos
|
| |
|
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
|
|