Autor Tema: Ayuda: como agregarle label dinamico a una clase de objeto en C#  (Leído 2266 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado SiKa

  • -^- Elite Silver -^-
  • The Communiter-
  • *
  • Mensajes: 2549
  • .
Señores tengo una clase que dibuja un control datetimepicker, con algunas propiedades extras.

El mambo es que yo quiero anteponerle un label a mi objeto, pero no se como agregarselo a la clase.  Sera que algun programador me da ideas como agregarlo??

La idea es que en la propiedad del objeto necesito que aparesca una propiedad "LABEL" y asi poder editarla en tiempo de diseño, al momento de utilizar el objeto en alguna forma me despreocupo de ubicar su respectivo  label .


Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms.VisualStyles;

namespace DateTimePickerWithBackColor
{
    /// <summary>
    ///     A derivation of DateTimePicker allowing to change background color
    /// </summary>
    class BCDateTimePicker : System.Windows.Forms.DateTimePicker
    {
        private Color _backDisabledColor;

        public BCDateTimePicker() : base()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            _backDisabledColor = Color.FromKnownColor(KnownColor.Control);
        }

        /// <summary>
        ///     Gets or sets the background color of the control
        /// </summary>
        [Browsable(true)]
        public override Color BackColor
        {
            get { return base.BackColor; }
            set { base.BackColor = value; }
        }

        /// <summary>
        ///     Gets or sets the background color of the control when disabled
        /// </summary>
        [Category("Appearance"), Description("The background color of the component when disabled")]
        [Browsable(true)]
        public Color BackDisabledColor
        {
            get { return _backDisabledColor; }
            set { _backDisabledColor = value; }
        }


        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            //Graphics g = e.Graphics;
           
            //The dropDownRectangle defines position and size of dropdownbutton block,
            //the width is fixed to 17 and height to 16. The dropdownbutton is aligned to right
            Rectangle dropDownRectangle = new Rectangle(ClientRectangle.Width - 17, 0, 17, 16);
            Brush bkgBrush;
            ComboBoxState visualState;

            //When the control is enabled the brush is set to Backcolor,
            //otherwise to color stored in _backDisabledColor
            if (this.Enabled) {
                 bkgBrush = new SolidBrush(this.BackColor);
                 visualState = ComboBoxState.Normal;
            }
            else {
                bkgBrush = new SolidBrush(this._backDisabledColor);
                visualState = ComboBoxState.Disabled;
            }

            // Painting...in action

            //Filling the background
            g.FillRectangle(bkgBrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
           
            //Drawing the datetime text
            g.DrawString(this.Text, this.Font, Brushes.Black, 0, 2);

            //Drawing the dropdownbutton using ComboBoxRenderer
            ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, visualState);

            g.Dispose();
            bkgBrush.Dispose();
        }
    }
}