¿Por qué algunos controles tienen propiedades BackgroundImage e Image?

Why some controls like Button or PictureBox tiene ambos BackgroundImage y Image ¿propiedad?

why in case of button both of them is needed? or why in picturebox backgroundimage should be available?

preguntado el 08 de enero de 11 a las 16:01

Do you understand the difference between the two? -

@matt: yes, why in case of button both of them is needed? -

@matt: or why in picturebox backgroundimage should be available? -

2 Respuestas

BackgroundImage es heredado de Control.

Image, En el caso de Button es heredado de ButtonBase.


En general, el BackgroundImage es:

An Image that represents the image to display in the background of the control.

Y la Image will be the one that is on el control.


Why do you need the two?

  • Because you may have margins around a control where you want the background image to show on them.
  • Because sometimes you may use transparencies on the Image and want the background image to show through.

Respondido el 08 de enero de 11 a las 19:01

This is largely because it is there anyway. It gets inherited from the Control class, no extra work is needed to make it functional. In fact, extra work is needed to ocultar it, required for native Windows controls that don't support a background image. Like TreeView:

public class TreeView : Control
{
    [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
    public override Image BackgroundImage
    {
       // etc..
    }
// etc..
}

Note the override keyword and the attributes required to hide it in both the property grid and the editor. Extra work to stop it from working.

Respondido el 09 de enero de 11 a las 02:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.