yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Drawing.Poison;
using DPumpHydr.WinFrmUI.RLT.Enum.Poison;
using DPumpHydr.WinFrmUI.RLT.Interface.Poison;
using DPumpHydr.WinFrmUI.RLT.Manager;
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region PoisonListView
 
    public partial class PoisonListView : ListView, IPoisonControl
    {
        private ListViewColumnSorter lvwColumnSorter;
        private readonly Font stdFont = new("Segoe UI", 11f, FontStyle.Regular, GraphicsUnit.Pixel);
        private readonly float _offset = 0.2F;
 
        #region Interface
 
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public event EventHandler<PoisonPaintEventArgs> CustomPaintBackground;
        protected virtual void OnCustomPaintBackground(PoisonPaintEventArgs e)
        {
            if (GetStyle(ControlStyles.UserPaint) && CustomPaintBackground != null)
            {
                CustomPaintBackground(this, e);
            }
        }
 
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public event EventHandler<PoisonPaintEventArgs> CustomPaint;
        protected virtual void OnCustomPaint(PoisonPaintEventArgs e)
        {
            if (GetStyle(ControlStyles.UserPaint) && CustomPaint != null)
            {
                CustomPaint(this, e);
            }
        }
 
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public event EventHandler<PoisonPaintEventArgs> CustomPaintForeground;
        protected virtual void OnCustomPaintForeground(PoisonPaintEventArgs e)
        {
            if (GetStyle(ControlStyles.UserPaint) && CustomPaintForeground != null)
            {
                CustomPaintForeground(this, e);
            }
        }
 
        private ColorStyle poisonStyle = ColorStyle.Default;
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        [DefaultValue(ColorStyle.Default)]
        public ColorStyle Style
        {
            get
            {
                if (DesignMode || poisonStyle != ColorStyle.Default)
                {
                    return poisonStyle;
                }
 
                if (StyleManager != null && poisonStyle == ColorStyle.Default)
                {
                    return StyleManager.Style;
                }
 
                if (StyleManager == null && poisonStyle == ColorStyle.Default)
                {
                    return PoisonDefaults.Style;
                }
 
                return poisonStyle;
            }
            set => poisonStyle = value;
        }
 
        private ThemeStyle poisonTheme = ThemeStyle.Default;
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        [DefaultValue(ThemeStyle.Default)]
        public ThemeStyle Theme
        {
            get
            {
                if (DesignMode || poisonTheme != ThemeStyle.Default)
                {
                    return poisonTheme;
                }
 
                if (StyleManager != null && poisonTheme == ThemeStyle.Default)
                {
                    return StyleManager.Theme;
                }
 
                if (StyleManager == null && poisonTheme == ThemeStyle.Default)
                {
                    return PoisonDefaults.Theme;
                }
 
                return poisonTheme;
            }
            set => poisonTheme = value;
        }
 
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public PoisonStyleManager StyleManager { get; set; } = null;
        [DefaultValue(false)]
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public bool UseCustomBackColor { get; set; } = false;
        [DefaultValue(false)]
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public bool UseCustomForeColor { get; set; } = false;
        [DefaultValue(false)]
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public bool UseStyleColors { get; set; } = false;
 
        [Browsable(false)]
        [Category(PoisonDefaults.PropertyCategory.Behaviour)]
        [DefaultValue(false)]
        public bool UseSelectable
        {
            get => GetStyle(ControlStyles.Selectable);
            set => SetStyle(ControlStyles.Selectable, value);
        }
 
        #endregion
 
        #region Scrollbar
        [StructLayout(LayoutKind.Sequential)]
        private struct SCROLLINFO
        {
            public uint cbSize;
            public uint fMask;
            public int nMin;
            public int nMax;
            public uint nPage;
            public int nPos;
            public int nTrackPos;
        }
 
        private enum ScrollBarDirection
        {
            SB_HORZ = 0,
            SB_VERT = 1,
            SB_CTL = 2,
            SB_BOTH = 3
        }
 
        private enum ScrollInfoMask
        {
            SIF_RANGE = 0x1,
            SIF_PAGE = 0x2,
            SIF_POS = 0x4,
            SIF_DISABLENOSCROLL = 0x8,
            SIF_TRACKPOS = 0x10,
            SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
        }
 
        //fnBar values
        private enum SBTYPES
        {
            SB_HORZ = 0,
            SB_VERT = 1,
            SB_CTL = 2,
            SB_BOTH = 3
        }
        //lpsi values
        private enum LPCSCROLLINFO
        {
            SIF_RANGE = 0x0001,
            SIF_PAGE = 0x0002,
            SIF_POS = 0x0004,
            SIF_DISABLENOSCROLL = 0x0008,
            SIF_TRACKPOS = 0x0010,
            SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS
        }
 
        //ListView item information
        [StructLayoutAttribute(LayoutKind.Sequential)]
        private struct LVITEM
        {
            public uint mask;
            public int iItem;
            public int iSubItem;
            public uint state;
            public uint stateMask;
            public IntPtr pszText;
            public int cchTextMax;
            public int iImage;
            public IntPtr lParam;
        }
 
        public enum ScrollBarCommands
        {
            SB_LINEUP = 0,
            SB_LINELEFT = 0,
            SB_LINEDOWN = 1,
            SB_LINERIGHT = 1,
            SB_PAGEUP = 2,
            SB_PAGELEFT = 2,
            SB_PAGEDOWN = 3,
            SB_PAGERIGHT = 3,
            SB_THUMBPOSITION = 4,
            SB_THUMBTRACK = 5,
            SB_TOP = 6,
            SB_LEFT = 6,
            SB_BOTTOM = 7,
            SB_RIGHT = 7,
            SB_ENDSCROLL = 8
        }
 
        private const uint WM_VSCROLL = 0x0115;
        private const uint WM_NCCALCSIZE = 0x83;
 
        private const uint LVM_FIRST = 0x1000;
        private const uint LVM_INSERTITEMA = LVM_FIRST + 7;
        private const uint LVM_INSERTITEMW = LVM_FIRST + 77;
        private const uint LVM_DELETEITEM = LVM_FIRST + 8;
        private const uint LVM_DELETEALLITEMS = LVM_FIRST + 9;
 
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
 
        public delegate void ScrollPositionChangedDelegate(PoisonListView listview, int pos);
 
        public event ScrollPositionChangedDelegate ScrollPositionChanged;
        public event Action<PoisonListView> ItemAdded;
        public event Action<PoisonListView> ItemsRemoved;
 
        private int _disableChangeEvents = 0;
 
        private readonly PoisonScrollBar _vScrollbar = new();
 
        private void BeginDisableChangeEvents()
        {
            _disableChangeEvents++;
        }
 
        private void EndDisableChangeEvents()
        {
            if (_disableChangeEvents > 0)
            {
                _disableChangeEvents--;
            }
        }
 
        private void _vScrollbar_ValueChanged(object sender, int newValue)
        {
            if (_disableChangeEvents > 0)
            {
                return;
            }
 
            SetScrollPosition(_vScrollbar.Value);
        }
 
        public void GetScrollPosition(out int min, out int max, out int pos, out int smallchange, out int largechange)
        {
            SCROLLINFO scrollinfo = new()
            {
                cbSize = (uint)Marshal.SizeOf(typeof(SCROLLINFO)),
                fMask = (int)ScrollInfoMask.SIF_ALL
            };
            if (GetScrollInfo(Handle, (int)SBTYPES.SB_VERT, ref scrollinfo))
            {
                min = scrollinfo.nMin;
                max = scrollinfo.nMax;
                pos = scrollinfo.nPos + 1;
                smallchange = 1;
                largechange = (int)scrollinfo.nPage;
            }
            else
            {
                min = 0;
                max = 0;
                pos = 0;
                smallchange = 0;
                largechange = 0;
            }
        }
 
        public void UpdateScrollbar()
        {
            if (_vScrollbar != null)
            {
                GetScrollPosition(out int min, out int max, out int pos, out int smallchange, out int largechange);
 
                BeginDisableChangeEvents();
                _vScrollbar.Value = pos == 1 ? 0 : pos;
                _vScrollbar.Maximum = max;// -largechange < largechange ? largechange : max - largechange;
                _vScrollbar.Minimum = min;
                _vScrollbar.SmallChange = smallchange;
                _vScrollbar.LargeChange = largechange;
                _vScrollbar.Visible = max > largechange;
                EndDisableChangeEvents();
            }
        }
 
        public void SetScrollPosition(int pos)
        {
            pos = Math.Min(Items.Count - 1, pos);
 
            if (pos < 0 || pos >= Items.Count)
            {
                return;
            }
 
            SuspendLayout();
            EnsureVisible(pos);
 
            if (View is View.Tile or View.LargeIcon or View.SmallIcon)
            {
                return;
            }
 
            for (int i = 0; i < 10; i++)
            {
                if (TopItem != null && TopItem.Index != pos)
                {
                    TopItem = Items[pos];
                }
            }
 
            ResumeLayout();
        }
 
        protected void OnItemAdded()
        {
            if (_disableChangeEvents > 0)
            {
                return;
            }
 
            UpdateScrollbar();
 
            ItemAdded?.Invoke(this);
        }
 
        protected void OnItemsRemoved()
        {
            if (_disableChangeEvents > 0)
            {
                return;
            }
 
            UpdateScrollbar();
 
            ItemsRemoved?.Invoke(this);
        }
 
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);
 
            if (_vScrollbar != null)
            {
                _vScrollbar.Value -= 3 * Math.Sign(e.Delta);
            }
        }
 
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_VSCROLL)
            {
                GetScrollPosition(out int min, out int max, out int pos, out int smallchange, out int largechange);
 
                ScrollPositionChanged?.Invoke(this, pos);
 
                if (_vScrollbar != null)
                {
                    _vScrollbar.Value = pos;
                }
            }
            else if (m.Msg == WM_NCCALCSIZE) // WM_NCCALCSIZE
            {
                int style = GetWindowLong(Handle, GWL_STYLE);
                if ((style & WS_VSCROLL) == WS_VSCROLL)
                {
                    SetWindowLong(Handle, GWL_STYLE, style & ~WS_VSCROLL);
                }
            }
 
            else if (m.Msg is (int)LVM_INSERTITEMA or (int)LVM_INSERTITEMW)
            {
                OnItemAdded();
            }
            else if (m.Msg is (int)LVM_DELETEITEM or (int)LVM_DELETEALLITEMS)
            {
                OnItemsRemoved();
            }
 
            base.WndProc(ref m);
        }
 
        private const int GWL_STYLE = -16;
        private const int WS_VSCROLL = 0x00200000;
 
        public static int GetWindowLong(IntPtr hWnd, int nIndex)
        {
            if (IntPtr.Size == 4)
            {
                return (int)GetWindowLong32(hWnd, nIndex);
            }
            else
            {
                return (int)(long)GetWindowLongPtr64(hWnd, nIndex);
            }
        }
 
        public static int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong)
        {
            if (IntPtr.Size == 4)
            {
                return (int)SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
            }
            else
            {
                return (int)(long)SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
            }
        }
 
        [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr GetWindowLong32(IntPtr hWnd, int nIndex);
 
        [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
 
        [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, int dwNewLong);
 
        [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, int dwNewLong);
        #endregion
 
        public PoisonListView()
        {
            Font = new("Segoe UI", 12.0f);
            HideSelection = true;
 
            OwnerDraw = true;
            DrawColumnHeader += PoisonListView_DrawColumnHeader;
            DrawItem += PoisonListView_DrawItem;
            DrawSubItem += PoisonListView_DrawSubItem;
            Resize += PoisonListView_Resize;
            ColumnClick += PoisonListView_ColumnClick;
            SelectedIndexChanged += PoisonListView_SelectedIndexChanged;
            FullRowSelect = true;
            Controls.Add(_vScrollbar);
            _vScrollbar.Visible = false;
            _vScrollbar.Width = 15;
            _vScrollbar.Dock = DockStyle.Right;
            _vScrollbar.ValueChanged += _vScrollbar_ValueChanged;
 
            //DoubleBuffering(true);
        }
 
        private void PoisonListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateScrollbar();
        }
 
        private bool allowSorting = false;
        [DefaultValue(false)]
        [Category(PoisonDefaults.PropertyCategory.Behaviour)]
        public bool AllowSorting
        {
            get => allowSorting;
            set
            {
                allowSorting = value;
                if (!value)
                {
                    lvwColumnSorter = null;
                    ListViewItemSorter = null;
                }
                else
                {
                    lvwColumnSorter = new ListViewColumnSorter();
                    ListViewItemSorter = lvwColumnSorter;
                }
            }
        }
 
        private void PoisonListView_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            if (lvwColumnSorter == null)
            {
                return;
            }
 
            if (e.Column == lvwColumnSorter.SortColumn)
            {
                // Reverse the current sort direction for this column.
                if (lvwColumnSorter.Order == SortOrder.Ascending)
                {
                    lvwColumnSorter.Order = SortOrder.Descending;
                }
                else
                {
                    lvwColumnSorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                lvwColumnSorter.SortColumn = e.Column;
                lvwColumnSorter.Order = SortOrder.Ascending;
            }
 
            // Perform the sort with these new sort options.
            Sort();
        }
 
        private void PoisonListView_Resize(object sender, EventArgs e)
        {
            if (Columns.Count <= 0)
            {
                return;
            }
        }
 
        [Description("Set the font of the button caption")]
        [Browsable(false)]
        public override Font Font
        {
            get => base.Font;
            set => base.Font = value;
        }
 
        private void PoisonListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            Color itemForeColor = PoisonPaint.ForeColor.Button.Disabled(Theme);
            if (View == View.Details)
            {
 
                if (e.Item.Selected)
                {
                    e.Graphics.FillRectangle(new SolidBrush(ControlPaint.Light(PoisonPaint.GetStyleColor(Style), _offset)), e.Bounds);
                    itemForeColor = Color.White;
                }
 
                TextFormatFlags align = TextFormatFlags.Left;
 
                int _ded = 0, _left = 0;
                if (CheckBoxes && e.ColumnIndex == 0)
                {
                    _ded = 12; _left = 14;
                    int _top = (e.Bounds.Height / 2) - 6;
                    using (Pen p = new(itemForeColor))
                    {
                        Rectangle boxRect = new(e.Bounds.X + 2, e.Bounds.Y + _top, 12, 12);
                        e.Graphics.DrawRectangle(p, boxRect);
                    }
 
                    if (e.Item.Checked)
                    {
                        Color fillColor = PoisonPaint.GetStyleColor(Style);
                        if (e.Item.Selected)
                        {
                            fillColor = Color.White;
                        }
 
                        using SolidBrush b = new(fillColor);
                        _top = (e.Bounds.Height / 2) - 4;
                        Rectangle boxRect = new(e.Bounds.X + 4, e.Bounds.Y + _top, 9, 9);
                        e.Graphics.FillRectangle(b, boxRect);
                    }
                }
 
                if (SmallImageList != null)
                {
                    Image _img = null;
                    if (e.Item.ImageIndex > -1)
                    {
                        _img = SmallImageList.Images[e.Item.ImageIndex];
                    }
 
                    if (e.Item.ImageKey != "")
                    {
                        _img = SmallImageList.Images[e.Item.ImageKey];
                    }
 
                    if (_img != null)
                    {
                        _left += _left > 0 ? 4 : 2;
                        int _top = (e.Item.Bounds.Height - _img.Height) / 2;
                        e.Graphics.DrawImage(_img, new Rectangle(e.Item.Bounds.Left + _left, e.Item.Bounds.Top + _top, _img.Width, _img.Height));
 
                        _left += SmallImageList.ImageSize.Width;
                        _ded += SmallImageList.ImageSize.Width;
                    }
                }
 
                int _colWidth = e.Item.Bounds.Width;
                if (View == View.Details)
                {
                    _colWidth = Columns[e.ColumnIndex].Width;
                }
 
                using StringFormat sf = new();
                //TextFormatFlags flags = TextFormatFlags.Left;
 
                sf.Alignment = e.Header.TextAlign switch
                {
                    HorizontalAlignment.Center => StringAlignment.Center,
                    HorizontalAlignment.Right => StringAlignment.Far,
                    _ => StringAlignment.Near,
                };
                if (e.ColumnIndex > 0 && double.TryParse(e.SubItem.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, out double subItemValue))
                {
                    sf.Alignment = StringAlignment.Far;
                    //flags = TextFormatFlags.Right;
                }
 
 
                //TextFormatFlags align = TextFormatFlags.Left;
                Rectangle rect = new(e.Bounds.X + _left, e.Bounds.Y, _colWidth - _ded, e.Item.Bounds.Height);
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, stdFont, rect, itemForeColor, align | TextFormatFlags.SingleLine | TextFormatFlags.GlyphOverhangPadding | TextFormatFlags.VerticalCenter | TextFormatFlags.WordEllipsis);
            }
            else
            {
                e.DrawDefault = true;
            }
        }
 
        private void PoisonListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            Color itemForeColor = PoisonPaint.ForeColor.Button.Disabled(Theme);
            if (View == View.Details | View == View.List | View == View.SmallIcon)
            {
                Color fillColor = PoisonPaint.GetStyleColor(Style);
 
                if (e.Item.Selected)
                {
                    e.Graphics.FillRectangle(new SolidBrush(ControlPaint.Light(PoisonPaint.GetStyleColor(Style), _offset)), e.Bounds);
                    itemForeColor = Color.White;
                    fillColor = Color.White;
                }
 
                TextFormatFlags align = TextFormatFlags.Left;
 
                int _ded = 0, _left = 0;
                if (CheckBoxes)
                {
                    _ded = 12; _left = 14;
                    int _top = (e.Bounds.Height / 2) - 6;
                    using (Pen p = new(itemForeColor))
                    {
                        Rectangle boxRect = new(e.Bounds.X + 2, e.Bounds.Y + _top, 12, 12);
                        e.Graphics.DrawRectangle(p, boxRect);
                    }
 
                    if (e.Item.Checked)
                    {
                        using SolidBrush b = new(fillColor);
                        _top = (e.Bounds.Height / 2) - 4;
                        Rectangle boxRect = new(e.Bounds.X + 4, e.Bounds.Y + _top, 9, 9);
                        e.Graphics.FillRectangle(b, boxRect);
                    }
                }
 
                if (SmallImageList != null)
                {
                    int _top = 0;
                    Image _img = null;
                    if (e.Item.ImageIndex > -1)
                    {
                        _img = SmallImageList.Images[e.Item.ImageIndex];
                    }
 
                    if (e.Item.ImageKey != "")
                    {
                        _img = SmallImageList.Images[e.Item.ImageKey];
                    }
 
                    if (_img != null)
                    {
                        _left += _left > 0 ? 4 : 2;
                        _top = (e.Item.Bounds.Height - _img.Height) / 2;
                        e.Graphics.DrawImage(_img, new Rectangle(e.Item.Bounds.Left + _left, e.Item.Bounds.Top + _top, _img.Width, _img.Height));
 
                        _left += SmallImageList.ImageSize.Width;
                        _ded += SmallImageList.ImageSize.Width;
                    }
                }
 
                if (View == View.Details)
                {
                    return;
                }
 
                int _colWidth = e.Item.Bounds.Width;
                if (View == View.Details)
                {
                    _colWidth = Columns[0].Width;
                }
 
                Rectangle rect = new(e.Bounds.X + _left, e.Bounds.Y, _colWidth - _ded, e.Item.Bounds.Height);
                TextRenderer.DrawText(e.Graphics, e.Item.Text, stdFont, rect, itemForeColor, align | TextFormatFlags.SingleLine | TextFormatFlags.GlyphOverhangPadding | TextFormatFlags.VerticalCenter | TextFormatFlags.WordEllipsis);
            }
 
            else if (View == View.Tile)
            {
                int _left = 0;
 
                if (LargeImageList != null)
                {
                    int _top = 0;
                    _left = LargeImageList.ImageSize.Width + 2;
 
                    Image _img = null;
                    if (e.Item.ImageIndex > -1)
                    {
                        _img = LargeImageList.Images[e.Item.ImageIndex];
                    }
 
                    if (e.Item.ImageKey != "")
                    {
                        _img = LargeImageList.Images[e.Item.ImageKey];
                    }
 
                    if (_img != null)
                    {
                        _top = (e.Item.Bounds.Height - _img.Height) / 2;
                        e.Graphics.DrawImage(_img, new Rectangle(e.Item.Bounds.Left + _left, e.Item.Bounds.Top + _top, _img.Width, _img.Height));
                    }
                }
 
                if (e.Item.Selected)
                {
                    Rectangle rect = new(e.Item.Bounds.X + _left, e.Item.Bounds.Y, e.Item.Bounds.Width, e.Item.Bounds.Height);
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(250, 194, 87)), rect);
                }
 
                int _fill = 0;
                foreach (ListViewItem.ListViewSubItem item in e.Item.SubItems)
                {
                    if (_fill > 0 && !e.Item.Selected)
                    {
                        itemForeColor = Color.Silver;
                    }
 
                    int _y = e.Item.Bounds.Y + _fill + ((e.Item.Bounds.Height - (e.Item.SubItems.Count * 15)) / 2);
 
                    Rectangle rect = new(e.Item.Bounds.X + _left, e.Item.Bounds.Y + _fill, e.Item.Bounds.Width, e.Item.Bounds.Height);
 
                    TextFormatFlags align = TextFormatFlags.Left;
                    TextRenderer.DrawText(e.Graphics, item.Text, new Font("Segoe UI", 9.0f), rect, itemForeColor, align | TextFormatFlags.SingleLine | TextFormatFlags.GlyphOverhangPadding | TextFormatFlags.WordEllipsis);
                    _fill += 15;
                }
            }
            else
            {
                if (CheckBoxes)
                {
                    int _top = (e.Bounds.Height / 2) - 6;
                    using (Pen p = new(Color.Black))
                    {
                        Rectangle boxRect = new(e.Bounds.X + 6, e.Bounds.Y + _top, 12, 12);
                        e.Graphics.DrawRectangle(p, boxRect);
                    }
 
                    if (e.Item.Checked)
                    {
                        Color fillColor = PoisonPaint.GetStyleColor(Style);
                        if (e.Item.Selected)
                        {
                            fillColor = Color.White;
                        }
 
                        using SolidBrush b = new(fillColor);
                        _top = (e.Bounds.Height / 2) - 4;
 
                        Rectangle boxRect = new(e.Bounds.X + 8, e.Bounds.Y + _top, 9, 9);
                        e.Graphics.FillRectangle(b, boxRect);
                    }
 
                    Rectangle rect = new(e.Bounds.X + 23, e.Bounds.Y + 1, e.Bounds.Width, e.Bounds.Height);
 
                    e.Graphics.DrawString(e.Item.Text, stdFont, new SolidBrush(itemForeColor), rect);
                }
 
                Font = stdFont;
                e.DrawDefault = true;
            }
        }
 
        private void PoisonListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            Color _headColor = PoisonPaint.ForeColor.Button.Press(Theme);
            e.Graphics.FillRectangle(new SolidBrush(PoisonPaint.GetStyleColor(Style)), e.Bounds);
 
            using StringFormat sf = new();
            sf.Alignment = StringAlignment.Center;
            e.Graphics.DrawString(e.Header.Text, stdFont, new SolidBrush(_headColor), e.Bounds, sf);
        }
    }
 
    #endregion
}