private void SfListView1_DrawItem(object sender, Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
 {
     if (e.ItemType == ItemType.Record)
     {
         //Custom drawing
         this.DrawRTFText(e);
         e.Handled = true;
     }
 }
예제 #2
0
        private void sfListView1_DrawItem(object sender, Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
        {
            var action = actionsDataSource.Find(x => x.ActionName.Equals(e.Text)) ?? new ActionInfo();

            if (!String.IsNullOrEmpty(action.Image))
            {
                e.Image = Image.FromFile(action.Image);
            }
            e.ImageAlignment = ContentAlignment.BottomLeft;
        }
예제 #3
0
        private void DropDownListView_DrawItem(object sender, Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
        {
            bool isItemEnable = (this.sfComboBox.ComboBoxMode == ComboBoxMode.MultiSelection && this.sfComboBox.AllowSelectAll && e.ItemIndex == 0) ? true : (e.ItemData as Details).IsEnabled;

            if (!isItemEnable)
            {
                e.Style.BackColor = Color.LightGray;
                e.Style.ForeColor = Color.Gray;
            }
        }
예제 #4
0
        /// <summary>
        /// Occurs when draws the items in SfListView.
        /// </summary>
        private void OnSfListViewDrawItem(object sender, Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
        {
            if (e.ItemType == Syncfusion.WinForms.ListView.Enums.ItemType.Header)
            {
                e.Text = "List of US States";
            }

            if (e.ItemType == Syncfusion.WinForms.ListView.Enums.ItemType.Footer)
            {
                e.Text = "Filtered Items Count : " + this.sfListView1.View.Items.Count;
            }
        }
        private void DropDownListView_DrawItem(object sender, Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
        {
            bool isEnableDraw = (this.sfComboBox1.ComboBoxMode == ComboBoxMode.MultiSelection && this.sfComboBox1.AllowSelectAll && this.sfComboBox1.DropDownListView.ShowCheckBoxes && e.ItemIndex == 0) ? false : (e.ItemData as Student).IsDraWSeparator;

            if (isEnableDraw)
            {
                e.Handled = true;
                var listView      = sender as SfListView;
                var linearLayout  = listView.GetType().GetProperty("LinearLayout", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(listView);
                var items         = linearLayout.GetType().GetProperty("Items").GetValue(linearLayout) as List <ListViewItemInfo>;
                var checkBoxStyle = items[e.ItemIndex].GetType().GetProperty("CheckBoxStyle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                checkBoxStyle.SetValue(items[e.ItemIndex], listView.Style.CheckBoxStyle);
                //Fill the background color of mouse hover item.
                if (e.ItemIndex == mouseHoverItemIndex)
                {
                    e.Graphics.FillRectangle(new SolidBrush(listView.Style.SelectionStyle.HoverBackColor), e.Bounds);
                }
                //Fill the background color of Selecteditem.
                if (sfComboBox1.SelectedIndex == e.ItemIndex)
                {
                    e.Graphics.FillRectangle(new SolidBrush(listView.Style.SelectionStyle.SelectionBackColor), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 2));
                }
                RectangleF bounds = new RectangleF(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height);
                //Draw the checkbox if MultiSelction and showcheckboxes are enabled.
                if (sfComboBox1.ComboBoxMode == ComboBoxMode.MultiSelection && this.sfComboBox1.DropDownListView.ShowCheckBoxes)
                {
                    CheckBoxPainter.DrawCheckBox(e.Graphics, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2), listView.CheckedItems.Contains(e.ItemData) ? CheckState.Checked : CheckState.Unchecked, listView.Style.CheckBoxStyle);
                    bounds = new RectangleF(e.Bounds.X + 20, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2);
                }
                //Draw the listview item text.
                e.Graphics.DrawString((e.ItemData as Student).StudentName, this.Font, new SolidBrush(Color.FromArgb(255, 51, 51, 51)), bounds);
                //Draw the separator line.
                e.Graphics.DrawLine(new Pen(Color.Gray, width: 1)
                {
                    DashPattern = new[] { 2f, 2f }
                }, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
            }
        }
        void DrawRTFText(Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
        {
            var    item          = e.ItemData as RTFText;
            var    split_text    = item.Text.Split(new String[] { "\r\n" }, StringSplitOptions.None);
            var    microSoft_10B = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold);
            var    microSoft_10  = new Font("Microsoft Sans Serif", 8f, FontStyle.Regular);
            var    microSoft_8   = new Font("Microsoft Sans Serif", 8f, FontStyle.Regular);
            var    microSoft_7   = new Font("Microsoft Sans Serif", 8f, FontStyle.Regular);
            Image  favorite1     = Image.FromFile(@"..\..\Images\Favorites.png");
            Image  favorite2     = Image.FromFile(@"..\..\Images\Favorites1.png");
            Bitmap bmp1          = new Bitmap(favorite2, new Size(40, 40));
            Bitmap bmp2          = new Bitmap(favorite1, new Size(40, 40));
            var    richTexts     = new RichText[] {
                new RichText(split_text[0], microSoft_10B),
                new RichText(split_text[1], microSoft_10),
                new RichText(split_text[2], microSoft_8),
            };
            Point      textPosition = new Point(e.Bounds.Location.X, e.Bounds.Y);
            RectangleF rectf        = e.Bounds;// new RectangleF(e.Bounds.Location.X + bmp1.Width, e.Bounds.Y, e.Bounds.Width - 17, e.Bounds.Height);
            int        maxWidth     = e.Bounds.Width;

            foreach (var richText in richTexts)
            {
                var text = richText.Text;
                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }

                var font = richText.Font ?? Control.DefaultFont;
                //var textColor = Array.IndexOf(richTexts, richText) == 0 ? Color.Black : style.ForeColor;//Color.Black;//richText.TextColor ?? Control.DefaultForeColor;
                var textColor = e.Style.ForeColor;
                using (var brush = new SolidBrush(textColor))
                {
                    var rslt_Measure = e.Graphics.MeasureString(text, font, (int)rectf.Width);
                    e.Graphics.DrawString(text, font, brush, rectf);
                    var newRectF = rectf;
                    rectf.Y += (int)rslt_Measure.Height + 4;
                }
            }
            var date_Measure = e.Graphics.MeasureString(split_text[3], microSoft_7, e.Bounds.Width);

            e.Graphics.DrawString(split_text[3], microSoft_7, new SolidBrush(e.Style.ForeColor), new PointF(e.Bounds.Width - date_Measure.Width, e.Bounds.Y));
            //To avoid the border getting drawn top of the item.
            if (e.Bounds.Y == 0)
            {
                if (item.Read)
                {
                    e.Graphics.DrawImage(bmp2, new PointF(rectf.Right - date_Measure.Width, e.Bounds.Y + e.Bounds.Height - bmp2.Height - 2));
                }
                else
                {
                    e.Graphics.DrawImage(bmp1, new PointF(rectf.Right - date_Measure.Width, e.Bounds.Y + e.Bounds.Height - bmp1.Height - 2));
                }
            }
            else
            {
                e.Graphics.DrawLine(new Pen(e.Style.ForeColor), textPosition, new Point(e.Bounds.Width, textPosition.Y));
                if (item.Read)
                {
                    e.Graphics.DrawImage(bmp2, new PointF(rectf.Right - date_Measure.Width, e.Bounds.Y + e.Bounds.Height - bmp2.Height - 2));
                }
                else
                {
                    e.Graphics.DrawImage(bmp1, new PointF(rectf.Right - date_Measure.Width, e.Bounds.Y + e.Bounds.Height - bmp1.Height - 2));
                }
            }
        }