Пример #1
0
        private void lbxResults_DrawItem(object sender, DrawItemEventArgs e)
        {
            Noun lemma = (Noun)lbxResults.Items[e.Index];

            e.DrawBackground();
            Graphics g = e.Graphics;
            Color    bgColor;

            switch (lemma.Gender)
            {
            case Noun.NounGender.Mannlich: bgColor = Color.SkyBlue; break;

            case Noun.NounGender.Weiblich: bgColor = Color.Pink; break;

            case Noun.NounGender.Neutrum: bgColor = Color.Gold; break;

            default: bgColor = Color.LightGoldenrodYellow; break;
            }
            g.FillRectangle(new SolidBrush(bgColor), e.Bounds);

            float scaleFactor     = FindFontScaleHor(g, string.Format("{0} ({1})", lemma.Word, NounGenderConvert.ToString(lemma.Gender)), defaultHeaderFont, e.Bounds.Width);
            Font  lemmaHeaderFont = new Font(headerFontFamily, 25 * scaleFactor, FontStyle.Bold, GraphicsUnit.Pixel);
            Font  lemmaGenderFont = new Font(headerFontFamily, 15 * scaleFactor, FontStyle.Italic, GraphicsUnit.Pixel);

            int       headerHeight = GetFontLineHeight(lemmaHeaderFont);
            Rectangle lemmaRect    = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, headerHeight);

            lemmaRect.Width = Convert.ToInt32(Math.Ceiling(g.MeasureString(lemma.Word, lemmaHeaderFont).Width));
            g.DrawString(lemma.Word, lemmaHeaderFont, Brushes.LightSlateGray, lemmaRect);

            int       genderOffset = GetFontAscent(lemmaHeaderFont) - GetFontAscent(lemmaGenderFont);
            int       genderHeight = GetFontLineHeight(lemmaGenderFont);
            Rectangle genderRect   = new Rectangle(lemmaRect.Width, e.Bounds.Y + genderOffset, e.Bounds.Width - lemmaRect.Width, genderHeight);

            g.DrawString(string.Format("({0})", NounGenderConvert.ToString(lemma.Gender)), lemmaGenderFont, Brushes.LightSlateGray, genderRect);

            e.DrawFocusRectangle();
        }
Пример #2
0
        private void lbxResults_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            Noun lemma = (Noun)lbxResults.Items[e.Index];

            float scaleFactor     = FindFontScaleHor(e.Graphics, string.Format("{0} ({1})", lemma.Word, NounGenderConvert.ToString(lemma.Gender)), defaultHeaderFont, lbxResults.Width);
            Font  lemmaHeaderFont = new Font(headerFontFamily, 25 * scaleFactor, FontStyle.Bold, GraphicsUnit.Pixel);
            Font  lemmaGenderFont = new Font(headerFontFamily, 15 * scaleFactor, FontStyle.Italic, GraphicsUnit.Pixel);

            e.ItemHeight = Convert.ToInt32(GetFontLineHeight(lemmaHeaderFont) * 1.15);
        }