Problem mit Location

  • VB.NET

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von Vatter.

    Problem mit Location

    Hallo,

    ich hab ein Problem.
    Ich erstelle mehrere Panels per Code.
    Und mein Problem ist nun, das ich es einfach nicht hinbekomme, die Location jedes mal wenn ein neues Panel erstellt wird, etwas zu ändern.
    Ich hoffe ihr könnt mir weiterhelfen, ich probier auch schon die ganze Zeit hier aus usw. und gesucht hab ich auch schon und nichts gefunden.

    Mit freundlichen Grüßen pc-freack

    VB.NET-Quellcode

    1. Panel1.Location = New Point(<X Position>, <Y Position>)

    oder relativ zu 'nem anderen Panel:

    VB.NET-Quellcode

    1. Panel2.Location = New Point(Panel1.Location.X + 5, Panel1.Location.Y + 5)



    link_275 :thumbup:
    Hello World
    Öffel.Location = new Point(x,y)
    x+=soviel
    y+= soviel

    @ pc-freack ma ehrlich: Ich habe den Eindruck, dass du dir deinen Code hier Zeile für Zeile zusammenfragst. Liest du auch mal ein Grundlagenbuch oder so?
    Kennst du gallileo Openbook?
    :thumbsup: Seit 26.Mai 2012 Oppa! :thumbsup:
    Mit dem Code erstelle ich ein panel:

    VB.NET-Quellcode

    1. Public Sub newtextfile(ByVal filename As String, Optional ByVal localnew As Boolean = True)
    2. Try
    3. If localnew = True Then
    4. writefile(filename)
    5. End If
    6. Dim filenamelabel As New Label
    7. filenamelabel.Text = filename
    8. filename1 = filename
    9. filenamelabel.Location = New Point(3, 53)
    10. filenamelabel.Size = New Size(58, 13)
    11. filenamelabel.AutoSize = False
    12. filenamelabel.TextAlign = ContentAlignment.MiddleCenter
    13. Dim pb As New Button
    14. pb.Size = New Size(64, 50)
    15. pb.Location = New Point(0, 0)
    16. pb.Image = My.Resources.aaaa
    17. Dim txtfile As New Panel
    18. txtfile.Size = New Size(65, 72)
    19. txtfile.Location = New Point(Cursor.Position.X + 50, Cursor.Position.Y + 50)
    20. txtfile.Controls.Add(filenamelabel)
    21. txtfile.Controls.Add(pb)
    22. txtfile.ContextMenuStrip = file_cm
    23. txtfile.Visible = True
    24. txtfile.BackColor = Color.Transparent
    25. txtfile.Parent = Me
    26. AddHandler pb.Click, AddressOf Button_Click
    27. AddHandler txtfile.MouseDown, AddressOf Panel_MouseDown
    28. AddHandler txtfile.MouseMove, AddressOf Panel_MouseMove
    29. Catch ex As Exception
    30. MsgBox(ex.Message)
    31. End Try
    32. End Sub


    Und an der stelle ist mein Problem:

    VB.NET-Quellcode

    1. txtfile.Location = New Point(Cursor.Position.X + 50, Cursor.Position.Y + 50)


    Und das Problem ist, das sich die location anscheinend nicht ändern, weil beim 2. mal, wenn der code aufgerufen wird, dann ist das 2. Panel nicht sichtbar.

    @Vatter
    Nein, den meisten Code schreibe ich selbst doch wenn ich ein Problem habe und auch nichts dazu finde, dann rstelle ich erst einen thread.
    Wenn das 2. Panel eine andere Position als das erste haben soll, mußt du die alte Position abfragen (siehe link_275) oder den errechneten Punkt global speichern und inkrementieren.
    Beachte außerdem, dass dir Cursor.Position die Position Bildschirmbasiert ausgibt und nicht Formbasiert. msdn.microsoft.com/de-de/libra…orms.cursor.position.aspx Mit PointToClient kannst du umrechnen.
    Wie gesagt: Is auch nich bös gemeint, aber du solltest dich mit den Codeschnipseln, die du aufschreibst beschäftigen und verstehe, was die machen. ;)
    :thumbsup: Seit 26.Mai 2012 Oppa! :thumbsup:

    link_275 schrieb:

    Die Koordinaten innerhalb der Form, das wird interessant für dich sein
    Stümmt, aber nur, wenn er e aus einem Event wie z.B. MouseMove als Parameter an die Sub übergebn tut oder global deklariert abspeichort.
    :thumbsup: Seit 26.Mai 2012 Oppa! :thumbsup: