Training
Module
Create a UI that uses data binding in .NET MAUI. - Training
Create a UI with data binding. Your UI automatically updates based on the latest data, while the data updates in response to changes in the UI.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This example demonstrates custom drawing of text in a ComboBox control. When an item meets a certain criteria, it is drawn in a larger font and turned red.
Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem
Dim bFont As New Font("Arial", 8, FontStyle.Bold)
Dim lFont As New Font("Arial", 12, FontStyle.Bold)
Dim siText As SizeF
If ComboBox1.Items().Item(e.Index) = "Two" Then
siText = e.Graphics.MeasureString(ComboBox1.Items().Item(e.Index), _
lFont)
Else
siText = e.Graphics.MeasureString(ComboBox1.Items().Item(e.Index), bFont)
End If
e.ItemHeight = siText.Height
e.ItemWidth = siText.Width
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
Dim g As Graphics = e.Graphics
Dim bFont As New Font("Arial", 8, FontStyle.Bold)
Dim lFont As New Font("Arial", 12, FontStyle.Bold)
If ComboBox1.Items().Item(e.Index) = "Two" Then
g.DrawString(ComboBox1.Items.Item(e.Index), lfont, Brushes.Red, _
e.Bounds.X, e.Bounds.Y)
Else
g.DrawString(ComboBox1.Items.Item(e.Index), bFont, Brushes.Black, e.Bounds.X, e.Bounds.Y)
End If
End Sub
This example requires:
A Windows form.
A ComboBox control named ListBox1
with three items in the Items property. In this example, the three items are named "One", Two", and Three"
. The DrawMode property of ComboBox1
must be set to OwnerDrawVariable.
References to the System.Windows.Forms and System.Drawing namespaces.
.NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback:
Training
Module
Create a UI that uses data binding in .NET MAUI. - Training
Create a UI with data binding. Your UI automatically updates based on the latest data, while the data updates in response to changes in the UI.