示例#1
0
        private void notesListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index != -1)
            {
                Note note = notesListBox.Items[e.Index] as Note;

                Brush darkBrush   = new SolidBrush(ColorManager.GetDarkColor(note.colorStr));
                Brush middleBrush = new SolidBrush(ColorManager.GetMiddleColor(note.colorStr));
                Brush noteBrush   = new SolidBrush(ColorManager.GetNoteColor(note.colorStr));
                Brush backBrush   = new SolidBrush(notesListBox.BackColor);

                e.Graphics.FillRectangle(darkBrush, new RectangleF(
                                             e.Bounds.X + 9,
                                             e.Bounds.Y + 9,
                                             e.Bounds.Width - 18,
                                             8
                                             ));
                e.Graphics.FillRectangle(noteBrush, new RectangleF(
                                             e.Bounds.X + 9,
                                             e.Bounds.Y + 17,
                                             e.Bounds.Width - 18,
                                             e.Bounds.Height - 17
                                             ));

                if (note.title.Length > 100)
                {
                    e.Graphics.DrawString(note.title.Substring(0, 100), e.Font, darkBrush, e.Bounds.X + 16, e.Bounds.Y + 21);
                }
                else
                {
                    e.Graphics.DrawString(note.title, e.Font, darkBrush, e.Bounds.X + 16, e.Bounds.Y + 21);
                }

                if (note.contentText.Length > 100)
                {
                    e.Graphics.DrawString(Regex.Replace(note.contentText.Substring(0, 100), @"\t|\n|\r", " "), e.Font, middleBrush, e.Bounds.X + 16, e.Bounds.Y + 39);
                }
                else
                {
                    e.Graphics.DrawString(Regex.Replace(note.contentText, @"\t|\n|\r", " "), e.Font, middleBrush, e.Bounds.X + 16, e.Bounds.Y + 39);
                }

                e.Graphics.FillRectangle(backBrush, new RectangleF(
                                             e.Bounds.X + e.Bounds.Width - 9,
                                             e.Bounds.Y,
                                             9,
                                             e.Bounds.Height
                                             ));

                // right side gradient
                var rc = new Rectangle(
                    e.Bounds.X + e.Bounds.Width - 39,
                    e.Bounds.Y + 17,
                    20,
                    e.Bounds.Height - 17
                    );
                using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(
                           rc,
                           Color.FromArgb(0, ColorManager.GetNoteColor(note.colorStr)),
                           Color.FromArgb(255, ColorManager.GetNoteColor(note.colorStr)),
                           0f
                           ))
                {
                    e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                    e.Graphics.FillRectangle(brush, rc);
                }

                e.Graphics.FillRectangle(noteBrush, new RectangleF(
                                             e.Bounds.X + e.Bounds.Width - 21,
                                             e.Bounds.Y + 17,
                                             12,
                                             e.Bounds.Height - 17
                                             ));

                // bottom right corner
                if (note.visible)
                {
                    PointF[] outerNoteTriangle =
                    {
                        new PointF(e.Bounds.X + e.Bounds.Width - 9,  e.Bounds.Y + e.Bounds.Height - 12),
                        new PointF(e.Bounds.X + e.Bounds.Width - 21, e.Bounds.Y + e.Bounds.Height),
                        new PointF(e.Bounds.X + e.Bounds.Width - 9,  e.Bounds.Y + e.Bounds.Height)
                    };
                    e.Graphics.FillPolygon(backBrush, outerNoteTriangle);

                    PointF[] innerNoteTriangle =
                    {
                        new PointF(e.Bounds.X + e.Bounds.Width - 9,  e.Bounds.Y + e.Bounds.Height - 12),
                        new PointF(e.Bounds.X + e.Bounds.Width - 21, e.Bounds.Y + e.Bounds.Height),
                        new PointF(e.Bounds.X + e.Bounds.Width - 21, e.Bounds.Y + e.Bounds.Height - 12)
                    };
                    e.Graphics.FillPolygon(middleBrush, innerNoteTriangle);
                }
            }
        }