Posts Tagged ‘Custom Control’

How create a Container User Control

  1. Imports System.ComponentModel
  2. Imports System.ComponentModel.Design
  3.  
  4. <Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", GetType(IDesigner))> _
  5. Public Class UserControl1
  6.  
  7. End Class

, , ,

No Comments


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;

  1. Select Listbox control, in the property set the DrawMode to OwnerDrawVariable
  2. InĀ MeasureItem event of the listbox, add the code below

    e.ItemHeight = 25

  3. Add this code to the DrawItem Event
    1.     Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
    2.         e.DrawBackground()
    3.  
    4.         Dim drawbrush As Brush
    5.  
    6.         If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
    7.             drawbrush = Brushes.White
    8.         Else
    9.             drawbrush = Brushes.Black
    10.         End If
    11.  
    12.         Dim s As String
    13.  
    14.         s = CType(sender, ListBox).Items(e.Index).ToString
    15.  
    16.         e.Graphics.DrawString(s, CType(sender, Control).Font, drawbrush, e.Bounds.X, e.Bounds.Y)
    17.  
    18.  
    19.     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.

, , ,

No Comments



SetPageWidth