1 // 2 // ToolStripRenderer.cs 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining 5 // a copy of this software and associated documentation files (the 6 // "Software"), to deal in the Software without restriction, including 7 // without limitation the rights to use, copy, modify, merge, publish, 8 // distribute, sublicense, and/or sell copies of the Software, and to 9 // permit persons to whom the Software is furnished to do so, subject to 10 // the following conditions: 11 // 12 // The above copyright notice and this permission notice shall be 13 // included in all copies or substantial portions of the Software. 14 // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 // 23 // Copyright (c) Jonathan Pobst 24 // 25 // Authors: 26 // Jonathan Pobst (monkey@jpobst.com) 27 // 28 29 using System; 30 using System.ComponentModel; 31 using System.Drawing; 32 using System.Drawing.Imaging; 33 using System.Drawing.Drawing2D; 34 35 namespace System.Windows.Forms 36 { 37 public abstract class ToolStripRenderer 38 { 39 private static ColorMatrix grayscale_matrix = new ColorMatrix (new float[][] { 40 new float[] {0.22f, 0.22f, 0.22f, 0, 0}, 41 new float[] {0.27f, 0.27f, 0.27f, 0, 0}, 42 new float[] {0.04f, 0.04f, 0.04f, 0, 0}, 43 new float[] {0.365f, 0.365f, 0.365f, 0.7f, 0}, 44 new float[] {0, 0, 0, 0, 1} 45 }); 46 ToolStripRenderer()47 protected ToolStripRenderer () 48 { 49 } 50 51 #region Public Methods CreateDisabledImage(Image normalImage)52 public static Image CreateDisabledImage(Image normalImage) 53 { 54 if (normalImage == null) 55 return null; 56 57 // Code adapted from ThemeWin32Classic.cs 58 ImageAttributes ia = new ImageAttributes(); 59 ia.SetColorMatrix (grayscale_matrix); 60 61 Bitmap b = new Bitmap(normalImage.Width, normalImage.Height); 62 using (Graphics g = Graphics.FromImage(b)) 63 g.DrawImage(normalImage, new Rectangle (0, 0, normalImage.Width, normalImage.Height), 0, 0, normalImage.Width, normalImage.Height, GraphicsUnit.Pixel, ia); 64 65 return b; 66 } 67 DrawArrow(ToolStripArrowRenderEventArgs e)68 public void DrawArrow (ToolStripArrowRenderEventArgs e) 69 { this.OnRenderArrow (e); } 70 DrawButtonBackground(ToolStripItemRenderEventArgs e)71 public void DrawButtonBackground (ToolStripItemRenderEventArgs e) 72 { this.OnRenderButtonBackground (e); } 73 DrawDropDownButtonBackground(ToolStripItemRenderEventArgs e)74 public void DrawDropDownButtonBackground (ToolStripItemRenderEventArgs e) 75 { this.OnRenderDropDownButtonBackground (e); } 76 DrawGrip(ToolStripGripRenderEventArgs e)77 public void DrawGrip (ToolStripGripRenderEventArgs e) 78 { this.OnRenderGrip (e); } 79 DrawImageMargin(ToolStripRenderEventArgs e)80 public void DrawImageMargin (ToolStripRenderEventArgs e) 81 { this.OnRenderImageMargin (e); } 82 DrawItemBackground(ToolStripItemRenderEventArgs e)83 public void DrawItemBackground (ToolStripItemRenderEventArgs e) 84 { this.OnRenderItemBackground (e); } 85 DrawItemCheck(ToolStripItemImageRenderEventArgs e)86 public void DrawItemCheck (ToolStripItemImageRenderEventArgs e) 87 { this.OnRenderItemCheck (e); } 88 DrawItemImage(ToolStripItemImageRenderEventArgs e)89 public void DrawItemImage (ToolStripItemImageRenderEventArgs e) 90 { this.OnRenderItemImage (e); } 91 DrawItemText(ToolStripItemTextRenderEventArgs e)92 public void DrawItemText (ToolStripItemTextRenderEventArgs e) 93 { this.OnRenderItemText (e); } 94 DrawLabelBackground(ToolStripItemRenderEventArgs e)95 public void DrawLabelBackground (ToolStripItemRenderEventArgs e) 96 { this.OnRenderLabelBackground (e); } 97 DrawMenuItemBackground(ToolStripItemRenderEventArgs e)98 public void DrawMenuItemBackground (ToolStripItemRenderEventArgs e) 99 { this.OnRenderMenuItemBackground (e); } 100 DrawOverflowButtonBackground(ToolStripItemRenderEventArgs e)101 public void DrawOverflowButtonBackground (ToolStripItemRenderEventArgs e) 102 { this.OnRenderOverflowButtonBackground (e); } 103 DrawSeparator(ToolStripSeparatorRenderEventArgs e)104 public void DrawSeparator (ToolStripSeparatorRenderEventArgs e) 105 { this.OnRenderSeparator (e); } 106 DrawSplitButton(ToolStripItemRenderEventArgs e)107 public void DrawSplitButton (ToolStripItemRenderEventArgs e) 108 { this.OnRenderSplitButtonBackground (e); } 109 DrawStatusStripSizingGrip(ToolStripRenderEventArgs e)110 public void DrawStatusStripSizingGrip (ToolStripRenderEventArgs e) 111 { this.OnRenderStatusStripSizingGrip (e); } 112 DrawToolStripBackground(ToolStripRenderEventArgs e)113 public void DrawToolStripBackground (ToolStripRenderEventArgs e) 114 { this.OnRenderToolStripBackground (e); } 115 DrawToolStripBorder(ToolStripRenderEventArgs e)116 public void DrawToolStripBorder (ToolStripRenderEventArgs e) 117 { this.OnRenderToolStripBorder (e); } 118 DrawToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)119 public void DrawToolStripContentPanelBackground (ToolStripContentPanelRenderEventArgs e) 120 { this.OnRenderToolStripContentPanelBackground (e); } 121 DrawToolStripPanelBackground(ToolStripPanelRenderEventArgs e)122 public void DrawToolStripPanelBackground (ToolStripPanelRenderEventArgs e) 123 { this.OnRenderToolStripPanelBackground (e); } 124 DrawToolStripStatusLabelBackground(ToolStripItemRenderEventArgs e)125 public void DrawToolStripStatusLabelBackground (ToolStripItemRenderEventArgs e) 126 { this.OnRenderToolStripStatusLabelBackground (e); } 127 #endregion 128 129 #region Protected Methods Initialize(ToolStrip toolStrip)130 protected internal virtual void Initialize (ToolStrip toolStrip) {} InitializeContentPanel(ToolStripContentPanel contentPanel)131 protected internal virtual void InitializeContentPanel (ToolStripContentPanel contentPanel) {} InitializeItem(ToolStripItem item)132 protected internal virtual void InitializeItem (ToolStripItem item) {} InitializePanel(ToolStripPanel toolStripPanel)133 protected internal virtual void InitializePanel (ToolStripPanel toolStripPanel) {} 134 OnRenderArrow(ToolStripArrowRenderEventArgs e)135 protected virtual void OnRenderArrow (ToolStripArrowRenderEventArgs e) 136 { 137 switch (e.Direction) { 138 case ArrowDirection.Down: 139 using (Pen p = new Pen (e.ArrowColor)) { 140 int x = e.ArrowRectangle.Left + (e.ArrowRectangle.Width / 2) - 3; 141 int y = e.ArrowRectangle.Top + (e.ArrowRectangle.Height / 2) - 2; 142 143 DrawDownArrow (e.Graphics, p, x, y); 144 } 145 break; 146 case ArrowDirection.Left: 147 break; 148 case ArrowDirection.Right: 149 using (Pen p = new Pen (e.ArrowColor)) { 150 int x = e.ArrowRectangle.Left + (e.ArrowRectangle.Width / 2) - 3; 151 int y = e.ArrowRectangle.Top + (e.ArrowRectangle.Height / 2) - 4; 152 153 DrawRightArrow (e.Graphics, p, x, y); 154 } 155 break; 156 case ArrowDirection.Up: 157 break; 158 } 159 160 ToolStripArrowRenderEventHandler eh = (ToolStripArrowRenderEventHandler)Events[RenderArrowEvent]; 161 if (eh != null) 162 eh (this, e); 163 } 164 OnRenderButtonBackground(ToolStripItemRenderEventArgs e)165 protected virtual void OnRenderButtonBackground (ToolStripItemRenderEventArgs e) 166 { 167 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderButtonBackgroundEvent]; 168 if (eh != null) 169 eh (this, e); 170 } 171 OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)172 protected virtual void OnRenderDropDownButtonBackground (ToolStripItemRenderEventArgs e) 173 { 174 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderDropDownButtonBackgroundEvent]; 175 if (eh != null) 176 eh (this, e); 177 } 178 OnRenderGrip(ToolStripGripRenderEventArgs e)179 protected virtual void OnRenderGrip (ToolStripGripRenderEventArgs e) 180 { 181 ToolStripGripRenderEventHandler eh = (ToolStripGripRenderEventHandler)Events [RenderGripEvent]; 182 if (eh != null) 183 eh (this, e); 184 } 185 OnRenderImageMargin(ToolStripRenderEventArgs e)186 protected virtual void OnRenderImageMargin (ToolStripRenderEventArgs e) 187 { 188 ToolStripRenderEventHandler eh = (ToolStripRenderEventHandler)Events [RenderImageMarginEvent]; 189 if (eh != null) 190 eh (this, e); 191 } 192 OnRenderItemBackground(ToolStripItemRenderEventArgs e)193 protected virtual void OnRenderItemBackground (ToolStripItemRenderEventArgs e) 194 { 195 if (e.Item.BackColor != Control.DefaultBackColor) { 196 // Only paint the BackColor if it's not the default one, 197 // to avoid painting a solid background color over the parent ToolStrip gradient. 198 Rectangle item_bounds = new Rectangle (0, 0, e.Item.Width, e.Item.Height); 199 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (e.Item.BackColor), item_bounds); 200 } 201 202 if (e.Item.BackgroundImage != null) { 203 Rectangle item_bounds = new Rectangle (0, 0, e.Item.Width, e.Item.Height); 204 DrawBackground (e.Graphics, item_bounds, e.Item.BackgroundImage, e.Item.BackgroundImageLayout); 205 } 206 207 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderItemBackgroundEvent]; 208 if (eh != null) 209 eh (this, e); 210 } 211 OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)212 protected virtual void OnRenderItemCheck (ToolStripItemImageRenderEventArgs e) 213 { 214 ToolStripItemImageRenderEventHandler eh = (ToolStripItemImageRenderEventHandler)Events [RenderItemCheckEvent]; 215 if (eh != null) 216 eh (this, e); 217 } 218 OnRenderItemImage(ToolStripItemImageRenderEventArgs e)219 protected virtual void OnRenderItemImage (ToolStripItemImageRenderEventArgs e) 220 { 221 bool need_dispose = false; 222 Image i = e.Image; 223 224 if (e.Item.RightToLeft == RightToLeft.Yes && e.Item.RightToLeftAutoMirrorImage == true) { 225 i = CreateMirrorImage (i); 226 need_dispose = true; 227 } 228 229 if (e.Item.ImageTransparentColor != Color.Empty) { 230 ImageAttributes ia = new ImageAttributes (); 231 ia.SetColorKey (e.Item.ImageTransparentColor, e.Item.ImageTransparentColor); 232 e.Graphics.DrawImage (i, e.ImageRectangle, 0, 0, i.Width, i.Height, GraphicsUnit.Pixel, ia); 233 ia.Dispose (); 234 } 235 else 236 e.Graphics.DrawImage (i, e.ImageRectangle); 237 238 if (need_dispose) 239 i.Dispose (); 240 241 ToolStripItemImageRenderEventHandler eh = (ToolStripItemImageRenderEventHandler)Events [RenderItemImageEvent]; 242 if (eh != null) 243 eh (this, e); 244 } 245 OnRenderItemText(ToolStripItemTextRenderEventArgs e)246 protected virtual void OnRenderItemText (ToolStripItemTextRenderEventArgs e) 247 { 248 if (e.TextDirection == ToolStripTextDirection.Vertical90) { 249 GraphicsState gs = e.Graphics.Save (); 250 PointF p = new PointF (e.Graphics.Transform.OffsetX, e.Graphics.Transform.OffsetY); 251 252 e.Graphics.ResetTransform (); 253 e.Graphics.RotateTransform (90); 254 255 RectangleF r = new RectangleF ((e.Item.Height - e.TextRectangle.Height) / 2, (e.TextRectangle.Width + p.X) * -1 - 18, e.TextRectangle.Height, e.TextRectangle.Width); 256 257 StringFormat sf = new StringFormat (); 258 sf.Alignment = StringAlignment.Center; 259 260 e.Graphics.DrawString (e.Text, e.TextFont, ThemeEngine.Current.ResPool.GetSolidBrush (e.TextColor), r, sf); 261 262 e.Graphics.Restore (gs); 263 } else if (e.TextDirection == ToolStripTextDirection.Vertical270) { 264 GraphicsState gs = e.Graphics.Save (); 265 PointF p = new PointF (e.Graphics.Transform.OffsetX, e.Graphics.Transform.OffsetY); 266 267 e.Graphics.ResetTransform (); 268 e.Graphics.RotateTransform (270); 269 270 RectangleF r = new RectangleF (-e.TextRectangle.Height - (e.Item.Height - e.TextRectangle.Height) / 2, (e.TextRectangle.Width + p.X) + 4, e.TextRectangle.Height, e.TextRectangle.Width); 271 272 StringFormat sf = new StringFormat (); 273 sf.Alignment = StringAlignment.Center; 274 275 e.Graphics.DrawString (e.Text, e.TextFont, ThemeEngine.Current.ResPool.GetSolidBrush (e.TextColor), r, sf); 276 277 e.Graphics.Restore (gs); 278 } else 279 TextRenderer.DrawText (e.Graphics, e.Text, e.TextFont, e.TextRectangle, e.TextColor, e.TextFormat); 280 281 ToolStripItemTextRenderEventHandler eh = (ToolStripItemTextRenderEventHandler)Events[RenderItemTextEvent]; 282 if (eh != null) 283 eh (this, e); 284 } 285 OnRenderLabelBackground(ToolStripItemRenderEventArgs e)286 protected virtual void OnRenderLabelBackground (ToolStripItemRenderEventArgs e) 287 { 288 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderLabelBackgroundEvent]; 289 if (eh != null) 290 eh (this, e); 291 } 292 OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)293 protected virtual void OnRenderMenuItemBackground (ToolStripItemRenderEventArgs e) 294 { 295 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderMenuItemBackgroundEvent]; 296 if (eh != null) 297 eh (this, e); 298 } 299 OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs e)300 protected virtual void OnRenderOverflowButtonBackground (ToolStripItemRenderEventArgs e) 301 { 302 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderOverflowButtonBackgroundEvent]; 303 if (eh != null) 304 eh (this, e); 305 } 306 OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)307 protected virtual void OnRenderSeparator (ToolStripSeparatorRenderEventArgs e) 308 { 309 ToolStripSeparatorRenderEventHandler eh = (ToolStripSeparatorRenderEventHandler)Events [RenderSeparatorEvent]; 310 if (eh != null) 311 eh (this, e); 312 } 313 OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)314 protected virtual void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e) 315 { 316 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderSplitButtonBackgroundEvent]; 317 if (eh != null) 318 eh (this, e); 319 } 320 OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs e)321 protected virtual void OnRenderStatusStripSizingGrip (ToolStripRenderEventArgs e) 322 { 323 StatusStrip ss = (StatusStrip)e.ToolStrip; 324 325 if (ss.SizingGrip == true) 326 DrawSizingGrip (e.Graphics, ss.SizeGripBounds); 327 328 ToolStripRenderEventHandler eh = (ToolStripRenderEventHandler)Events [RenderStatusStripSizingGripEvent]; 329 if (eh != null) 330 eh (this, e); 331 } 332 OnRenderToolStripBackground(ToolStripRenderEventArgs e)333 protected virtual void OnRenderToolStripBackground (ToolStripRenderEventArgs e) 334 { 335 ToolStripRenderEventHandler eh = (ToolStripRenderEventHandler)Events [RenderToolStripBackgroundEvent]; 336 if (eh != null) 337 eh (this, e); 338 } 339 OnRenderToolStripBorder(ToolStripRenderEventArgs e)340 protected virtual void OnRenderToolStripBorder (ToolStripRenderEventArgs e) 341 { 342 ToolStripRenderEventHandler eh = (ToolStripRenderEventHandler)Events [RenderToolStripBorderEvent]; 343 if (eh != null) 344 eh (this, e); 345 } 346 OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)347 protected virtual void OnRenderToolStripContentPanelBackground (ToolStripContentPanelRenderEventArgs e) 348 { 349 ToolStripContentPanelRenderEventHandler eh = (ToolStripContentPanelRenderEventHandler)Events [RenderToolStripContentPanelBackgroundEvent]; 350 if (eh != null) 351 eh (this, e); 352 } 353 OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)354 protected virtual void OnRenderToolStripPanelBackground (ToolStripPanelRenderEventArgs e) 355 { 356 ToolStripPanelRenderEventHandler eh = (ToolStripPanelRenderEventHandler)Events [RenderToolStripPanelBackgroundEvent]; 357 if (eh != null) 358 eh (this, e); 359 } 360 OnRenderToolStripStatusLabelBackground(ToolStripItemRenderEventArgs e)361 protected virtual void OnRenderToolStripStatusLabelBackground (ToolStripItemRenderEventArgs e) 362 { 363 ToolStripItemRenderEventHandler eh = (ToolStripItemRenderEventHandler)Events [RenderToolStripStatusLabelBackgroundEvent]; 364 if (eh != null) 365 eh (this, e); 366 } 367 #endregion 368 369 #region Public Events 370 EventHandlerList events; 371 372 EventHandlerList Events { 373 get { 374 if (events == null) 375 events = new EventHandlerList (); 376 return events; 377 } 378 } 379 380 static object RenderArrowEvent = new object (); 381 static object RenderButtonBackgroundEvent = new object (); 382 static object RenderDropDownButtonBackgroundEvent = new object (); 383 static object RenderGripEvent = new object (); 384 static object RenderImageMarginEvent = new object (); 385 static object RenderItemBackgroundEvent = new object (); 386 static object RenderItemCheckEvent = new object (); 387 static object RenderItemImageEvent = new object (); 388 static object RenderItemTextEvent = new object (); 389 static object RenderLabelBackgroundEvent = new object (); 390 static object RenderMenuItemBackgroundEvent = new object (); 391 static object RenderOverflowButtonBackgroundEvent = new object (); 392 static object RenderSeparatorEvent = new object (); 393 static object RenderSplitButtonBackgroundEvent = new object (); 394 static object RenderStatusStripSizingGripEvent = new object (); 395 static object RenderToolStripBackgroundEvent = new object (); 396 static object RenderToolStripBorderEvent = new object (); 397 static object RenderToolStripContentPanelBackgroundEvent = new object (); 398 static object RenderToolStripPanelBackgroundEvent = new object (); 399 static object RenderToolStripStatusLabelBackgroundEvent = new object (); 400 401 public event ToolStripArrowRenderEventHandler RenderArrow { 402 add { Events.AddHandler (RenderArrowEvent, value); } 403 remove {Events.RemoveHandler (RenderArrowEvent, value); } 404 } 405 public event ToolStripItemRenderEventHandler RenderButtonBackground { 406 add { Events.AddHandler (RenderButtonBackgroundEvent, value); } 407 remove {Events.RemoveHandler (RenderButtonBackgroundEvent, value); } 408 } 409 public event ToolStripItemRenderEventHandler RenderDropDownButtonBackground { 410 add { Events.AddHandler (RenderDropDownButtonBackgroundEvent, value); } 411 remove {Events.RemoveHandler (RenderDropDownButtonBackgroundEvent, value); } 412 } 413 public event ToolStripGripRenderEventHandler RenderGrip { 414 add { Events.AddHandler (RenderGripEvent, value); } 415 remove {Events.RemoveHandler (RenderGripEvent, value); } 416 } 417 public event ToolStripRenderEventHandler RenderImageMargin { 418 add { Events.AddHandler (RenderImageMarginEvent, value); } 419 remove {Events.RemoveHandler (RenderImageMarginEvent, value); } 420 } 421 public event ToolStripItemRenderEventHandler RenderItemBackground { 422 add { Events.AddHandler (RenderItemBackgroundEvent, value); } 423 remove {Events.RemoveHandler (RenderItemBackgroundEvent, value); } 424 } 425 public event ToolStripItemImageRenderEventHandler RenderItemCheck { 426 add { Events.AddHandler (RenderItemCheckEvent, value); } 427 remove {Events.RemoveHandler (RenderItemCheckEvent, value); } 428 } 429 public event ToolStripItemImageRenderEventHandler RenderItemImage { 430 add { Events.AddHandler (RenderItemImageEvent, value); } 431 remove {Events.RemoveHandler (RenderItemImageEvent, value); } 432 } 433 public event ToolStripItemTextRenderEventHandler RenderItemText { 434 add { Events.AddHandler (RenderItemTextEvent, value); } 435 remove {Events.RemoveHandler (RenderItemTextEvent, value); } 436 } 437 public event ToolStripItemRenderEventHandler RenderLabelBackground { 438 add { Events.AddHandler (RenderLabelBackgroundEvent, value); } 439 remove {Events.RemoveHandler (RenderLabelBackgroundEvent, value); } 440 } 441 public event ToolStripItemRenderEventHandler RenderMenuItemBackground { 442 add { Events.AddHandler (RenderMenuItemBackgroundEvent, value); } 443 remove {Events.RemoveHandler (RenderMenuItemBackgroundEvent, value); } 444 } 445 public event ToolStripItemRenderEventHandler RenderOverflowButtonBackground { 446 add { Events.AddHandler (RenderOverflowButtonBackgroundEvent, value); } 447 remove {Events.RemoveHandler (RenderOverflowButtonBackgroundEvent, value); } 448 } 449 public event ToolStripSeparatorRenderEventHandler RenderSeparator { 450 add { Events.AddHandler (RenderSeparatorEvent, value); } 451 remove {Events.RemoveHandler (RenderSeparatorEvent, value); } 452 } 453 public event ToolStripItemRenderEventHandler RenderSplitButtonBackground { 454 add { Events.AddHandler (RenderSplitButtonBackgroundEvent, value); } 455 remove {Events.RemoveHandler (RenderSplitButtonBackgroundEvent, value); } 456 } 457 public event ToolStripRenderEventHandler RenderStatusStripSizingGrip { 458 add { Events.AddHandler (RenderStatusStripSizingGripEvent, value); } 459 remove {Events.RemoveHandler (RenderStatusStripSizingGripEvent, value); } 460 } 461 public event ToolStripRenderEventHandler RenderToolStripBackground { 462 add { Events.AddHandler (RenderToolStripBackgroundEvent, value); } 463 remove {Events.RemoveHandler (RenderToolStripBackgroundEvent, value); } 464 } 465 public event ToolStripRenderEventHandler RenderToolStripBorder { 466 add { Events.AddHandler (RenderToolStripBorderEvent, value); } 467 remove {Events.RemoveHandler (RenderToolStripBorderEvent, value); } 468 } 469 public event ToolStripContentPanelRenderEventHandler RenderToolStripContentPanelBackground { 470 add { Events.AddHandler (RenderToolStripContentPanelBackgroundEvent, value); } 471 remove {Events.RemoveHandler (RenderToolStripContentPanelBackgroundEvent, value); } 472 } 473 public event ToolStripPanelRenderEventHandler RenderToolStripPanelBackground { 474 add { Events.AddHandler (RenderToolStripPanelBackgroundEvent, value); } 475 remove {Events.RemoveHandler (RenderToolStripPanelBackgroundEvent, value); } 476 } 477 public event ToolStripItemRenderEventHandler RenderToolStripStatusLabelBackground { 478 add { Events.AddHandler (RenderToolStripStatusLabelBackgroundEvent, value); } 479 remove {Events.RemoveHandler (RenderToolStripStatusLabelBackgroundEvent, value); } 480 } 481 #endregion 482 483 #region Private Methods CreateMirrorImage(Image normalImage)484 internal static Image CreateMirrorImage (Image normalImage) 485 { 486 if (normalImage == null) 487 return null; 488 489 Bitmap b = new Bitmap (normalImage); 490 b.RotateFlip (RotateFlipType.RotateNoneFlipX); 491 492 return b; 493 } 494 DrawBackground(Graphics g, Rectangle bounds, Image image, ImageLayout layout)495 private void DrawBackground (Graphics g, Rectangle bounds, Image image, ImageLayout layout) 496 { 497 // Center and Tile don't matter if the image is larger than the control 498 if (layout == ImageLayout.Center || layout == ImageLayout.Tile) 499 if (image.Size.Width >= bounds.Size.Width && image.Size.Height >= bounds.Size.Height) 500 layout = ImageLayout.None; 501 502 switch (layout) { 503 case ImageLayout.None: 504 g.DrawImageUnscaledAndClipped (image, bounds); 505 break; 506 case ImageLayout.Tile: 507 int x = 0; 508 int y = 0; 509 510 while (y < bounds.Height) { 511 while (x < bounds.Width) { 512 g.DrawImageUnscaledAndClipped (image, bounds); 513 x += image.Width; 514 } 515 x = 0; 516 y += image.Height; 517 } 518 break; 519 case ImageLayout.Center: 520 Rectangle r = new Rectangle ((bounds.Size.Width - image.Size.Width) / 2, (bounds.Size.Height - image.Size.Height) / 2, image.Width, image.Height); 521 g.DrawImageUnscaledAndClipped (image, r); 522 break; 523 case ImageLayout.Stretch: 524 g.DrawImage (image, bounds); 525 break; 526 case ImageLayout.Zoom: 527 if (((float)image.Height / (float)image.Width) < ((float)bounds.Height / (float)bounds.Width)) { 528 Rectangle rzoom = new Rectangle (0, 0, bounds.Width, (int)((float)bounds.Width * ((float)image.Height / (float)image.Width))); 529 rzoom.Y = (bounds.Height - rzoom.Height)/ 2; 530 g.DrawImage (image, rzoom); 531 } else { 532 Rectangle rzoom = new Rectangle (0, 0, (int)((float)bounds.Height * ((float)image.Width / (float)image.Height)), bounds.Height); 533 rzoom.X = (bounds.Width - rzoom.Width) / 2; 534 g.DrawImage (image, rzoom); 535 } 536 break; 537 } 538 } 539 DrawRightArrow(Graphics g, Pen p, int x, int y)540 internal static void DrawRightArrow (Graphics g, Pen p, int x, int y) 541 { 542 g.DrawLine (p, x, y, x, y + 6); 543 g.DrawLine (p, x + 1, y + 1, x + 1, y + 5); 544 g.DrawLine (p, x + 2, y + 2, x + 2, y + 4); 545 g.DrawLine (p, x + 2, y + 3, x + 3, y + 3); 546 } 547 DrawDownArrow(Graphics g, Pen p, int x, int y)548 internal static void DrawDownArrow (Graphics g, Pen p, int x, int y) 549 { 550 g.DrawLine (p, x + 1, y, x + 5, y); 551 g.DrawLine (p, x + 2, y + 1, x + 4, y + 1); 552 g.DrawLine (p, x + 3, y + 1, x + 3, y + 2); 553 } 554 DrawSizingGrip(Graphics g, Rectangle rect)555 private void DrawSizingGrip (Graphics g, Rectangle rect) 556 { 557 DrawGripBox (g, rect.Right - 5, rect.Bottom - 5); 558 DrawGripBox (g, rect.Right - 9, rect.Bottom - 5); 559 DrawGripBox (g, rect.Right - 5, rect.Bottom - 9); 560 DrawGripBox (g, rect.Right - 13, rect.Bottom - 5); 561 DrawGripBox (g, rect.Right - 5, rect.Bottom - 13); 562 DrawGripBox (g, rect.Right - 9, rect.Bottom - 9); 563 } 564 DrawGripBox(Graphics g, int x, int y)565 private void DrawGripBox (Graphics g, int x, int y) 566 { 567 g.DrawRectangle (Pens.White, x + 1, y + 1, 1, 1); 568 g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.FromArgb (172, 168, 153)), x, y, 1, 1); 569 } 570 #endregion 571 } 572 } 573