Beispiel #1
0
        /// <summary>
        /// Owner draw the list items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox21_DrawItem(object sender, OpenNETCF.Windows.Forms.DrawItemEventArgs e)
        {
            ////Draw the background
            //e.DrawBackground();
            ////Draw the focus rectangle
            //e.DrawFocusRectangle();

            e.Graphics.Clip = new Region(e.Bounds);
            //Draw the data
            if (e.Index <= this.listBox21.Items.Count - 1)
            {
                VoiceNote.VoiceNoteRow row = ((VoiceListItem)this.listBox21.Items[e.Index]).VoiceRow;
                if (row != null)
                {
                    using (Brush b = new SolidBrush(e.State == DrawItemState.Selected ? SystemColors.ActiveCaptionText : e.ForeColor))
                    {
                        //get the length of the data
                        string length = this.GetVoiceNoteLength(row.Data);
                        SizeF  size   = e.Graphics.MeasureString(length, e.Font);
                        int    y      = (e.Bounds.Height / 2 - (int)size.Height / 2) + e.Bounds.Top;

                        //Draw the date
                        e.Graphics.DrawString(this.GetDate(row.Date), e.Font, b, 2, y);

                        //Draw the length
                        e.Graphics.DrawString(length, e.Font, b, e.Bounds.Right - (int)size.Width - 2, y);
                    }
                }
            }
            e.Graphics.ResetClip();
        }
Beispiel #2
0
        protected override void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            if (this.DrawMode == DrawMode.Normal)
            {
                Brush         textBrush; //Brush for the text
                SmartListItem item;

                Rectangle rc      = e.Bounds;
                int       autoNum = (int)rc.Y / rc.Height + 1;

                //int autoNum = e.Index + 1;

                rc.X += DRAW_OFFSET;

                //Get the SmartListItem
                if ((e.Index > -1) && (e.Index < itemList.Count))
                {
                    item = (SmartListItem)itemList[e.Index];
                }
                else
                {
                    return;
                }


                //Check if the item is selected
                if (e.State == DrawItemState.Selected)
                {
                    //Highlighted
                    e.DrawBackground();
                    textBrush = new SolidBrush(SystemColors.HighlightText);
                }
                else
                {
                    if (this.BackgroundImage != null) // don't do background if there is back image
                    {
                        Rectangle rcImage = Rectangle.Empty;
                        if (showLines)
                        {
                            rcImage = new Rectangle(0, rc.Y + 1, this.Width, rc.Height - 1);
                        }
                        else
                        {
                            rcImage = new Rectangle(0, rc.Y, this.Width, rc.Height);
                        }

                        e.Graphics.DrawImage(BackgroundImage, 1, rc.Y + 1, rcImage, GraphicsUnit.Pixel);
                    }
                    else
                    {
                        //Change the background for every even item
                        if ((e.Index % 2) == 0)
                        {
                            e.DrawBackground(colorEvenItem);
                        }
                        else
                        {
                            e.DrawBackground(this.BackColor);
                        }
                    }

                    textBrush = new SolidBrush(item.ForeColor);
                }

                int   numberShift = 0;
                SizeF numSize     = SizeF.Empty;

                if (autoNumbering)
                {
                    numSize     = e.Graphics.MeasureString("22", item.Font);
                    numberShift = (int)numSize.Width + 4;
                }

                // Check if the item has a image
                if ((item.ImageIndex > -1) && (imageList != null))
                {
                    Image img = imageList.Images[item.ImageIndex];
                    if (img != null)
                    {
                        imageAttr = new ImageAttributes();
                        //Set the transparency key
                        imageAttr.SetColorKey(BackgroundImageColor(img), BackgroundImageColor(img));
                        //Image's rectangle
                        Rectangle imgRect = Rectangle.Empty;

                        imgRect = new Rectangle(2 + numberShift, rc.Y + 2, img.Width, img.Height);
                        //Draw the image
                        e.Graphics.DrawImage(img, imgRect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttr);
                        //Shift the text to the right
                        rc.X += img.Width + 2;
                    }
                }
                //

                if (autoNumbering)
                {
                    e.Graphics.DrawString(autoNum.ToString(), item.Font, textBrush, 6, rc.Top + (rc.Height - (int)numSize.Height) / 2);
                    rc.X += numberShift;
                }
                //Draw item's text
                if (wrapText)
                {
                    e.Graphics.DrawString(item.Text, item.Font, textBrush, rc);
                }
                else
                {
                    //center the text vertically
                    SizeF     size   = e.Graphics.MeasureString(item.Text, item.Font);
                    Rectangle rcText = Rectangle.Empty;


                    rcText = new Rectangle(rc.X, rc.Y + (rc.Height - (int)size.Height) / 2, rc.Width - rc.X - 3, (int)size.Height);

                    string itemText = ShortString(item, e, rcText.Width);


                    if (selected > 0)
                    {
                        DrawTextSelected(e.Graphics, item, itemText, textBrush, 0, selected, rcText, e.State);
                    }
                    else
                    {
                        e.Graphics.DrawString(itemText, item.Font, textBrush, rcText);
                    }
                }

                //Draw the line
                if (showLines)
                {
                    e.Graphics.DrawLine(penLine, 0, e.Bounds.Bottom, e.Bounds.Width, e.Bounds.Bottom);
                }

                textBrush.Dispose();
            }
            else
            {
                //Call the base's OnDrawEvent
                base.OnDrawItem(sender, e);
            }
        }