This documentation is archived and is not being maintained.

Control.ScaleCore Method

Performs the work of scaling the entire control and any child controls.

[Visual Basic]
Protected Overridable Sub ScaleCore( _
   ByVal dx As Single, _
   ByVal dy As Single _
)
[C#]
protected virtual void ScaleCore(
 float dx,
 float dy
);
[C++]
protected: virtual void ScaleCore(
 float dx,
 float dy
);
[JScript]
protected function ScaleCore(
   dx : float,
 dy : float
);

Parameters

dx
The ratio by which to scale the control horizontally.
dy
The ratio by which to scale the control vertically.

Remarks

This ScaleCore method uses the dx and dy parameter values to scale both the height and width of the control independantly. To keep the height and width of the control in proportion to their current size, use the same value for the dx and dy parameters, or call the version of the Scale method that takes one parameter.

You would typically override this method to change the scaling behavior of the control.

Notes to Inheritors:  When overriding ScaleCore in a derived class, be sure to call the base class's ScaleCore method so that the control is resized properly.

Example

[Visual Basic, C#, C++] The following example overrides the ScaleCore method to ensure that the derived control and its child controls are scaled. This example assumes you have a class that is either directly or indirectly derived from the Control class.

[Visual Basic] 
Protected Overrides Sub ScaleCore(dx As Single, dy As Single)
   ' Scale all child controls.
   Me.SuspendLayout()
   
   Dim myClientSize As Size = Me.ClientSize
   myClientSize.Height = CInt(myClientSize.Height * dx)
   myClientSize.Width = CInt(myClientSize.Width * dy)
   
   ' Scale the child controls because
   ' MyBase.ScaleCore was not called. 
   Dim childControl As Control
   For Each childControl In  Me.Controls
      childControl.Scale(dx, dy)
   Next childControl
   Me.ResumeLayout()
   
   Me.ClientSize = myClientSize
End Sub

[C#] 
protected override void ScaleCore(float dx, float dy)
{
   // Scale all child controls.
   this.SuspendLayout();

   Size myClientSize = this.ClientSize;
   myClientSize.Height = (int)(myClientSize.Height * dx);
   myClientSize.Width = (int)(myClientSize.Width * dy);
   
   /* Scale the child controls because
    * base.ScaleCore was not called. */
   foreach(Control childControl in this.Controls)
   {
      childControl.Scale(dx, dy);      
   }
   this.ResumeLayout();

   this.ClientSize = myClientSize;
}

[C++] 
protected:
   void ScaleCore(float dx, float dy) {
      // Scale all child controls.
      this->SuspendLayout();

      System::Drawing::Size myClientSize = this->ClientSize;
      myClientSize.Height = (int)(myClientSize.Height * dx);
      myClientSize.Width = (int)(myClientSize.Width * dy);

      /* Scale the child controls because
      * UserControl::ScaleCore was not called. */
      System::Collections::IEnumerator* myEnum = this->Controls->GetEnumerator();
      while (myEnum->MoveNext()) {
         Control* childControl = __try_cast<Control*>(myEnum->Current);

         childControl->Scale(dx, dy);
      }
      this->ResumeLayout();

      this->ClientSize = myClientSize;
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | Scale

Show: