No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Adapter la taille des composants GUI en C#

Nous avons vu comment réaliser une petite application graphique en C#, nous allons maintenant voir comment adapter la taille d'un composant à la taille de la fenêtre. En effet, si nous agrandissons la fenêtre, le composant que nous y avions placé conserve sa taille initiale.

Si nous cliquons sur le composant dans la fenêtre en mode design, nous pouvons en afficher les propriétés.

Dans la partie Layout de l'onglet properties, nous allons modifier la valeur de l'attribut Anchor. Si nous activons les 4 parties dans l'image qui apparaît alors, la propriété correspondra à Top, Bottom, Left, Right, ce qui revient à dire que le composant doit s'étirer selon ces 4 directions pour s'adapter à la taille de la fenêtre.

Voici le code qui est généré pour notre composant TreeView :

  1. this.classInfoTreeView.Anchor = ((System.Windows.Forms.AnchorStyles) (((
  2. ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom )
  3. | System.Windows.Forms.AnchorStyles.Left )
  4. | System.Windows.Forms.AnchorStyles.Right )
  5. )
  6. );

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 04/10/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/csharp-gui-adapter-taille.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.