Formular una preguntaFormular una pregunta
 

RespondidaPanel doesnt show real width

  • domingo, 08 de noviembre de 2009 11:14naurispunk Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi

    Here is the situation:
    Im dynamicaly adding buttons to panel using Panel.Controls.Add
    All the buttons are lined up by increasing Location.x value of button
    When button goes over panel borders the scroll bar appears

    So far so good...

    Now I dont want that scroll bar so i decide to put buttons that go outside the right side of panel
    to put in lower line. 
    But the thing is that the first button that goes out of sight has x cordinate of 1000 or something like that while panel width is only like 600?

    Reason for this may be the fact that panel is anchored and my application on diferent resolution has different widths. 
    But the funny thing is that also the parents of this panel are way too small (I mean their width atributes are smaller that the actual width of  window)


    Does anyone know why this happens and how to get thre real width of panels?

    Thanks in advance for answers.


    Cheers!

Respuestas

Todas las respuestas

  • domingo, 08 de noviembre de 2009 12:52Omie Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Tiene código
    But the thing is that the first button that goes out of sight has x cordinate of 1000 or something like that while panel width is only like 600?

    - Could not reproduce. Are you sure about this ? Most probably it could be the location of last button in row which you dont see. It will be helpful if you post your code.


    my code for reference,

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim buttons(10) As Button
            Dim xLoc, yLoc As Integer
    
            xLoc = 5
            yLoc = 15
    
            For i As Integer = 1 To 10
                buttons(i) = New Button
                With buttons(i)
                    .Location = New Point(xLoc, yLoc)
                    .Size = New Size(100, 100)
                    .Text = .Location.ToString
                End With
    
                xLoc += 105
    
                If (xLoc + 100) > Panel1.Right Then
                    xLoc = 5
                    yLoc += 110
                End If
    
                Panel1.Controls.Add(buttons(i))
            Next
        End Sub
    

    Thanks

    My BlogMy FacebookYOUR Place to have fun time ! Awesome RPG Action Game
  • domingo, 08 de noviembre de 2009 13:16Dig-Boy Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    Is your panel docked?  Docking can give a false sense of width because the true width is overridden during docked display. 
    • Marcado como respuestanaurispunk domingo, 08 de noviembre de 2009 22:30
    •  
  • domingo, 08 de noviembre de 2009 13:28naurispunk Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Yes its docked. 
    But still i think Width of panel should represent the real width of it... unless im adding buttons befor the docking has taken place...hmm


    Cheers!
  • domingo, 08 de noviembre de 2009 13:28naurispunk Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Here's the code:


                Dim row As DataRow
                Dim i As Byte = 0
                Dim x, y As Integer
                tblUzdevumi = ptblUzdevumi
                Dim xLoc, yLoc As Integer

                xLoc = 5
                yLoc = 15

                For Each row In tblUzdevumi.Rows
                    i = i + 1

                    ''creates button
                    Dim cmdUzd As Infragistics.Win.Misc.UltraButton
                    cmdUzd = New Infragistics.Win.Misc.UltraButton
                    cmdUzd.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(186, Byte))
                    cmdUzd.Name = Convert.ToString(i)
                    cmdUzd.Size = New System.Drawing.Size(27, 21)
                    cmdUzd.TabIndex = i
                    cmdUzd.Text = Convert.ToString(i)
                    Me.ToolTip1.SetToolTip(cmdUzd, row.Item("Virsraksts"))

                    ''sets location
                    With cmdUzd
                        .Location = New Point(xLoc, yLoc)
                    End With

                    xLoc += 27

                    If (xLoc + 27) > Me.SplitContainer1.Panel1.Right Then
                        xLoc = 5
                        yLoc += (5 + 21)
                    End If

                    Me.SplitContainer1.Panel1.Controls.Add(cmdUzd)

                    pArrPogas.Add(cmdUzd)
                    arrIrAtbildes.Add(False)
                    arrIrSaubos.Add(False)
                Next

    Cheers!
  • domingo, 08 de noviembre de 2009 23:02Dig-Boy Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    I tried your code with a button click (which is definitely after the form has loaded and initialized all docking) and it worked fine.  I got the buttons to wrap down within the panel.  You should know that once you get past 99 the last digit in the text gets cut off so either go with a wider button or a smaller font (unless you are sure it will never have more than 99 buttons.)

    Also, you didn't mention it was a SplitContainer panel!  Not sure if it make a difference anyhow, but the SC panels are special controls with different functionality than the standard panel.

    If you are indeed doing this is the form's Load handler then try placing this code in the Shown event instead - or just try it for testing by using a button -- that way you can see if the timing was really the issue.