【问题标题】:How to set image control properties that belong to a class?如何设置属于某个类的图像控件属性?
【发布时间】:2013-02-05 15:09:28
【问题描述】:

我有一个图像控件作为类的属性之一。

    public Image ImageControl
    {
        get
        {
            return _imgControl;
        }

        set
        {
            _imgControl = value;
        }

    }

在类构造函数中,使用this是否正确

        ImageControl.Width = bi.PixelWidth;
        ImageControl.Height = bi.PixelHeight;
        ImageControl.Source = bi;

还是这个?

        _imgControl.Width = bi.PixelWidth;
        _imgControl.Height = bi.PixelHeight;
        _imgControl.Source = bi;

我只是想知道因为ImageControl本身是一个包含属性的控件,它如何影响_imageControl的值?

【问题讨论】:

    标签: c# image oop class controls


    【解决方案1】:

    ImageControl 属性只返回_imgControl,因此当您使用前者时,您实际上是在使用后者。在您的情况下,没有区别。虽然总体上回答了您的问题,但我更喜欢在构造函数中使用字段语法,因为该属性可能会影响可能尚未初始化的当前实例的状态。

    【讨论】:

      猜你喜欢
      • 2017-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多