Größen Änderung zur Laufzeit

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Andy16823.

    Größen Änderung zur Laufzeit

    Morgen VB-Pler,

    Ich habe mir mit GDI+ ein set von Controls erstellt das ähnlich wie in der Entwiklungslaufzeit einen Rahmen mit Punkten hinzufügt. Das war ja ganz einfach nun mein Problem wie kann ich das Control zur Laufzeit Vergrößern und verkleinern


    mein code dazu:

    VB.NET-Quellcode

    1. Protected Overrides Sub OnMouseDown(e As Windows.Forms.MouseEventArgs)
    2. MyBase.OnMouseDown(e)
    3. If e.Button = Windows.Forms.MouseButtons.Left Then
    4. If rect1.Contains(e.Location) Then
    5. MyBase.Cursor = Windows.Forms.Cursors.PanNW
    6. End If
    7. If rect2.Contains(e.Location) Then
    8. MyBase.Cursor = Windows.Forms.Cursors.PanNE
    9. End If
    10. If rect3.Contains(e.Location) Then
    11. MyBase.Cursor = Windows.Forms.Cursors.PanSW
    12. End If
    13. If rect4.Contains(e.Location) Then
    14. MyBase.Cursor = Windows.Forms.Cursors.PanSE
    15. End If
    16. End If
    17. End Sub
    18. Protected Overrides Sub OnMouseMove(e As Windows.Forms.MouseEventArgs)
    19. MyBase.OnMouseMove(e)
    20. If e.Button = Windows.Forms.MouseButtons.Left Then
    21. If rect1.Contains(e.Location) Then
    22. End If
    23. If rect2.Contains(e.Location) Then
    24. End If
    25. If rect3.Contains(e.Location) Then
    26. End If
    27. If rect4.Contains(e.Location) Then
    28. End If
    29. End If
    30. End Sub
    Bilder
    • control mit rahmen.JPG

      33,68 kB, 713×678, 148 mal angesehen
    Ich hab dir mal ein Beispiel runtergetippt. Hab aber nur groessenänderung an den Ecken gemacht, musst du noch erweitern.
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class sPanel
    2. Inherits Panel
    3. Private corners(3) As Rectangle 'NW,NE,SE,SW
    4. Private Enum SizeMode
    5. NW
    6. NE
    7. SE
    8. SW
    9. None
    10. End Enum
    11. Private Property sMode As SizeMode
    12. Sub New()
    13. SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    14. SetStyle(ControlStyles.ResizeRedraw, True)
    15. SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    16. MinimumSize = New Size(25, 25)
    17. MaximumSize = New Size(1000, 1000)
    18. Width = 200
    19. Height = 75
    20. sMode = SizeMode.None
    21. SetCornerRects()
    22. End Sub
    23. Protected Overrides Sub OnPaint(e As PaintEventArgs)
    24. MyBase.OnPaint(e)
    25. With e.Graphics
    26. .FillRectangles(New SolidBrush(ForeColor), corners)
    27. End With
    28. End Sub
    29. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
    30. MyBase.OnMouseMove(e)
    31. Static startloc As Point = Location
    32. Static startcursorloc As Point = Cursor.Position
    33. Static startsize As Size = Size
    34. If e.Button = Windows.Forms.MouseButtons.Left Then
    35. Dim diff_cur As Size = New Size(Cursor.Position.X - startcursorloc.X, Cursor.Position.Y - startcursorloc.Y)
    36. Select Case sMode
    37. Case SizeMode.NW
    38. Size = New Size(startsize.Width - diff_cur.Width, startsize.Height - diff_cur.Height)
    39. Location = New Point(startloc.X - Width + startsize.Width, startloc.Y - Height + startsize.Height)
    40. Case SizeMode.NE
    41. Size = New Size(startsize.Width + diff_cur.Width, startsize.Height - diff_cur.Height)
    42. Location = New Point(startloc.X, startloc.Y - Height + startsize.Height)
    43. Case SizeMode.SE
    44. Size = New Size(startsize.Width + diff_cur.Width, startsize.Height + diff_cur.Height)
    45. Case SizeMode.SW
    46. Size = New Size(startsize.Width - diff_cur.Width, startsize.Height + diff_cur.Height)
    47. Location = New Point(startloc.X - Width + startsize.Width, startloc.Y)
    48. End Select
    49. SetCornerRects()
    50. Else
    51. startloc = Location
    52. startcursorloc = Cursor.Position
    53. startsize = Size
    54. SetCornerRects()
    55. Dim mr As New Rectangle(e.X, e.Y, 1, 1)
    56. For i = 0 To 3
    57. If mr.IntersectsWith(corners(i)) Then
    58. Select Case i
    59. Case 0
    60. Cursor = Cursors.SizeNWSE
    61. sMode = SizeMode.NW
    62. Exit For
    63. Case 1
    64. Cursor = Cursors.SizeNESW
    65. sMode = SizeMode.NE
    66. Exit For
    67. Case 2
    68. Cursor = Cursors.SizeNWSE
    69. sMode = SizeMode.SE
    70. Exit For
    71. Case 3
    72. Cursor = Cursors.SizeNESW
    73. sMode = SizeMode.SW
    74. Exit For
    75. End Select
    76. Else
    77. Cursor = Cursors.Arrow
    78. sMode = SizeMode.None
    79. End If
    80. Next
    81. End If
    82. End Sub
    83. Private Sub SetCornerRects()
    84. corners(0) = New Rectangle(0, 0, 5, 5)
    85. corners(1) = New Rectangle(Width - 5, 0, 5, 5)
    86. corners(2) = New Rectangle(Width - 5, Height - 5, 5, 5)
    87. corners(3) = New Rectangle(0, Height - 5, 5, 5)
    88. End Sub
    89. End Class

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Derfuhr“ ()

    @nafets3646 ich will eine Art Design Surface Erstellen, also eine Control Sammlung die man während der Laufzeit Verschieben und Verändern kann.

    @Derfuhr Danke für den Code werde Ihn Ausprobieren

    Grüße Andy
    Sorry für OT: We wäre es, wenn du Dir GDI+ erstmal ausgiebig mit den Grundlagen zusammen ansiehst? Den Code zusammenstellen zu lassen ist sicherlich keine Dauerlösung.
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!: