Ejemplo n.º 1
0
 public void AddColorItem(ColorItem item, bool needRefresh)
 {
     if (needRefresh)
     {
         item.Position = 0.5f;
     }
     _colorItems.Insert(1, item);
     if (needRefresh)
     {
         ReCreateBrush();
     }
 }
Ejemplo n.º 2
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (_isDraging && _selectedColorItem != null)
     {
         if (e.X <= 0 || e.X >= ClientSize.Width)
         {
             return;
         }
         _selectedColorItem.Position = e.X / (float)Width;
         AdjustOrderOfColorItems();
         ReCreateBrush();
         if (OnMoveColorBarHandler != null)
         {
             string vstring = string.Empty;
             if (MaxValue > MinValue)
             {
                 int   span         = MaxValue - MinValue;
                 float pixelPerSpan = span / (float)Width;
                 int   v            = (int)(e.X * pixelPerSpan);
                 vstring = v.ToString();
             }
             OnMoveColorBarHandler(this, vstring, _bitmap.GetPixel(e.X, Height / 2));
         }
         return;
     }
     if (_colorItems == null || _colorItems.Count == 0)
     {
         return;
     }
     foreach (ColorItem it in _colorItems)
     {
         if (it.Bounds == null)
         {
             continue;
         }
         if (it.Bounds.IsVisible(e.Location))
         {
             _selectedColorItem = it;
             Invalidate();
             return;
         }
     }
     _selectedColorItem = null;
     Invalidate();
 }
Ejemplo n.º 3
0
 protected override void OnPaint(PaintEventArgs e)
 {
     if (_brush == null)
     {
         return;
     }
     _bitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
     using (Graphics g = Graphics.FromImage(_bitmap))
     {
         g.FillRectangle(_brush, 0, barTopBank + barMaxHeight, Width, Height - 2 * barTopBank - 30);
         if (IsDrawScales)
         {
             if (MaxValue > MinValue)
             {
                 int   span         = MaxValue - MinValue;
                 float pixelPerSpan = span / (float)Width;
                 int   pixelSpan    = 40;
                 int   beginX       = 0;
                 float v            = MinValue;
                 g.DrawLine(Pens.Blue, 0, Height - 6, Width, Height - 6);
                 while (beginX < Width)
                 {
                     g.DrawLine(Pens.Blue, beginX, Height - 6, beginX, Height - 12);
                     int intv = (int)v;
                     g.DrawString(intv.ToString(), Font, Brushes.Blue, beginX, Height - 17);
                     beginX += pixelSpan;
                     v      += (pixelSpan * pixelPerSpan);
                 }
             }
         }
     }
     e.Graphics.DrawImage(_bitmap, 0, 0);
     if (_colorItems.Count == 0)
     {
         return;
     }
     if (_colorItems.Count < 3)
     {
         return;
     }
     for (int i = 1; i < _colorItems.Count - 1; i++)
     {
         ColorItem it = _colorItems[i];
         int       x  = (int)(Width * it.Position);
         it.X = x;
         GraphicsPath path = new GraphicsPath();
         path.AddLine(x - barHalfWidth, barTopBank, x + barHalfWidth, barTopBank);
         path.AddLine(x + barHalfWidth, barTopBank, x + barHalfWidth, barTopBank + barMinHeight);
         path.AddLine(x + barHalfWidth, barTopBank + barMinHeight, x, barTopBank + barMaxHeight);
         path.AddLine(x, barTopBank + barMaxHeight, x - barHalfWidth, barTopBank + barMinHeight);
         path.AddLine(x - barHalfWidth, barTopBank + barMinHeight, x - barHalfWidth, barTopBank);
         it.Bounds = path;
         if (_selectedColorItem != null && it.Equals(_selectedColorItem))
         {
             e.Graphics.FillPath(Brushes.Red, path);
             e.Graphics.DrawPath(Pens.Black, path);
         }
         else
         {
             e.Graphics.FillPath(Brushes.LightSkyBlue, path);
             e.Graphics.DrawPath(Pens.Black, path);
         }
     }
 }
Ejemplo n.º 4
0
 public void AddColorItem(ColorItem item)
 {
     ucLinearColorRampEditor1.AddColorItem(item);
 }
Ejemplo n.º 5
0
 public void AddColorItem(ColorItem item)
 {
     ucColorPanel1.AddColorItem(item, true);
 }
Ejemplo n.º 6
0
        private void btnInsertColor_Click(object sender, EventArgs e)
        {
            ColorItem item = new ColorItem(0f, txtColor.BackColor);

            ucColorPanel1.AddColorItem(item, true);
        }