Posts Tagged ‘Custom Control’
How create a Container User Control
Posted by: admin in .NET, User Control on December 28th, 2010
-
Imports System.ComponentModel
-
Imports System.ComponentModel.Design
-
-
<Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", GetType(IDesigner))> _
-
Public Class UserControl1
-
-
End Class
How to change the Height of Listbox Item
To change the height of the listbox items you have to customize the listbox by drawing the each item manually, to do this;
- Select Listbox control, in the property set the DrawMode to OwnerDrawVariable
- InĀ MeasureItem event of the listbox, add the code below
e.ItemHeight = 25
- Add this code to the DrawItem Event
-
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
-
e.DrawBackground()
-
-
Dim drawbrush As Brush
-
-
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
-
drawbrush = Brushes.White
-
Else
-
drawbrush = Brushes.Black
-
End If
-
-
Dim s As String
-
-
s = CType(sender, ListBox).Items(e.Index).ToString
-
-
e.Graphics.DrawString(s, CType(sender, Control).Font, drawbrush, e.Bounds.X, e.Bounds.Y)
-
-
-
End Sub
-
Note: The difference between the two owner-drawn options is that with fixed drawing each item in the list is the standard size (typically 13 px), and with OwnerDrawVariable you can specify the height for each item independently.