12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace SmartCoalApplication
- {
- internal class IconBox : UserControl
- {
- private Bitmap renderSurface = null;
- private Bitmap icon = null;
- public Bitmap Icon
- {
- get
- {
- return icon;
- }
- set
- {
- if (value == null)
- {
- value = new Bitmap(1, 1);
- using (Graphics g = Graphics.FromImage(value))
- {
- g.Clear(Color.Transparent);
- }
- }
- icon = value;
- if (renderSurface != null)
- {
- renderSurface.Dispose();
- }
- renderSurface = null;
- Invalidate();
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- e.Graphics.Clear(this.BackColor);
- Rectangle srcBounds = new Rectangle(new Point(0, 0), this.icon.Size);
- Rectangle dstBounds = new Rectangle(new Point(0, 0), this.ClientSize);
- e.Graphics.DrawImage(this.Icon, dstBounds, srcBounds, GraphicsUnit.Pixel);
- base.OnPaint(e);
- }
- public IconBox()
- {
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
- // This call is required by the Windows.Forms Form Designer.
- InitializeComponent();
- this.ResizeRedraw = true;
- }
- #region Component Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- }
- #endregion
- }
- }
|