///<summary></summary> public OutlookBar(){ // This call is required by the Windows.Forms Form Designer. InitializeComponent(); Buttons=new OutlookButton[7]; Buttons[0]=new OutlookButton("Appts",0); Buttons[1]=new OutlookButton("Family",1); Buttons[2]=new OutlookButton("Account",2); Buttons[3]=new OutlookButton("Treat' Plan",3); Buttons[4]=new OutlookButton("Chart",4); Buttons[5]=new OutlookButton("Images",5); Buttons[6]=new OutlookButton("Manage",6); UpdateAll(); }
///<summary></summary> protected void OnButtonClicked(OutlookButton myButton, bool myCancel) { if (this.ButtonClicked != null) { //previousSelected=SelectedIndex; ButtonClicked_EventArgs oArgs = new ButtonClicked_EventArgs(myButton, myCancel); this.ButtonClicked(this, oArgs); if (oArgs.Cancel) { SelectedIndex = previousSelected; Invalidate(); } } }
///<summary></summary> public OutlookBar() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); Buttons = new OutlookButton[7]; Buttons[0] = new OutlookButton("Appts", 0); Buttons[1] = new OutlookButton("Family", 1); Buttons[2] = new OutlookButton("Account", 2); Buttons[3] = new OutlookButton("Treat' Plan", 3); Buttons[4] = new OutlookButton("Chart", 4); Buttons[5] = new OutlookButton("Images", 5); Buttons[6] = new OutlookButton("Manage", 6); UpdateAll(); }
///<summary></summary> public OutlookBar() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); this.DoubleBuffered = true; //reduces flicker SetTheme(); Buttons = new OutlookButton[7]; Buttons[0] = new OutlookButton("Appts", imageList32.Images[ODColorTheme.OutlookApptImageIndex]); Buttons[1] = new OutlookButton("Family", imageList32.Images[ODColorTheme.OutlookFamilyImageIndex]); Buttons[2] = new OutlookButton("Account", imageList32.Images[ODColorTheme.OutlookAcctImageIndex]); Buttons[3] = new OutlookButton("Treat' Plan", imageList32.Images[ODColorTheme.OutlookTreatPlanImageIndex]); Buttons[4] = new OutlookButton("Chart", imageList32.Images[ODColorTheme.OutlookChartImageIndex]); Buttons[5] = new OutlookButton("Images", imageList32.Images[ODColorTheme.OutlookImagesImageIndex]); Buttons[6] = new OutlookButton("Manage", imageList32.Images[ODColorTheme.OutlookManageImageIndex]); UpdateAll(); }
///<summary></summary> public ButtonClicked_EventArgs(OutlookButton myButton, bool myCancel) { outlookButton = myButton; }
/// <summary>Draws one button using the info specified.</summary> /// <param name="myButton">Contains caption, image and bounds info.</param> /// <param name="isHot">Is the mouse currently hovering over this button.</param> /// <param name="isPressed">Is the left mouse button currently down on this button.</param> /// <param name="isSelected">Is this the currently selected button</param> private void DrawButton(OutlookButton myButton, bool isHot, bool isPressed, bool isSelected) { Rectangle gradientRect = new Rectangle(myButton.Bounds.X , myButton.Bounds.Y + myButton.Bounds.Height - 10 , myButton.Bounds.Width, 10); Color hotColor = Color.FromArgb(235, 235, 235); Color pressedColor = Color.FromArgb(210, 210, 210); Color selectedColor = Color.White; Color outlineColor = Color.FromArgb(28, 81, 128); using (Graphics g = this.CreateGraphics()) using (SolidBrush blackBrush = new SolidBrush(Color.Black)) using (SolidBrush controlBrush = new SolidBrush(SystemColors.Control)) using (SolidBrush pressedBrush = new SolidBrush(pressedColor)) using (SolidBrush whiteBrush = new SolidBrush(Color.White)) using (SolidBrush hotSolidBrush = new SolidBrush(hotColor)) using (Pen outlinePen = new Pen(outlineColor, 1)) using (StringFormat format = new StringFormat()) using (LinearGradientBrush hotBrush = new LinearGradientBrush(gradientRect, Color.White, pressedColor, LinearGradientMode.Vertical)) { format.Alignment = StringAlignment.Center; if (!myButton.Visible) { g.FillRectangle(controlBrush, myButton.Bounds.X, myButton.Bounds.Y , myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); return; } if (isPressed) { g.FillRectangle(pressedBrush, myButton.Bounds.X, myButton.Bounds.Y , myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); } else if (isSelected) { g.FillRectangle(whiteBrush, myButton.Bounds.X, myButton.Bounds.Y , myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); g.FillRectangle(hotBrush, myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height - 10 , myButton.Bounds.Width + 1, 10); } else if (isHot) { g.FillRectangle(hotSolidBrush, myButton.Bounds.X, myButton.Bounds.Y , myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); } else { g.FillRectangle(controlBrush, myButton.Bounds.X, myButton.Bounds.Y , myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); } //outline if (isPressed || isSelected || isHot) { //block out the corners so they won't show. This can be improved later. g.FillPolygon(controlBrush, new Point[] { new Point(myButton.Bounds.X, myButton.Bounds.Y), new Point(myButton.Bounds.X + 3, myButton.Bounds.Y), new Point(myButton.Bounds.X, myButton.Bounds.Y + 3) }); g.FillPolygon(controlBrush, new Point[] {//it's one pixel to the right because of the way rect drawn. new Point(myButton.Bounds.X + myButton.Bounds.Width - 2, myButton.Bounds.Y), new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y), new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y + 3) }); g.FillPolygon(controlBrush, new Point[] {//it's one pixel down and right. new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y + myButton.Bounds.Height - 3), new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y + myButton.Bounds.Height + 1), new Point(myButton.Bounds.X + myButton.Bounds.Width - 3, myButton.Bounds.Y + myButton.Bounds.Height + 1) }); g.FillPolygon(controlBrush, new Point[] {//it's one pixel down new Point(myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height - 3), new Point(myButton.Bounds.X + 3, myButton.Bounds.Y + myButton.Bounds.Height + 1), new Point(myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height + 1) }); //then draw outline DrawRoundedRectangle(g, outlinePen, myButton.Bounds, 4); } //Image Rectangle imgRect = new Rectangle((this.Width - 32) / 2, myButton.Bounds.Y + 3, 32, 32); if (myButton.ImageIndex > -1 && this.ImageList != null && myButton.ImageIndex < this.ImageList.Images.Count) { g.DrawImage(ImageList.Images[myButton.ImageIndex], imgRect); } //Text Rectangle textRect = new Rectangle(myButton.Bounds.X - 1, imgRect.Bottom + 3 , myButton.Bounds.Width + 2, myButton.Bounds.Bottom - imgRect.Bottom + 3); g.DrawString(myButton.Caption, textFont, blackBrush, textRect, format); } }
/// <summary>Draws one button using the info specified.</summary> /// <param name="myButton">Contains caption, image and bounds info.</param> /// <param name="isHot">Is the mouse currently hovering over this button.</param> /// <param name="isPressed">Is the left mouse button currently down on this button.</param> /// <param name="isSelected">Is this the currently selected button</param> private void DrawButton(OutlookButton myButton, bool isHot, bool isPressed, bool isSelected, Graphics g) { if (!myButton.Visible) { g.FillRectangle(ODColorTheme.OutlookBackBrush, myButton.Bounds.X, myButton.Bounds.Y , myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); return; } if (isPressed) { g.FillRectangle(ODColorTheme.OutlookPressedBrush, myButton.Bounds.X, myButton.Bounds.Y, myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); } else if (isSelected) { g.FillRectangle(ODColorTheme.OutlookSelectedBrush, myButton.Bounds.X, myButton.Bounds.Y, myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); Rectangle gradientRect = new Rectangle(myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height - 10, myButton.Bounds.Width, 10); //Recreate _hotBrush if theme color changed. if (!myButton.Color1HotBrush.Equals(ODColorTheme.OutlookSelectedBrush.Color) || !myButton.Color2HotBrush.Equals(ODColorTheme.OutlookPressedBrush.Color)) { if (myButton.HotBrush != null) { myButton.HotBrush.Dispose(); } myButton.Color1HotBrush = ODColorTheme.OutlookSelectedBrush.Color; myButton.Color2HotBrush = ODColorTheme.OutlookPressedBrush.Color; myButton.HotBrush = new LinearGradientBrush(gradientRect, myButton.Color1HotBrush, myButton.Color2HotBrush, LinearGradientMode.Vertical); } g.FillRectangle(myButton.HotBrush, myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height - 10, myButton.Bounds.Width + 1, 10); } else if (isHot) { g.FillRectangle(ODColorTheme.OutlookHotBrush, myButton.Bounds.X, myButton.Bounds.Y, myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); } else { g.FillRectangle(ODColorTheme.OutlookBackBrush, myButton.Bounds.X, myButton.Bounds.Y, myButton.Bounds.Width + 1, myButton.Bounds.Height + 1); } //outline if (isPressed || isSelected || isHot) { //block out the corners so they won't show. This can be improved later. g.FillPolygon(ODColorTheme.OutlookBackBrush, new Point[] { new Point(myButton.Bounds.X, myButton.Bounds.Y), new Point(myButton.Bounds.X + 3, myButton.Bounds.Y), new Point(myButton.Bounds.X, myButton.Bounds.Y + 3) }); g.FillPolygon(ODColorTheme.OutlookBackBrush, new Point[] { //it's one pixel to the right because of the way rect drawn. new Point(myButton.Bounds.X + myButton.Bounds.Width - 2, myButton.Bounds.Y), new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y), new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y + 3) }); g.FillPolygon(ODColorTheme.OutlookBackBrush, new Point[] { //it's one pixel down and right. new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y + myButton.Bounds.Height - 3), new Point(myButton.Bounds.X + myButton.Bounds.Width + 1, myButton.Bounds.Y + myButton.Bounds.Height + 1), new Point(myButton.Bounds.X + myButton.Bounds.Width - 3, myButton.Bounds.Y + myButton.Bounds.Height + 1) }); g.FillPolygon(ODColorTheme.OutlookBackBrush, new Point[] { //it's one pixel down new Point(myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height - 3), new Point(myButton.Bounds.X + 3, myButton.Bounds.Y + myButton.Bounds.Height + 1), new Point(myButton.Bounds.X, myButton.Bounds.Y + myButton.Bounds.Height + 1) }); //then draw outline GraphicsHelper.DrawRoundedRectangle(g, ODColorTheme.OutlookOutlineColor, myButton.Bounds, ODColorTheme.OutlookHoverCornerRadius); } //Image Rectangle imgRect = new Rectangle((Width - myButton.Image.Width) / 2, myButton.Bounds.Y + 3, myButton.Image.Width, myButton.Image.Height); if (myButton.Image != null) { ODException.SwallowAnyException(() => { //If fails, then would be a bad reason to crash. Should still draw button text below so user knows what the button is. //Consider using ODColorTheme.InvertImageIfNeeded(myButton.Image) in future for dark themes, //however, if we use the inverted image, then we need to prevent processing the inverted image every frame. g.DrawImage(myButton.Image, imgRect); }); } //Text Rectangle textRect = new Rectangle(myButton.Bounds.X - 1, imgRect.Bottom + 3, myButton.Bounds.Width + 2, myButton.Bounds.Bottom - imgRect.Bottom + 3); g.DrawString(myButton.Caption, textFont, ODColorTheme.OutlookTextBrush, textRect, _format); }
///<summary></summary> public ButtonClicked_EventArgs(OutlookButton myButton,bool myCancel){ outlookButton=myButton; }
///<summary></summary> protected void OnButtonClicked(OutlookButton myButton,bool myCancel){ if(this.ButtonClicked != null){ //previousSelected=SelectedIndex; ButtonClicked_EventArgs oArgs = new ButtonClicked_EventArgs(myButton,myCancel); this.ButtonClicked(this,oArgs); if(oArgs.Cancel){ SelectedIndex=previousSelected; Invalidate(); } } }
/// <summary>Draws one button using the info specified.</summary> /// <param name="myButton">Contains caption, image and bounds info.</param> /// <param name="isHot">Is the mouse currently hovering over this button.</param> /// <param name="isPressed">Is the left mouse button currently down on this button.</param> /// <param name="isSelected">Is this the currently selected button</param> private void DrawButton(OutlookButton myButton,bool isHot,bool isPressed,bool isSelected){ Graphics g=this.CreateGraphics(); Color hotColor=Color.FromArgb(235,235,235);//.FromArgb(210,218,232); Color pressedColor=Color.FromArgb(210,210,210);//(182,193,214); Color selectedColor=Color.White; Color outlineColor=Color.FromArgb(28,81,128);//Color.Gray; SolidBrush textBrush = new SolidBrush(Color.Black); SolidBrush backgBrush=new SolidBrush(SystemColors.Control); StringFormat format = new StringFormat(); format.Alignment=StringAlignment.Center; if(!myButton.Visible){ g.FillRectangle(backgBrush,myButton.Bounds.X,myButton.Bounds.Y ,myButton.Bounds.Width+1,myButton.Bounds.Height+1); g.Dispose(); return; } if(isPressed){ g.FillRectangle(new SolidBrush(pressedColor),myButton.Bounds.X,myButton.Bounds.Y ,myButton.Bounds.Width+1,myButton.Bounds.Height+1); } else if(isSelected){ g.FillRectangle(new SolidBrush(Color.White),myButton.Bounds.X,myButton.Bounds.Y ,myButton.Bounds.Width+1,myButton.Bounds.Height+1); Rectangle gradientRect=new Rectangle(myButton.Bounds.X ,myButton.Bounds.Y+myButton.Bounds.Height-10 ,myButton.Bounds.Width,10); LinearGradientBrush hotBrush=new LinearGradientBrush(gradientRect,Color.White,pressedColor, LinearGradientMode.Vertical); g.FillRectangle(hotBrush,myButton.Bounds.X,myButton.Bounds.Y+myButton.Bounds.Height-10 ,myButton.Bounds.Width+1,10); } else if(isHot){ g.FillRectangle(new SolidBrush(hotColor),myButton.Bounds.X,myButton.Bounds.Y ,myButton.Bounds.Width+1,myButton.Bounds.Height+1); } else{ g.FillRectangle(new SolidBrush(SystemColors.Control),myButton.Bounds.X,myButton.Bounds.Y ,myButton.Bounds.Width+1,myButton.Bounds.Height+1); } //outline if(isPressed || isSelected || isHot){ //block out the corners so they won't show. This can be improved later. g.FillPolygon(backgBrush,new Point[] { new Point(myButton.Bounds.X,myButton.Bounds.Y), new Point(myButton.Bounds.X+3,myButton.Bounds.Y), new Point(myButton.Bounds.X,myButton.Bounds.Y+3)}); g.FillPolygon(backgBrush,new Point[] {//it's one pixel to the right because of the way rect drawn. new Point(myButton.Bounds.X+myButton.Bounds.Width-2,myButton.Bounds.Y), new Point(myButton.Bounds.X+myButton.Bounds.Width+1,myButton.Bounds.Y), new Point(myButton.Bounds.X+myButton.Bounds.Width+1,myButton.Bounds.Y+3)}); g.FillPolygon(backgBrush,new Point[] {//it's one pixel down and right. new Point(myButton.Bounds.X+myButton.Bounds.Width+1,myButton.Bounds.Y+myButton.Bounds.Height-3), new Point(myButton.Bounds.X+myButton.Bounds.Width+1,myButton.Bounds.Y+myButton.Bounds.Height+1), new Point(myButton.Bounds.X+myButton.Bounds.Width-3,myButton.Bounds.Y+myButton.Bounds.Height+1)}); g.FillPolygon(backgBrush,new Point[] {//it's one pixel down new Point(myButton.Bounds.X,myButton.Bounds.Y+myButton.Bounds.Height-3), new Point(myButton.Bounds.X+3,myButton.Bounds.Y+myButton.Bounds.Height+1), new Point(myButton.Bounds.X,myButton.Bounds.Y+myButton.Bounds.Height+1)}); //g.FillRectangle(backgBrush,myButton.Bounds.X,myButton.Bounds.Y,2,2); //g.FillRectangle(backgBrush,myButton.Bounds.X+,myButton.Bounds.Y,2,2); //then draw outline DrawRoundedRectangle(g,new Pen(outlineColor,1),myButton.Bounds,4); } //Image Rectangle imgRect = new Rectangle((this.Width-32)/2,myButton.Bounds.Y+3,32,32); if(myButton.ImageIndex > -1 && this.ImageList != null && myButton.ImageIndex < this.ImageList.Images.Count) { g.DrawImage(ImageList.Images[myButton.ImageIndex],imgRect); } //Text Rectangle textRect = new Rectangle(myButton.Bounds.X-1,imgRect.Bottom+3 ,myButton.Bounds.Width+2,myButton.Bounds.Bottom-imgRect.Bottom+3); g.DrawString(myButton.Caption,textFont,textBrush,textRect,format); g.Dispose(); }