Click here to Skip to main content
15,919,749 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reading & Modifying XML Data in C# Pin
GrgBalden27-Apr-10 23:33
GrgBalden27-Apr-10 23:33 
GeneralRe: Reading & Modifying XML Data in C# [modified] Pin
Dan Mos28-Apr-10 3:24
Dan Mos28-Apr-10 3:24 
GeneralRe: Reading & Modifying XML Data in C# Pin
GrgBalden28-Apr-10 4:43
GrgBalden28-Apr-10 4:43 
GeneralRe: Reading & Modifying XML Data in C# Pin
Dan Mos28-Apr-10 8:02
Dan Mos28-Apr-10 8:02 
GeneralRe: Reading & Modifying XML Data in C# Pin
GrgBalden28-Apr-10 10:44
GrgBalden28-Apr-10 10:44 
QuestionCheckbox on the ColumnHeader [modified] Pin
Natural_Demon27-Apr-10 4:55
Natural_Demon27-Apr-10 4:55 
AnswerRe: Checkbox on the ColumnHeader [modified] Pin
Natural_Demon27-Apr-10 5:39
Natural_Demon27-Apr-10 5:39 
AnswerRe: Checkbox on the ColumnHeader Pin
Natural_Demon27-Apr-10 9:12
Natural_Demon27-Apr-10 9:12 
this is the entire code to create a listview with a checkbox in the left upper corner of the ListView.
NM_CUSTOMDRAW seams to be the message when the mouse hover over the headers.
but i fail to keep the checkBox visible / ontop @ all time.
if you slightly hoover of the first header, the headers mousehover effect draws over the check.
anyone an idea how to prevent this?


using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Listview_Colum_header_checkbox
{
    class CCehckBox2 : CheckBox
    {
        public CCehckBox2()
        {
            Width = 14;
            Height = 14;
        }
    }

    class CustomChechBox2 : Control
    {
        readonly CCehckBox2 _chb = new CCehckBox2();
        public CustomChechBox2()
        {
            Size = new Size(16, 16);
            _chb.Location = new Point(0, 0);
            Controls.Add(_chb);
        }
    }

    class CListview2 : ListView
    {
        public delegate void MessageNeedsSendingCallback(string message, Color color);
        public event MessageNeedsSendingCallback OnMessageNeedsSending;


        //private readonly CCehckBox _cCehckBox = new CCehckBox();
        private readonly CustomChechBox2 _cCehckBox = new CustomChechBox2();
 
        private readonly ColumnHeader _header1, _header2, _header3 = new ColumnHeader();
        #region  PInvoke Declarations

        [DllImport("User32", CallingConvention = CallingConvention.Cdecl)]
        private static extern uint RealGetWindowClass(IntPtr hwnd, System.Text.StringBuilder pszType, int cchType);

        [DllImport("user32")]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll")]
        private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

        #endregion

        public CListview2()
        {
            View = View.Details;
            //this.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            //_header1.
            _header1 = Columns.Add("");
            _header1.Width = (Location.X + 5) + 12;
            //_header1.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            _header1.Name = "CheckBox";
            _header1.DisplayIndex = 0;

            _header2 = Columns.Add("bah");
            _header2.Width = 50;

            _header3 = Columns.Add("boh");
            _header3.Width = 50;

            var wijd = _cCehckBox.Width;
            var hoog = _cCehckBox.Height;
            _cCehckBox.Location = new Point((Location.X + 5), (Location.Y + 5));
        }
        protected override void OnHandleCreated(EventArgs e)
        {
            SetParent(_cCehckBox.Handle, Handle);
            base.OnHandleCreated(e);
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct NMHDR
        {
            public IntPtr hwndFrom;
            public int idFrom;
            public int code;
            public int coder;
        } //NMHDR

        private const int WM_NOTIFY = 0x4E;
        private const int CCM_FIRST = 8192; //				# Common control shared messages
        private const int CCM_SETBKCOLOR = (CCM_FIRST + 1);//		# lParam is bkColor
        private const int CCM_SETCOLORSCHEME = (CCM_FIRST + 2);//	# lParam is color scheme
        private const int CCM_GETCOLORSCHEME = (CCM_FIRST + 3);//	# fills in COLORSCHEME pointed to by lParam
        private const int CCM_GETDROPTARGET = (CCM_FIRST + 4);//
        private const int CCM_SETUNICODEFORMAT = (CCM_FIRST + 5);//
        private const int CCM_GETUNICODEFORMAT = (CCM_FIRST + 6);//

        private const int HDN_FIRST = (0 - 300);
        private const int HDM_FIRST = 4608;
        private const int HDM_HITTEST = (HDM_FIRST + 6);
        private const int HDM_GETITEMRECT = (HDM_FIRST + 7);
        private const int HDM_SETIMAGELIST = (HDM_FIRST + 8);
        private const int HDM_GETIMAGELIST = (HDM_FIRST + 9);
        private const int HDM_ORDERTOINDEX = (HDM_FIRST + 15);
        private const int HDM_CREATEDRAGIMAGE = (HDM_FIRST + 16); // # wparam = which item (by index)
        private const int HDM_GETORDERARRAY = (HDM_FIRST + 17);
        private const int HDM_SETORDERARRAY = (HDM_FIRST + 18);
        private const int HDM_SETHOTDIVIDER = (HDM_FIRST + 19);
        private const int HDM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT;
        private const int HDM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT;
        private const int HDN_ITEMCHANGINGA = (HDN_FIRST - 0);
        private const int HDN_ITEMCHANGINGW = (HDN_FIRST - 20);
        private const int HDN_ITEMCHANGEDA = (HDN_FIRST - 1);
        private const int HDN_ITEMCHANGEDW = (HDN_FIRST - 21);
        private const int HDN_ITEMCLICKA = (HDN_FIRST - 2);
        private const int HDN_ITEMCLICKW = (HDN_FIRST - 22);
        private const int HDN_ITEMDBLCLICKA = (HDN_FIRST - 3);
        private const int HDN_ITEMDBLCLICKW = (HDN_FIRST - 23);
        private const int HDN_DIVIDERDBLCLICKA = (HDN_FIRST - 5);
        private const int HDN_DIVIDERDBLCLICKW = (HDN_FIRST - 25);
        private const int HDN_BEGINTRACKA = (HDN_FIRST - 6);
        private const int HDN_BEGINTRACKW = (HDN_FIRST - 26);
        private const int HDN_ENDTRACKA = (HDN_FIRST - 7);
        private const int HDN_ENDTRACKW = (HDN_FIRST - 27);
        private const int HDN_TRACKA = (HDN_FIRST - 8);
        private const int HDN_TRACKW = (HDN_FIRST - 28);
        private const int HDN_GETDISPINFOA = (HDN_FIRST - 9);
        private const int HDN_GETDISPINFOW = (HDN_FIRST - 29);
        private const int HDN_BEGINDRAG = (HDN_FIRST - 10);
        private const int HDN_ENDDRAG = (HDN_FIRST - 11);
        private const int HDN_ITEMCHANGING = HDN_ITEMCHANGINGA;
        private const int HDN_ITEMCHANGED = HDN_ITEMCHANGEDA;
        private const int HDN_ITEMCLICK = HDN_ITEMCLICKA;
        private const int HDN_ITEMDBLCLICK = HDN_ITEMDBLCLICKA;
        private const int HDN_DIVIDERDBLCLICK = HDN_DIVIDERDBLCLICKA;
        private const int HDN_BEGINTRACK = HDN_BEGINTRACKA;
        private const int HDN_ENDTRACK = HDN_ENDTRACKA;
        private const int HDN_TRACK = HDN_TRACKA;
        private const int HDN_GETDISPINFO = HDN_GETDISPINFOA;

        private const int NM_FIRST = 0;
        private const int NM_OUTOFMEMORY = (NM_FIRST - 1);
        private const int NM_CLICK = (NM_FIRST - 2);//# uses NMCLICK struct
        private const int NM_DBLCLK = (NM_FIRST - 3);
        private const int NM_RETURN = (NM_FIRST - 4);
        private const int NM_RCLICK = (NM_FIRST - 5);//# uses NMCLICK struct
        private const int NM_RDBLCLK = (NM_FIRST - 6);
        private const int NM_SETFOCUS = (NM_FIRST - 7);
        private const int NM_KILLFOCUS = (NM_FIRST - 8);
        private const int NM_CUSTOMDRAW = (NM_FIRST - 12);
        private const int NM_HOVER = (NM_FIRST - 13);
        private const int NM_NCHITTEST = (NM_FIRST - 14);//# uses NMMOUSE struct
        private const int NM_KEYDOWN = (NM_FIRST - 15);//# uses NMKEY struct
        private const int NM_RELEASEDCAPTURE = (NM_FIRST - 16);
        private const int NM_SETCURSOR = (NM_FIRST - 17);//# uses NMMOUSE struct
        private const int NM_CHAR = (NM_FIRST - 18);

        protected override void WndProc(ref Message message)
        {
            bool callBase = true;

            switch (message.Msg)
            {
                case WM_NOTIFY:

                    NMHDR nmhdr = (NMHDR)message.GetLParam(typeof(NMHDR));
                    OnMessageNeedsSending("code: " + nmhdr.code + ", hwndFrom: " + nmhdr.hwndFrom + ", idFrom: " + nmhdr.idFrom + ", coder: " + nmhdr.coder, Color.Black);
                    switch (nmhdr.coder)
                    {
                        case HDN_BEGINTRACKA:  //Process both ANSI and
                            OnMessageNeedsSending("HDN_BEGINTRACKA " + message, Color.Black);
                            break;
                        case HDN_BEGINTRACKW:  //UNICODE versions of the message.
                            OnMessageNeedsSending("HDN_BEGINTRACKW " + message, Color.Black);
                            break;
                        case HDN_ENDTRACKW:
                            OnMessageNeedsSending("HDN_ENDTRACKW " + message, Color.Black);
                            break;
                        case HDN_ITEMCLICKA:
                            OnMessageNeedsSending("HDN_ITEMCLICKA " + message, Color.Black);
                            break;
                        case HDN_ITEMDBLCLICKW:
                            OnMessageNeedsSending("HDN_ITEMDBLCLICKW " + message, Color.Black);
                            break;
                        case HDN_ITEMCLICKW:
                            OnMessageNeedsSending("HDN_ITEMCLICKW " + message, Color.Black);
                            break;
                        case HDN_ITEMCHANGINGW:
                            OnMessageNeedsSending("HDN_ITEMCHANGINGW " + message, Color.Black);
                            break;
                        case HDN_ITEMCHANGEDA:
                            OnMessageNeedsSending("HDN_ITEMCHANGEDA " + message, Color.Black);
                            break;
                        case HDN_ITEMCHANGEDW:
                            OnMessageNeedsSending("HDN_ITEMCHANGEDW " + message, Color.Black);
                            break;
                        case NM_HOVER:
                            OnMessageNeedsSending("NM_HOVER " + message, Color.Black);
                            break;
                        case NM_RELEASEDCAPTURE:
                            OnMessageNeedsSending("NM_RELEASEDCAPTURE" + message, Color.Black);
                            break;
                        case NM_CUSTOMDRAW:
                            //lpNMCustomDraw = (LPNMLVCUSTOMDRAW)lParam;
                            callBase = false;
                            //OnMouseHover(EventArgs.Empty);
                            OnMessageNeedsSending("NM_CUSTOMDRAW" + message, Color.Black);
                            _cCehckBox.BringToFront();

                            _cCehckBox.Invalidate();
                            break;
                        default:
                            OnMessageNeedsSending("code: " + nmhdr.code + ", hwndFrom: " + nmhdr.hwndFrom + ", idFrom: " + nmhdr.idFrom + ", coder: " + nmhdr.coder, Color.Black);
                            break;

                    } //switch

                    break;
            } //switch


            if (callBase)
            {
                // pass messages on to the base control for processing

                base.WndProc(ref message);
            } //if
        }
    }
}

Bad = knowing 2 much

QuestionHow Secure are MDF DB Files? Pin
Caniac21727-Apr-10 2:21
Caniac21727-Apr-10 2:21 
AnswerRe: How Secure are MDF DB Files? Pin
Michel Godfroid27-Apr-10 3:35
Michel Godfroid27-Apr-10 3:35 
GeneralRe: How Secure are MDF DB Files? Pin
Caniac21727-Apr-10 4:23
Caniac21727-Apr-10 4:23 
QuestionMessage Removed Pin
27-Apr-10 2:17
Emmet_Brown27-Apr-10 2:17 
AnswerRe: form design / update clash Pin
Rajesh Anuhya27-Apr-10 2:21
professionalRajesh Anuhya27-Apr-10 2:21 
GeneralRe: form design / update clash Pin
Emmet_Brown27-Apr-10 3:51
Emmet_Brown27-Apr-10 3:51 
GeneralRe: form design / update clash Pin
AspDotNetDev27-Apr-10 18:14
protectorAspDotNetDev27-Apr-10 18:14 
JokeRe: form design / update clash Pin
Calla27-Apr-10 20:01
Calla27-Apr-10 20:01 
QuestionCopyFile Pin
toto_201027-Apr-10 1:48
toto_201027-Apr-10 1:48 
AnswerRe: CopyFile Pin
Rajesh Anuhya27-Apr-10 1:51
professionalRajesh Anuhya27-Apr-10 1:51 
AnswerRe: CopyFile Pin
Rajesh Anuhya27-Apr-10 1:59
professionalRajesh Anuhya27-Apr-10 1:59 
AnswerRe: CopyFile Pin
harold aptroot27-Apr-10 5:02
harold aptroot27-Apr-10 5:02 
GeneralRe: CopyFile Pin
toto_201027-Apr-10 7:11
toto_201027-Apr-10 7:11 
GeneralRe: CopyFile Pin
harold aptroot27-Apr-10 7:20
harold aptroot27-Apr-10 7:20 
QuestionRotate Text OpenGL Pin
Paul Harsent27-Apr-10 0:29
Paul Harsent27-Apr-10 0:29 
AnswerRe: Rotate Text OpenGL [modified] Pin
Natural_Demon27-Apr-10 4:29
Natural_Demon27-Apr-10 4:29 
GeneralRe: Rotate Text OpenGL Pin
Paul Harsent27-Apr-10 5:30
Paul Harsent27-Apr-10 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.