Eigene Form - Resizeable

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

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.

    Eigene Form - Resizeable

    Hallo.
    Und zwar habe ich jetzt eine eigene Form erstellt (per Inherits Form).

    Soweit klappt alles gut, jedoch würde ich gerne die Form unten Rechts in
    der Ecke resizen können ( so wie bei Mac Os X).

    Weiß jemand wie das funktioniert?


    Des Weiteren wird meine Form erst im Debug angezeigt,
    im IDE Designer jedoch nach erfolgreicher Vererbung nicht.
    Muss man da noch eine Property hinzufügen oder soetwas?

    Daniel Baumert schrieb:

    im IDE Designer jedoch nach erfolgreicher Vererbung nicht.
    Hast Du einen expliziten Konstruktor mit explizitem InitializeComponents()-Aufruf?
    -----
    Poste mal von dieser Form New() und InitializeComponents().
    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!
    Der Code sieht so aus:

    VB.NET-Quellcode

    1. Option Strict On
    2. Option Infer Off
    3. Imports System.Runtime.InteropServices
    4. Public Class Design : Inherits Form
    5. Private Sub Round(x As Integer, y As Integer, width As Integer, height As Integer, radius As Integer, T As Form)
    6. Dim gp As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath()
    7. gp.AddLine(x + radius, y, x + width - radius, y)
    8. gp.AddArc(x + width - radius, y, radius, radius, 270, 90)
    9. gp.AddLine(x + width, y + radius, x + width, y + height - radius)
    10. gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90)
    11. gp.AddLine(x + width - radius, y + height, x + radius, y + height)
    12. gp.AddArc(x, y + height - radius, radius, radius, 90, 90)
    13. gp.AddLine(x, y + height - radius, x, y + radius)
    14. gp.AddArc(x, y, radius, radius, 180, 90)
    15. gp.CloseFigure()
    16. T.Region = New System.Drawing.Region(gp)
    17. gp.Dispose()
    18. End Sub
    19. Private EdgeTopLeft, EdgeTopRight, EdgeBottomLeft, EdgeBottomRight, Middle, FormBgCol, SideL, SideR As Bitmap
    20. Public Sub New()
    21. Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    22. Me.Size = New Size(107, 95)
    23. Me.DoubleBuffered = True
    24. Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    25. Me.SetStyle(ControlStyles.FixedHeight, True)
    26. Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    27. Me.SetStyle(ControlStyles.ResizeRedraw, True)
    28. Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
    29. Me.SetStyle(ControlStyles.UserPaint, True)
    30. EdgeTopLeft = My.Resources.EdgeL
    31. EdgeTopRight = My.Resources.EdgeR
    32. EdgeBottomLeft = My.Resources.BottomL
    33. EdgeBottomRight = My.Resources.BottomR
    34. FormBgCol = My.Resources.FillColor
    35. Middle = My.Resources.Middle
    36. SideL = My.Resources.SideL
    37. SideR = My.Resources.SideR
    38. End Sub
    39. Public Sub Redraw(ausgabe As Graphics)
    40. Dim gr As Graphics = ausgabe
    41. gr.Clear(Me.BackColor)
    42. Dim topcz As Size = New Size(EdgeTopLeft.Width, EdgeTopLeft.Height)
    43. gr.DrawImage(EdgeTopLeft, 1, 1, topcz.Width, topcz.Height)
    44. gr.DrawImage(EdgeTopRight, Me.Width - 1 - topcz.Width, 1, topcz.Width, topcz.Height)
    45. For b As Integer = topcz.Width To Me.Size.Width - (topcz.Width - 1)
    46. gr.DrawImage(Middle, b, 1, Middle.Width, Middle.Height)
    47. Next
    48. Dim green As Bitmap = My.Resources.Green
    49. Dim red As Bitmap = My.Resources.red
    50. Dim yellow As Bitmap = My.Resources.yellow
    51. Dim si As Size = New Size(green.Width, green.Height)
    52. Dim ypo As Short = 6
    53. gr.DrawImage(red, 9, ypo, si.Width, si.Height)
    54. gr.DrawImage(yellow, 9 + si.Width + 6, ypo, si.Width, si.Height)
    55. gr.DrawImage(green, 9 + si.Width * 2 + 12, ypo, si.Width, si.Height)
    56. Dim WorkingareaWithoutCorners As New Size()
    57. WorkingareaWithoutCorners.Height = Me.Height - EdgeBottomLeft.Height + 2
    58. WorkingareaWithoutCorners.Width = Me.Width - EdgeTopLeft.Width
    59. For x As Integer = EdgeTopLeft.Width - 7 To WorkingareaWithoutCorners.Width + 7
    60. For y As Integer = EdgeTopLeft.Height To WorkingareaWithoutCorners.Height
    61. gr.DrawImage(FormBgCol, x, y, 1, 1)
    62. Next
    63. Next
    64. Round(1, 1, Me.Width - 2, Me.Height - 2, 10, Me)
    65. Dim tc As New Size(SideL.Width, SideR.Height)
    66. For z As Integer = EdgeTopLeft.Height To Me.Width
    67. gr.DrawImage(SideL, tc.Width - 1, z, tc.Width, tc.Height)
    68. gr.DrawImage(SideR, Me.Width - 1 - tc.Width, z, tc.Width, tc.Height)
    69. Next
    70. End Sub
    71. Protected Overrides Sub OnPaint(pevent As System.Windows.Forms.PaintEventArgs)
    72. Redraw(pevent.Graphics)
    73. End Sub
    74. Private Sub InitializeComponent()
    75. Me.SuspendLayout()
    76. '
    77. 'Design
    78. '
    79. Me.ClientSize = New System.Drawing.Size(284, 261)
    80. Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    81. Me.Name = "Design"
    82. Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    83. Me.ResumeLayout(False)
    84. End Sub
    85. End Class


    Es besteht zudem noch das Problem, dass man die Form bei Laufzeit nicht bewegen kann.

    Daniel Baumert schrieb:

    VB.NET-Quellcode

    1. Private Sub InitializeComponent()
    wird nicht aufgeerufen, pack den Aufruf als erstes in Konstruktor.
    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!