Microsoft Developer Network >
Página principal de foros
>
Visual Basic General
>
Panel doesnt show real width
Panel doesnt show real width
- HiHere is the situation:Im dynamicaly adding buttons to panel using Panel.Controls.AddAll the buttons are lined up by increasing Location.x value of buttonWhen button goes over panel borders the scroll bar appearsSo far so good...Now I dont want that scroll bar so i decide to put buttons that go outside the right side of panelto 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
- 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
Todas las respuestas
- 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 Blog ♦ My Facebook ♦ YOUR Place to have fun time ! ♦ Awesome RPG Action Game - 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
- 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! - Here's the code:Dim row As DataRowDim i As Byte = 0Dim x, y As IntegertblUzdevumi = ptblUzdevumiDim xLoc, yLoc As IntegerxLoc = 5yLoc = 15For Each row In tblUzdevumi.Rowsi = i + 1''creates buttonDim cmdUzd As Infragistics.Win.Misc.UltraButtoncmdUzd = New Infragistics.Win.Misc.UltraButtoncmdUzd.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 = icmdUzd.Text = Convert.ToString(i)Me.ToolTip1.SetToolTip(cmdUzd, row.Item("Virsraksts"))''sets locationWith cmdUzd.Location = New Point(xLoc, yLoc)End WithxLoc += 27If (xLoc + 27) > Me.SplitContainer1.Panel1.Right ThenxLoc = 5yLoc += (5 + 21)End IfMe.SplitContainer1.Panel1.Controls.Add(cmdUzd)pArrPogas.Add(cmdUzd)arrIrAtbildes.Add(False)arrIrSaubos.Add(False)Next
Cheers! - 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.

