![xojo custom listbox xojo custom listbox](https://ifnotnil.com/uploads/default/original/1X/89487830b38a1ac053a7b26800cc3b0d71f380a7.png)
State = isChecked ? RadioButtonState.CheckedDisabled :Įlse if ((e.State & DrawItemState.Grayed) = DrawItemState.Grayed) If ((e.State & DrawItemState.Disabled) = DrawItemState.Disabled) RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal e.Bounds.Top Į.Graphics.FillRectangle(BackBrush, backRect) īool isChecked = (e.State & DrawItemState.Selected) = DrawItemState.Selected Int size = e.Font.Height // button size depends on font height, not on item height // Calculate bounds for background, if last item paint up to bottom of controlīackRect.Height = + Erase all background if control has no itemsĮ.Graphics.FillRectangle(BackBrush, this.ClientRectangle)
Xojo custom listbox code#
Here is the C# source code:Ĭopy Code // Main painting method protected override void OnDrawItem(DrawItemEventArgs e) It also manages the focus state to draw the focus rectangle properly and the background color according to the transparency attribute. The method does not highlight the selected item as in a standard ListBox control, but draws a radio button instead. The core enhancement is at the OnDrawItem() method. Protected override void OnParentBackColorChanged(EventArgs e). Protected override void OnParentChanged(EventArgs e). Protected override void OnFontChanged(EventArgs e). Other event handlers protected override void OnHandleCreated(EventArgs e). Prevent background erasing protected override void DefWndProc( ref Message m). Main painting method protected override void OnDrawItem(DrawItemEventArgs e). Public constructor public RadioListBox(). Public override SelectionMode SelectionMode. Hides these properties in the designer Private bool IsTransparent = false // Handles the transparent state private Brush BackBrush // Manages its own background brush // Allows the BackColor to be transparent public override Color BackColor. The resumed class definition is the following:
Xojo custom listbox windows#
The RadioListBox class is derived from Windows Forms' ListBox class with the owner-draw feature.
![xojo custom listbox xojo custom listbox](https://mma.prnewswire.com/media/1244383/Xojo_Screen_Shot_1.jpg)
When setting the background color to transparent, the control will mimic the parent form or control, even if the form has a non-standard background color. I decided to stay in the managed world by providing fake transparency to the control by overriding the BackColor property to accept it, and saving its own background color brush. It allows the control to acquire a real radio button look and feel, as you can see in the screenshot above. However, transparency is a key feature needed for this control to be useful. So, transparency requires lots of non-managed tricks. NET controls accept a transparent color as a BackColor property, but ListBox is not one of them. You can add items with the Items.Add() method and query for user selection with the SelectedIndex property. That's all! Now you can use the radio button collection as a regular ListBox.
![xojo custom listbox xojo custom listbox](https://ifnotnil.com/uploads/default/optimized/1X/caca27ff025d9d2349d44b80cdf07afb50980fdd_2_264x375.png)
Countersense to standard ListBox, transparent BackColor property is allowed.Change the standard properties of the control, just like a ListBox.Drop a RadioListBox object into your form.Include RadioListBox.cs into your project.To implement RadioListBox into your project, you just need to do a few steps: It will be easier to manage selection events, also shown in the demo application.It will be easier to change options dynamically, as shown in the demo application.It inherits some useful features like scrolling, sorting, data binding and multi-column.It is a good alternative to a group of radio buttons because you have to maintain just one control, less memory use.
![xojo custom listbox xojo custom listbox](https://www.pidog.com/wp/wp-content/uploads/2019/02/Screen-Shot-2019-01-23-at-11.25.41-AM-e1549051257384-300x147.png)
Xojo custom listbox download#