/// <summary> /// Reset all buttons after properties have changed /// </summary> public void RefreshProperties() { this.Width = Parent.Width; this.Height = Parent.Height; if (MainForm.IsHidden) { this.AutoScroll = false; HorizontalScroll.Enabled = false; VerticalScroll.Enabled = false; } else { this.AutoScroll = true; if (FlowDirection == System.Windows.Forms.FlowDirection.LeftToRight) { HorizontalScroll.Enabled = false; VerticalScroll.Enabled = true; this.Padding = new System.Windows.Forms.Padding(0, 0, 10, 0); this.VerticalScroll.SmallChange = this.VerticalScroll.LargeChange = this.Height; } else { HorizontalScroll.Enabled = true; VerticalScroll.Enabled = false; this.Padding = new System.Windows.Forms.Padding(0, 0, 0, 10); this.HorizontalScroll.SmallChange = this.HorizontalScroll.LargeChange = this.Width; } } foreach (var item in this.Controls) { TaskbarButton button = item as TaskbarButton; if (button != null) { button.UpdateFont(); button.SetDefaultHeight(); button.ShowLabel = TaskbarPropertiesManager.Instance.Properties.ShowLabels; var process = button.Tag as SecondDisplayProcess; if (process.Icon != null) { button.Image = (this.IsBig ? process.Icon : process.SmallIcon).ConvertToBitmap(this.IsBig); } } else { (item as TaskbarPinnedButton).Init(); } } ArrangeButtons(); }
/// <summary> /// Add a new button to the taskbar /// </summary> /// <param name="process">Window wrapper</param> /// <param name="tooltipManager">Reference to the tooltip manager</param> /// <param name="processMenu">Button's context menu</param> public void AddButton(SecondDisplayProcess process, ToolTipManager tooltipManager, ContextMenuStrip processMenu) { // multiple windows messages call this method, in the same thread. // so we need to ignore same message when repeated if (_lastAddButtonHandle == process.Handle) { return; } _lastAddButtonHandle = process.Handle; TaskbarButton button = _taskbarButtons.Find(tb => { var sdp = (tb.Tag as SecondDisplayProcess); return(sdp.Handle == process.Handle); }); if (button != null) { _lastAddButtonHandle = IntPtr.Zero; return; } // can't use locks since the thread is the same //if (_syncEvent.WaitOne(500)) { button = _taskbarButtons.Find(tb => { var sdp = (tb.Tag as SecondDisplayProcess); return(sdp.Handle == process.Handle); }); if (button != null) { _lastAddButtonHandle = IntPtr.Zero; //_syncEvent.Release(); return; } button = new TaskbarButton(tooltipManager); button.Tag = process; _taskbarButtons.Add(button); //_syncEvent.Release(); } /* * else * { * _lastAddButtonHandle = IntPtr.Zero; * return; * } */ _lastAddButtonHandle = IntPtr.Zero; this.SuspendLayout(); try { this.Controls.Add(button); } catch (Win32Exception e) { var p = System.Diagnostics.Process.GetCurrentProcess(); if (MessageBox.Show(string.Format("Err: {1}{0}Thread Count: {2}{0}Handle Count: {3}", Environment.NewLine, e.Message, p.Threads.Count, p.HandleCount), "Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { Debugger.Break(); } _taskbarButtons.Remove(button); this.ResumeLayout(); return; } button.AutoSize = false; button.Text = process.Title; if (process.Icon != null) { button.Image = (IsBig ? process.Icon : process.SmallIcon).ConvertToBitmap(IsBig); } button.Padding = new System.Windows.Forms.Padding(0); button.Margin = new System.Windows.Forms.Padding(0); button.ShowLabel = TaskbarPropertiesManager.Instance.Properties.ShowLabels; button.SetDefaultHeight(); button.ContextMenuStrip = processMenu; _groups.AddToGroup(process.Path, button); ArrangeButtons(); this.ResumeLayout(); button.Refresh(); }