SoFunction
Updated on 2025-03-08

C# Winform Example Code for Implementing Control Adaptive Parent Container Size

C# Winform Example Code for Implementing Control Adaptive Parent Container Size

Updated: March 24, 2021 10:39:44 Author: lcsyhh
This article mainly introduces the sample code of C# Winform to implement the adaptive parent container size of the control. The sample code is introduced in this article in detail, which has a certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.

In daily development, we often encounter controls that cannot change the size of the parent container and automatically change the location and size of the control. The following is the implementation code

 /// <summary>
  /// Implement the adaptive size position of the control according to the parent container  /// </summary>
  /// <param name="control">Controls for adaptive size positions required</param>  private void ChangeLocationSizeByParent (Control control)
  {
    //Record the size of the parent container to determine whether the control size position is changed because of the change of the parent container or by setting the control size position to change    Size parentOldSize = ;

    PointF locationPF = new PointF();
     = (float) / (float);
     = (float) / (float);
    
    PointF sizePF = new PointF();
     = (float) / (float);
     = (float) / (float);

     += delegate (Object o, EventArgs e) {

      if ( != null&amp;&amp;())
      {
         = (float) / (float);
         = (float) / (float);
        
      }
    };
     += delegate (Object o, EventArgs e) {

      if ( != null &amp;&amp; ())
      {
         = (float) / (float);
         = (float) / (float);
        
      }
    };
     += delegate (Object o, EventArgs e) {
      if ( == null)
      {
        return;
      }
       = (float) / (float);
       = (float) / (float);
       = (float) / (float);
       = (float) / (float);
    };
     += delegate (Object po, EventArgs pe) {

      Control pControl = (Control)po;
      int x = (int)( * );
      int y = (int)( * );
       = new Point(x, y);
      int width = (int)( * );
      int hetght = (int)( * );
       = new Size(width, hetght);
      ();
      parentOldSize = ;
    };
  }

This is the article about the sample code for implementing the size of control adaptive parent container size in C# Winform. For more related content on C# Winform control adaptive parent container size, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!

  • C#
  • Winform
  • container

Related Articles

  • Example of C# method to implement lazy loading using Lazy

    In C#, the Lazy< T>  class is a very useful tool, which can be used to delay loading values. In this article, we will introduce the implementation mechanism and usage of Lazy< T>  in detail, and provide some examples to show its advantages. The article explains it in detail through code examples. Friends who need it can refer to it.
    2024-06-06
  • C# combined with Minio to implement file upload storage and update

    MinIO is an open source object storage server, specially designed for running in a large-scale data storage environment. This article mainly introduces how C# combines Minio to implement file upload storage and updates. If you need it, please refer to it.
    2024-03-03
  • Detailed explanation of instances of WPF ListView binding data in C#

    This article mainly introduces the detailed explanation of the WPF ListView binding data example in C#. I hope this article can help you and let you understand this part of the content. Friends who need it can refer to it.
    2017-10-10
  • Recursive Algorithm of C# Recursive Algorithm

    This article mainly introduces the merge sorting in C# recursive algorithm. Friends who need it can refer to it.
    2016-06-06
  • C# calculates the value of the determinant using the addition method

    This article mainly introduces C#'s use of edge addition method to calculate the value of the determinant. It analyzes the principles and implementation techniques of C#'s edge addition method to calculate the determinant. It has certain reference value. Friends who need it can refer to it.
    2015-08-08
  • Detailed explanation of C# operation of non-persistent memory mapped files

    Data sharing and inter-process communication can be realized between multiple processes by operating memory mapped files that are not mapped to existing files on disk. Let’s learn how C# operates non-persistent memory mapped files.
    2023-12-12
  • C# uses WebClient to implement two ways to download files

    This article mainly introduces C# to use WebClient to download files. It introduces two methods in detail. It is very practical and can be used by friends who need it.
    2017-02-02
  • Set shortcut keys in c#

    Set shortcut keys in c#...
    2007-03-03
  • C# Basic Introduction-Keywords

    This article mainly introduces the basic knowledge of C# - related knowledge of keywords, which has good reference value. Let's take a look with the editor below.
    2017-03-03
  • Detailed analysis of value passing and reference passing in C#

    This article mainly provides a detailed analysis and introduction to reference and value transfer in C#. Friends who need it can come and refer to it. I hope it will be helpful to you.
    2014-01-01

Latest Comments