ein Option Strict On Problem "System.Drawing.Point" <> System.Drawing.Size"

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 9 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    ein Option Strict On Problem "System.Drawing.Point" <> System.Drawing.Size"

    Hallo liebe Freunde,

    ich steh bei einem Problem auf dem Schlauch.

    Mit Option Strickt off funktioniert alles wie es soll, dennoch möchte ich gerne auf "on" stellen.
    Es geht nur um diese Codeteile, wo ich nicht wirklich weiß, wie ich das richtig hinbekomme.

    Zweck des Codes ist es mehrere Panels per Maus auf einer Form oder einem Panel zu verschieben.

    Code und Fehlermeldungen anbei als Bildanhang.

    VB.NET-Quellcode

    1. Private PanelPos As Point
    2. 'Panel verschiebbar
    3. Private Sub Panel_Notiz_MouseDown(sender As Object, e As MouseEventArgs)
    4. If e.Button = Windows.Forms.MouseButtons.Left Then
    5. PanelPos = New Point(e.Location)
    6. End If
    7. End Sub
    8. 'Panel verschiebbar
    9. Private Sub Panel_Notiz_MouseMove(sender As Object, e As MouseEventArgs)
    10. Dim index As Integer = CInt(DirectCast(sender, Control).Tag)
    11. With Notiz(index).ProjektonsPanel
    12. .BringToFront()
    13. 'verschieben während linke Maustaste gedrückt
    14. If e.Button = Windows.Forms.MouseButtons.Left Then
    15. .Location = New Point(.Location + (e.Location - PanelPos))
    16. Exit Sub
    17. End If
    18. End With
    19. End Sub
    20. 'Panel verschiebbar
    21. Private Sub Panel_Notiz_MouseUp(sender As Object, e As MouseEventArgs)
    22. Dim index As Integer = CInt(DirectCast(sender, Control).Tag)
    23. If Notiz(index).ProjektonsPanel.Left < 16 Then Notiz(index).ProjektonsPanel.Left = 16
    24. If Notiz(index).ProjektonsPanel.Top < 90 Then Notiz(index).ProjektonsPanel.Top = 90
    25. If Notiz(index).ProjektonsPanel.Left > Panel_Spezial.Width - Notiz(index).ProjektonsPanel.Width - 22 Then Notiz(index).ProjektonsPanel.Left = Panel_Spezial.Width - Notiz(index).ProjektonsPanel.Width - 22
    26. If Notiz(index).ProjektonsPanel.Top > Panel_Spezial.Height - Notiz(index).ProjektonsPanel.Height - 22 Then Notiz(index).ProjektonsPanel.Top = Panel_Spezial.Height - Notiz(index).ProjektonsPanel.Height - 22
    27. Notiz(index).links = Notiz(index).ProjektonsPanel.Left
    28. Notiz(index).oben = Notiz(index).ProjektonsPanel.Top
    29. End Sub


    Danke für Eure Hilfe und Tipps.

    LG Roland
    Bilder
    • 12022019171834.jpg

      235,72 kB, 914×541, 100 mal angesehen
    Liebe Grüße
    Roland Berghöfer

    Meine aktuellen und kostenlos verwendbaren Tools (mit VB.NET erstellt): freeremarkabletools.com | priconman.com | SimpleCalendar | AudibleTouch | BOComponent.com | bonit.at
    @dive26 Location ist ein Point. Da muss wohl ein New Size(...) hin.

    VB.NET-Quellcode

    1. Dim sz = New Size(10, 11)
    2. Dim pt = New Point(sz)
    3. Dim sz2 = New Size(pt)
    geht alles,

    VB.NET-Quellcode

    1. Dim pt2 = New Point(pt)
    geht nicht wegen Point => Point.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Ist es nicht so, das Location auch ein Point (von Drawing) ist?
    Point kann glaube ich keine Point aufnehmen, dass muss doch so heissen

    VB.NET-Quellcode

    1. 'Korrektur
    2. Me.PanelPos = e.Location
    3. 'Beispiel
    4. Dim p = New Point With {.X = e.Location.X + Me.PanelPos.X,
    5. .Y = e.Location.Y + Me.PanelPos.Y}


    Das gleiche Problem auch in Zeile 17.

    Ist Notiz eine selber gemachte Panel?

    EDIT: RFG du hast natürlich recht, Zuweisung gleich direkt. Beim zusammenzählen von Point, muss der Weg über die Koordinaten trotzdem gegangen werden.

    Freundliche Grüsse

    exc-jdbi

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „exc-jdbi“ ()

    @exc-jdbi Wenn, dann doch gleich

    VB.NET-Quellcode

    1. Me.PanelPos = e.Location
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Vielen Dank @RodFromGermany
    Die MouseDown Routine habe ich so umgebaut, das passt schon mal:

    VB.NET-Quellcode

    1. 'Panel verschiebbar
    2. Private Sub Panel_Notiz_MouseDown(sender As Object, e As MouseEventArgs)
    3. Dim index As Integer = CInt(DirectCast(sender, Control).Tag)
    4. LetzterNotizIndex = index
    5. If e.Button = Windows.Forms.MouseButtons.Left Then
    6. Dim sz = New Size(e.Location.X, e.Location.Y)
    7. PanelPos = New Point(sz)
    8. End If
    9. End Sub


    aber bei diesem Teil steh ich noch auf der Leitung:

    VB.NET-Quellcode

    1. .Location = New Point(.Location + (e.Location - PanelPos))
    Liebe Grüße
    Roland Berghöfer

    Meine aktuellen und kostenlos verwendbaren Tools (mit VB.NET erstellt): freeremarkabletools.com | priconman.com | SimpleCalendar | AudibleTouch | BOComponent.com | bonit.at
    Warum nicht einfach ein eigenes Control machen? Sieht so aus, als wenn du das in der Klasse des Forms machst. Hast du da ein eigenes Control hast du deinen Code übersichtlicher und der Code wird nicht lämger wenn man mehrere Panels beweglich haben möchte. Hier ein Strip-Down einer meiner Panels

    VB.NET-Quellcode

    1. Public Class MoveAblePanel
    2. Inherits Panel
    3. Sub New()
    4. DoubleBuffered = True
    5. End Sub
    6. Private ClickedAt As Point = Nothing
    7. Private Sub Me_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
    8. If e.Button = MouseButtons.Left Then
    9. ClickedAt = e.Location
    10. End If
    11. End Sub
    12. Private Sub Me_MouseMove(sedner As Object, e As MouseEventArgs) Handles Me.MouseMove
    13. If ClickedAt <> Nothing Then
    14. Dim newpos As Point = Parent.PointToClient(New Point(Cursor.Position.X - ClickedAt.X, Cursor.Position.Y - ClickedAt.Y))
    15. If newpos.X < 0 Then newpos.X = 0
    16. If newpos.X > Parent.ClientRectangle.Width - Width Then newpos.X = Parent.ClientRectangle.Width - Width
    17. If newpos.Y < 0 Then newpos.Y = 0
    18. If newpos.Y > Parent.ClientRectangle.Height - Height Then newpos.Y = Parent.ClientRectangle.Height - Height
    19. Location = newpos
    20. End If
    21. End Sub
    22. Private Sub Me_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
    23. ClickedAt = Nothing
    24. End Sub
    25. End Class


    Edit @dive26
    Sonst sollte es so klappen:

    VB.NET-Quellcode

    1. .Location = New Point(.Location.x + (e.Location.x - PanelPos.x), .Location.y + (e.Location.y - PanelPos.y)


    Cloud Computer? Nein Danke! Das ist nur ein weiterer Schritt zur totalen Überwachung.
    „Wer die Freiheit aufgibt, um Sicherheit zu gewinnen, wird am Ende beides verlieren.“
    Benjamin Franklin

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „NoIde“ ()

    Danke, klappt nun so mit Option Stict on.

    VB.NET-Quellcode

    1. 'Panel verschiebbar
    2. Private Sub Panel_Notiz_MouseMove(sender As Object, e As MouseEventArgs)
    3. Dim index As Integer = CInt(DirectCast(sender, Control).Tag)
    4. LetzterNotizIndex = index
    5. With Notiz(index).ProjektonsPanel
    6. .BringToFront()
    7. 'verschieben während linke Maustaste gedrückt
    8. If e.Button = Windows.Forms.MouseButtons.Left Then
    9. Dim sz = New Size(e.Location.X - PanelPos.X + .Location.X, e.Location.Y - PanelPos.Y + .Location.Y)
    10. .Location = New Point(sz)
    11. Exit Sub
    12. End If
    13. End With
    14. End Sub
    Liebe Grüße
    Roland Berghöfer

    Meine aktuellen und kostenlos verwendbaren Tools (mit VB.NET erstellt): freeremarkabletools.com | priconman.com | SimpleCalendar | AudibleTouch | BOComponent.com | bonit.at

    dive26 schrieb:

    VB.NET-Quellcode

    1. .Location = New Point(.Location + (e.Location - PanelPos))
    Points zu addieren / subtrahieren wäre doch glatt eine Befehlserweiterung wert:

    VB.NET-Quellcode

    1. Imports System.Runtime.CompilerServices
    2. ' Modul, Sub, Function
    3. ' Properties können keine Extension sein (DisplayMember)
    4. Module Extensions
    5. <Extension()> _
    6. Public Function MyAdd(ByVal a As Point, ByVal b As Point) As Point
    7. Return New Point(a.X + b.X, a.Y + b.Y)
    8. End Function
    9. End Module

    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!