コード例 #1
0
 public void SetData(Pen pen)
 {
     _pen = new PenWrapper(pen);
     textBoxWidth.Text  = _pen.Width.ToString();
     lblColor.BackColor = _pen.Color;
     updateSample();
 }
コード例 #2
0
 private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
 {
     if (e.Index > 0)
     {
         PenWrapper pw       = comboBox1.Items[e.Index] as PenWrapper;
         bool       selected = ((e.State & DrawItemState.Selected) != DrawItemState.None);
         if (selected)
         {
             e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);
         }
         else
         {
             e.Graphics.FillRectangle(Brushes.White, e.Bounds);
         }
         e.Graphics.FillRectangle(new SolidBrush(pw.Pen.Color), e.Bounds.Left + 2, e.Bounds.Top + 2, 16, 16);
         if (selected)
         {
             e.Graphics.DrawString(pw.ToString(), this.Font, Brushes.White, e.Bounds.Left + (float)20, e.Bounds.Top + (float)2);
         }
         else
         {
             e.Graphics.DrawString(pw.ToString(), this.Font, Brushes.Black, e.Bounds.Left + (float)20, e.Bounds.Top + (float)2);
         }
     }
 }
コード例 #3
0
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             DlgSelectPen dlg = new DlgSelectPen();
             Pen          p   = value as Pen;
             if (p != null)
             {
                 dlg.SetData(p);
             }
             PenWrapper pw = value as PenWrapper;
             if (pw != null)
             {
                 dlg.SetData(pw.Pen);
             }
             if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
             {
                 if (context.PropertyDescriptor.PropertyType.Equals(typeof(Pen)))
                 {
                     return(dlg._pen.Pen);
                 }
                 return(dlg._pen);
             }
         }
     }
     return(value);
 }
コード例 #4
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = comboBox1.SelectedIndex;

            if (n > 0)
            {
                _pen = comboBox1.Items[n] as PenWrapper;
                textBoxWidth.Text  = "1";
                lblColor.BackColor = _pen.Color;
                updateSample();
            }
        }
コード例 #5
0
        private void btColor_Click(object sender, EventArgs e)
        {
            ColorDialog dlg = new ColorDialog();

            dlg.Color = _pen.Color;
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                _pen = new PenWrapper(dlg.Color, _pen.Width);
                lblColor.BackColor = dlg.Color;
                updateSample();
            }
        }
コード例 #6
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // other TypeConverter operations go here...
            //
            PenWrapper pt = value as PenWrapper;

            if (destinationType == typeof(InstanceDescriptor) && pt != null)
            {
                ConstructorInfo ctor = typeof(PenWrapper).GetConstructor(new Type[] { typeof(Color), typeof(float) });
                if (ctor != null)
                {
                    return(new InstanceDescriptor(ctor, new object[] { pt.Color, pt.Width }));
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #7
0
        private void textBoxWidth_TextChanged(object sender, EventArgs e)
        {
            float n = _pen.Width;

            try
            {
                n = Convert.ToSingle(textBoxWidth.Text);
                if (n > 0 && n < 30)
                {
                    _pen = new PenWrapper(_pen.Color, n);
                    updateSample();
                }
            }
            catch
            {
            }
        }
コード例 #8
0
        public override void PaintValue(PaintValueEventArgs e)
        {
            Pen p = e.Value as Pen;

            if (p != null)
            {
                e.Graphics.FillRectangle(new SolidBrush(p.Color), e.Bounds.Left, e.Bounds.Top, 16, 16);
                e.Graphics.DrawString(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} {1}", p.Width, p.Color.Name), _font, Brushes.Black, (float)(e.Bounds.Left + 20), (float)(e.Bounds.Top + 2));
            }
            else
            {
                PenWrapper pw = e.Value as PenWrapper;
                if (pw != null)
                {
                    e.Graphics.FillRectangle(new SolidBrush(pw.Color), e.Bounds.Left, e.Bounds.Top, 16, 16);
                }
                else
                {
                    base.PaintValue(e);
                }
            }
        }