Пример #1
0
            /// <summary>
            /// Initialize a new instance of this class
            /// </summary>
            public SmileyPanel()
            {
                base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                base.SetStyle(ControlStyles.StandardClick, true);
                base.BackColor = Color.Transparent;
                _Items         = new List <SmileyItem>();
                _Tooltip       = new ToolTip();

                var x = 3;
                var y = 3;

                var width  = 6 + (ItemsPerLine * OneItemSize.Width);
                var height = 6 + Convert.ToInt32(Math.Ceiling((double)_SmileyDatas.Count / (double)ItemsPerLine)) * OneItemSize.Height;

                Size = new Size(width, height);
                var pos = 0;

                foreach (string key in _SmileyDatas.Keys)
                {
                    SmileyInfo data = _SmileyDatas[key];
                    SmileyItem item = new SmileyItem
                    {
                        Data   = data,
                        Image  = _SmileyImages.Images[data.ImageIndex],
                        Bounds = new Rectangle(x, y, OneItemSize.Width, OneItemSize.Height)
                    };
                    pos++;

                    if (pos == ItemsPerLine)
                    {
                        y  += OneItemSize.Height;
                        x   = 3;
                        pos = 0;
                    }
                    else
                    {
                        x += OneItemSize.Width;
                    }
                    _Items.Add(item);
                }
            }
Пример #2
0
            /// <summary>
            /// Draws an item
            /// </summary>
            /// <param name="g"></param>
            /// <param name="item"></param>
            /// <param name="pt"></param>
            /// <param name="normal"></param>
            /// <param name="highlight"></param>
            private void DrawItem(Graphics g, SmileyItem item, Point pt, Pen normal, Pen highlight)
            {
                var rct = item.Bounds;

                rct.Inflate(-1, -1);
                if (item.Bounds.Contains(pt))
                {
                    using (var br = new LinearGradientBrush(item.Bounds, Color.MistyRose, Color.Yellow, LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(br, rct);
                    }
                    g.DrawRectangle(highlight, rct);
                    rct.Inflate(-2, -2);
                    g.DrawImage(item.Image, rct.X, rct.Y, 19, 19);
                }
                else
                {
                    g.DrawRectangle(normal, rct);
                    rct.Inflate(-2, -2);
                    g.DrawImage(item.Image, rct.X, rct.Y, 19, 19);
                }
            }