HomeActive Query Builder - HowTos and TroubleshootingUser Interface CustomizationHow to implement custom drawing of the fields inside datasources?

1.3. How to implement custom drawing of the fields inside datasources?

The following code displays field description if it's not empty; otherwise it displays field name.

void queryBuilder1_FieldListDrawItem(Graphics g, Rectangle rect, DrawItemState state, MetadataField field, ref bool handled)
{
       Brush bgBrush;
       Color textColor;
       String s = String.Empty;

       if ((state & DrawItemState.Selected) == DrawItemState.Selected)
       {
               bgBrush = SystemBrushes.Highlight;
               textColor = SystemColors.HighlightText;
       }
       else
       {
               bgBrush = new SolidBrush(Color.LightYellow);
               textColor = Color.MediumSeaGreen;
       }

       rect.X -= rect.Height;
       rect.Width += rect.Height;

       g.FillRectangle(bgBrush, rect);

       if (field != null)
       {
               if (!String.IsNullOrEmpty(field.AltName) && queryBuilder1.UseAltNames)
               {
                       s = field.AltName;
               }
               else
               {
                       s = field.Name.QualifiedNameWithoutQuotes;
               }
       }
       else
       {
               s = "*";
       }

       TextRenderer.DrawText(g, s, new Font("Arial", 8, FontStyle.Bold), rect.Location, textColor);

       if ((state & DrawItemState.Focus) == DrawItemState.Focus)
       {
               ControlPaint.DrawFocusRectangle(g, rect);
       }
       handled = true;
}

This page was: Helpful | Not Helpful