1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
'1er forme de test du panel
Imports System.Windows.Forms
Public Class frmTLPanel
Friend WithEvents TLP As TableLayoutPanel
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.TLP = New TableLayoutPanel
Me.TLP.RowCount = 10
Dim style As RowStyle
Dim labelTest As New Label
Dim rndHeight As Random = New Random
MessageBox.Show(Me.TLP.RowStyles.Count.ToString)
For numRow As Integer = 0 To Me.TLP.RowCount - 1
Dim reste As Integer = 0
Math.DivRem(numRow, 2, reste)
If numRow > 1 And reste = 0 Then 'ligne impaire >1
labelTest = New Label
labelTest.Text = "myRow"
labelTest.Height = 80
labelTest.BackColor = Color.Yellow
labelTest.Dock = DockStyle.Fill
Me.TLP.Controls.Add(labelTest, 0, numRow)
style = New RowStyle
style.SizeType = SizeType.Absolute
style.Height = rndHeight.Next(50, 70)
Me.TLP.RowStyles.Add(style)
Else
labelTest = New Label
labelTest.Text = "myRow"
labelTest.Height = 80
labelTest.BackColor = Color.Red
labelTest.Dock = DockStyle.Fill
Me.TLP.Controls.Add(labelTest, 0, numRow)
style = New RowStyle
style.SizeType = SizeType.Percent
style.Height = rndHeight.Next(50, 50)
Me.TLP.RowStyles.Add(style)
End If
Next
'docker
Me.TLP.Dock = DockStyle.Fill
Me.TLP.AutoScroll = True
'grille visible
Me.TLP.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single
'GrowStyle
Me.TLP.GrowStyle = TableLayoutPanelGrowStyle.AddRows
'add to form
Me.Controls.Add(Me.TLP)
Me.AutoScroll = True
End Sub
Public Sub AdjustRowHeightTableLayoutPanel()
Dim styles As TableLayoutRowStyleCollection = Me.TLP.RowStyles
For i As Integer = 0 To styles.Count - 1
If styles(i).SizeType = SizeType.Absolute And i > 2 Then
' Set the row height to 60 pixels.
styles(i).Height = 60
End If
Next
End Sub
End Class
'2eme forme avec 2 buttons
Public Class Form1
Private maForme As frmTLPanel = New frmTLPanel
'liste les rows existants
Private Sub btnDisplayHeightRows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayHeightRows.Click
'affiche le form
maForme.Show()
'obtient hauteur des lignes
Dim heightRows() As Integer = maForme.TLP.GetRowHeights
'obtient styles des lignes
Dim styles As TableLayoutRowStyleCollection = maForme.TLP.RowStyles
For i As Integer = 0 To maForme.TLP.RowCount - 1
Me.ListBoxRowHeight.Items.Add("ligne" & (i + 1).ToString & " :" & heightRows(i).ToString & "style : " & styles(i).SizeType.ToString)
Next
End Sub
'sette les rows impairs
Private Sub btnSetHeightRows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetHeightRows.Click
Dim styles As TableLayoutRowStyleCollection = maForme.TLP.RowStyles
Me.ListBoxSetRowHeight.Items.Add("nb styles: " & styles.Count.ToString)
Me.ListBoxSetRowHeight.Items.Add(vbCrLf)
For i As Integer = 0 To styles.Count - 1
If styles(i).SizeType = SizeType.Absolute And i > 2 Then
' Set the row height to 150 pixels.
styles(i).Height = 150
Me.ListBoxSetRowHeight.Items.Add("row n° : " & (i + 1).ToString & " - " & styles(i).SizeType.ToString & " - " & styles(i).Height.ToString)
End If
Next
End Sub
End Class |
Partager