ImageTooltip.cs (2125B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // The Command & Conquer Map Editor and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // The Command & Conquer Map Editor and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 using System; 16 using System.Drawing; 17 using System.Windows.Forms; 18 19 namespace MobiusEditor.Controls 20 { 21 public partial class ImageTooltip : ToolTip 22 { 23 public Size MaxSize { get; set; } = Size.Empty; 24 25 public ImageTooltip() 26 { 27 InitializeComponent(); 28 29 OwnerDraw = true; 30 Popup += ImageTooltip_Popup; 31 Draw += ImageTooltip_Draw; 32 } 33 34 private void ImageTooltip_Popup(object sender, PopupEventArgs e) 35 { 36 if (e.AssociatedControl.Tag is Image image) 37 { 38 var size = image.Size; 39 if (MaxSize.Width > 0) 40 { 41 size.Width = Math.Min(MaxSize.Width, size.Width); 42 } 43 if (MaxSize.Height > 0) 44 { 45 size.Height = Math.Min(MaxSize.Height, size.Height); 46 } 47 48 e.ToolTipSize = size; 49 } 50 else 51 { 52 e.Cancel = true; 53 } 54 } 55 56 private void ImageTooltip_Draw(object sender, DrawToolTipEventArgs e) 57 { 58 if (e.AssociatedControl.Tag is Image image) 59 { 60 e.Graphics.DrawImage(image, e.Bounds); 61 } 62 } 63 } 64 }