共用方式為


ControlAdapter.Control 屬性

定義

取得控制項的參考 (指控制項配置器附加的控制項)。

protected:
 property System::Web::UI::Control ^ Control { System::Web::UI::Control ^ get(); };
[System.ComponentModel.Browsable(false)]
protected System.Web.UI.Control Control { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Control : System.Web.UI.Control
Protected ReadOnly Property Control As Control

屬性值

Control

Control 所附加的 ControlAdapter

屬性

範例

下列程式碼範例示範如何從 Control 類別衍生自訂控制項,然後建立繼承自 類別的 ControlAdapter 對應配接器。 配接器會 Control 覆寫 屬性,並傳回控制項的強型別參考。

#using <System.Web.Mobile.dll>
#using <System.dll>
#using <System.Web.dll>

using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::Adapters;
using namespace System::Web::UI::WebControls;

public ref class CustomControl: public Control{};

public ref class CustomControlAdapter: public ControlAdapter
{
public:

   property System::Web::UI::Control^ Control 
   {
      // Return a strongly-typed reference to your custom control.
      System::Web::UI::Control^ get()
      {
         return (CustomControl^)ControlAdapter::Control;
      }
   }
   // Override other ControlAdapter members, as necessary. 
};
using System;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;

public class CustomControl : Control
{
    // Add your custom control code.
}

public class CustomControlAdapter : ControlAdapter
{
    // Return a strongly-typed reference to your custom control.
    public new CustomControl Control
    {
        get
        {
            return (CustomControl)base.Control;
        }

        // Override other ControlAdapter members, as necessary. 
    }
}
Imports System.Web.UI
Imports System.Web.UI.Adapters
Imports System.Web.UI.WebControls

Public Class CustomControl
    Inherits Control

    ' Add your custom control code.

End Class

Public Class CustomControlAdapter
    Inherits ControlAdapter

    ' Return a strongly-typed reference to your custom control.
    Public Shadows ReadOnly Property Control() As CustomControl
        Get
            Return CType(MyBase.Control, CustomControl)
        End Get
    End Property

    ' Override other ControlAdapter member as necessary. 

End Class

備註

當衍生控制項配接器附加至控制項時,.NET Framework會呼叫特定配接器成員,而不是控制項成員。

給繼承者的注意事項

當您繼承自 ControlAdapter 類別時,至少應該實 Control 作 屬性來傳回控制項的強型別實例,如 Example 區段所示。

適用於

另請參閱