Property: Show / Hide controls within a User Control

0

I am trying to create a Categoría for controles (components) within a Control de Usuario so that they are reflected in Propiedades of Visual Studio, to make visible / not visible a PictureBox , between other options, I did it like this:

    bool _pictureBoxVisible = true;
    Image _imagenPictureBox = Properties.Resources.Laimagen;
    Color _colorFondoPanel = Color.Transparent;
    Color _colorLetraLabel = Color.White;
    Font _letraLabel = new Font("Tahoma", 14, FontStyle.Regular, GraphicsUnit.Pixel);

    [Category("Configuración Control")]
    [DefaultValue(true)]
    [DesignOnly(true)]
    [Description("Si es Verdadero (True), se muestra. Si es Falso (False) no mostrarlo.")]
    [DisplayName("Mostrar/Ocultar")]
    public bool PictureBoxVisible
    {
        get { return _pictureBoxVisible; }
        set 
        {
            _pictureBoxVisible = value;

            if (_pictureBoxVisible)
                this.picturebox_imagen.Visible = true; 
            else
                this.picturebox_imagen.Visible = false; 
        }
    }

  

Problems to solve

     

1- The property comes out correctly in the properties of the design, but when I change the property in the two controls, one works and another does not, and the design is shown correctly, but when the application is executed the% is shown picturebox even if the value of the property is false How do I solve it?

I would also like to expose the following properties in the same category:

  • 2: Move the PictureBox to the right side corner of the panel, when the panel changes its Resize .
  • 3: The Background Color of the Panel (BackColor)
  • 4: Color of the Letter of the Label (ForeColor)
  • 5: Source of the Label (Font)
  • 6: The Picture and / or BackgroundImage of the PictureBox

But I do not know how to expose those other properties so that they come out like this:

  

How do I agree to create those system properties?

Environment: Visual Studio & .NET Netframework 4

    
asked by J. Rodríguez 12.01.2018 в 19:16
source

1 answer

0
  

In the end I have achieved it. Thanks @gbianchi for helping me solve the%% and 1

points

Points resolved:

Point 1: Removing this: 2 and [DefaultValue(true)]

Point 2: Changing the Property [DesignOnly(true)] to Dock .

Point 3: Color Background Panel:

    Color _color_fondo_panel = Color.Transparent;

    [Category("Panel Plegable")]
    [Description("Color de Fondo del Panel.")]
    [DisplayName("Color Fondo Panel")]
    public Color ColorFondoPanel
    {
        get
        {
            return _color_fondo_panel;
        }
        set
        {
            _color_fondo_panel = value;
            panel_titulo.BackColor = _color_fondo_panel;
        }
    }

Point 4: Color Letter Label:

Color _color_titulo_menu = Color.Black;

[Category("Panel Plegable")]
[Description("Color del Título del Menú.")]
[DisplayName("Color Título Menú")]
public Color ColorTituloMenu
{
     get
     {
        return _color_titulo_menu;
     }
     set
     {
        _color_titulo_menu = value;
        label_titulo.ForeColor = _color_titulo_menu;
     }
}

Point 5: Source of the Label:

    Font _fuente_titulo_menu = new Font("Microsoft Sans Serif", 8, FontStyle.Bold, GraphicsUnit.Pixel);

    [Category("Panel Plegable")]
    [Description("Fuente del Título del Menú.")]
    [DisplayName("Fuente Título Menú")]
    public Font FuenteTituloMenu
    {
        get
        {
            return _fuente_titulo_menu;
        }
        set
        {
            _fuente_titulo_menu = value;
            label_titulo.Font = _fuente_titulo_menu;
        }
    }

Point 6: Image Picturebox Background:

    Image _imagen_categoria_menu = Properties.Resources.Myimagen;

    [Category("Panel Plegable")]
    [Description("Imagen de Fondo Categoría Menu.")]
    [DisplayName("Imagen Categoría Menú")]
    public Image ImagenCategoriaMenu
    {
        get
        {
            return _imagen_categoria_menu;
        }
        set
        {
            _imagen_categoria_menu = value;
            pictureBox_imagen_categoria.BackgroundImage = _imagen_categoria_menu;
        }
    }

Final Result:

    
answered by 12.01.2018 / 22:57
source