listbox
の現在使用可能な項目をすべて太字に設定しようとしています。そして、後でアイテムが追加されると、それらはデフォルトフォントを持ちます。ユーザーは最初にリストされたアイテムと新しいアイテムを視覚的に見ることができます。リストボックスの項目を(太字で)設定してください。太字のフォント
フォームコンストラクタから、私はこのようなリストボックスを埋めます。これらは、追加される初期値です。
Private Sub FillLinkedBox(ByVal oReferenceList As String())
' Fill the linked listbox with the current linked items
Debug.Print(oReferenceList.ToString)
lbLinkedParameters.Items.AddRange(oReferenceList)
' Set the font of all the existing items in the listbox
For i As Integer = 0 To lbLinkedParameters.Items.Count - 1
' Set the font to bold for these items.
Next
End Sub
ので、私は初期値とするものではなかったものを確定することができます(私はまた、メモリ内のリストを保持し、アイテムをかどうかを確認できを処理する際、ユーザーは、私はまた、アイテムのフォントをテストしたい終了した後フォントチェックが適切なオプションでない場合はリストされます)。
見つかった場合はpostこの操作を行う必要があるものの、イベントに基づいています。私はそれがどのように機能するのか分かりません。
Dim buttonPressed As Boolean
Private Sub ListBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground()
If ListBox1.SelectedIndices.Contains(e.Index) And buttonPressed Then
e.Graphics.DrawString(ListBox1.Items(e.Index), e.Font, Brushes.Green, e.Bounds.X, e.Bounds.Y)
Else
e.Graphics.DrawString(ListBox1.Items(e.Index), e.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y)
End If
If e.Index = ListBox1.Items.Count - 1 Then
buttonPressed = False
End If
e.DrawFocusRectangle()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
buttonPressed = True
ListBox1.Refresh()
End Sub
私の質問は、どのようにして指定されたインデックスのリストボックスアイテムのフォントを変更できますか?
は代わりのDataGridViewを使用してみてください。行とセルをフォーマットする方が簡単です –
Trueですが、比較的難易度の低い 'ListBox'を使って行えます。 – user7777777