예제 #1
0
        private void SetGrpState(ListViewGroup lvGroup, ListViewGroupState grpState, string task)
        {
            if (OSVersion.IsBelow(WindowsVersion.Vista))
            {
                return;
            }
            if (lvGroup == null || lvGroup.ListView == null)
            {
                return;
            }
            if (lvGroup.ListView.InvokeRequired)
            {
                lvGroup.ListView.Invoke(new CallBackSetGroupState(SetGrpState), lvGroup, grpState, task);
            }
            else
            {
                int?    GrpId  = GetGroupID(lvGroup);
                int     gIndex = lvGroup.ListView.Groups.IndexOf(lvGroup);
                LVGroup group  = new LVGroup();
                group.CbSize = Marshal.SizeOf(group);
                group.Mask  |= ListViewGroupMask.Task
                               | ListViewGroupMask.State
                               | ListViewGroupMask.Align;

                IntPtr taskString = Marshal.StringToHGlobalAuto(task);

                if (task.Length > 1)
                {
                    group.Task    = taskString;
                    group.CchTask = task.Length;
                }

                group.GroupState = grpState;

                if (GrpId != null)
                {
                    group.GroupId = GrpId.Value;
                    SendMessage(base.Handle, LVM_SetGroupInfo, GrpId.Value, ref group);
                }
                else
                {
                    group.GroupId = gIndex;
                    SendMessage(base.Handle, LVM_SetGroupInfo, gIndex, ref group);
                }
                lvGroup.ListView.Refresh();

                Marshal.FreeHGlobal(taskString);
            }
        }
예제 #2
0
        public TreeViewAdv()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.CacheText, true);

            if (OSVersion.IsBelow(WindowsVersion.Vista))
            {
                this.ColumnHeaderHeight = ExplorerVisualStyle.VisualStylesEnabled ? 20 : 17;
            }
            else
            {
                this.ColumnHeaderHeight = ExplorerVisualStyle.VisualStylesEnabled ? 25 : 17;
            }

            //BorderStyle = BorderStyle.Fixed3D;
            _hScrollBar.Height = SystemInformation.HorizontalScrollBarHeight;
            _vScrollBar.Width  = SystemInformation.VerticalScrollBarWidth;

            _rowLayout         = new FixedRowHeightLayout(this, RowHeight);
            this.RowMap        = new List <TreeNodeAdv>();
            this.Selection     = new List <TreeNodeAdv>();
            this.SelectedNodes = new ReadOnlyCollection <TreeNodeAdv>(this.Selection);
            this.Columns       = new TreeColumnCollection(this);
            _toolTip           = new ToolTip();

            _measureContext = new DrawContext
            {
                Font     = this.Font,
                Graphics = Graphics.FromImage(new Bitmap(1, 1))
            };

            this.Input = new NormalInputState(this);
            _search    = new IncrementalSearch(this);

            CreateNodes();
            CreatePens();

            ArrangeControls();

            _plusMinus        = new NodePlusMinus(this);
            this.NodeControls = new NodeControlsCollection(this);

            Font = _font;
        }
예제 #3
0
        public void SetImage(MenuItem mnuItem, Image value, bool ignorePending)
        {
            if (_delaySetImageCalls && !ignorePending)
            {
                _pendingSetImageCalls.Enqueue(new KeyValuePair <MenuItem, Image>(mnuItem, value));
                return;
            }

            Properties prop = EnsurePropertiesExists(mnuItem);

            if (DesignMode)
            {
                prop.Image = value;
            }

            if (!DesignMode && OSVersion.IsAboveOrEqual(WindowsVersion.Vista))
            {
                //Destroy old bitmap object
                if (prop.renderBmpHbitmap != IntPtr.Zero)
                {
                    DeleteObject(prop.renderBmpHbitmap);
                    prop.renderBmpHbitmap = IntPtr.Zero;
                }

                //if there's no Image, then just bail out
                if (value == null)
                {
                    // wj32: clean up resources before doing that...
                    RemoveVistaMenuItem(mnuItem);
                    return;
                }

                //convert to 32bppPArgb (the 'P' means The red, green, and blue components are premultiplied, according to the alpha component.)
                Bitmap   renderBmp = new Bitmap(value.Width, value.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                Graphics g         = Graphics.FromImage(renderBmp);

                g.DrawImage(value, 0, 0, value.Width, value.Height);
                g.Dispose();

                prop.renderBmpHbitmap = renderBmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0));
                renderBmp.Dispose();

                if (formHasBeenIntialized)
                {
                    AddVistaMenuItem(mnuItem);
                }
            }
            else if (!DesignMode && OSVersion.IsBelow(WindowsVersion.Vista))
            {
                if (prop.PreVistaBitmap != null)
                {
                    prop.PreVistaBitmap.Dispose();
                    prop.PreVistaBitmap = null;
                }

                if (value == null)
                {
                    RemoveVistaMenuItem(mnuItem);
                    return;
                }

                Bitmap   bmp = new Bitmap(value.Width, value.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                Graphics g   = Graphics.FromImage(bmp);

                g.DrawImage(value, 0, 0, value.Width, value.Height);
                g.Dispose();

                prop.PreVistaBitmap = bmp;

                //for every Pre-Vista Windows, add the parent of the menu item to the list of parents
                if (formHasBeenIntialized)
                {
                    AddPreVistaMenuItem(mnuItem);
                }
            }
        }