Method without code

-1

Following a book, I created a windows forms application project. I put in form textBox and button . In onclick of button I get the value of textBox and the assignment to the text of form .

The book asks you to look at the InitializeComponents() of form method. So I came across the SuspendLayout() method. I went to the method to see what he did and there was no code in it. But researching, as I understand it, when you add multiple controls (I mean buttons , textBox , etc.) SuspendLayout() takes care of assembling the layout after rendering all of them, making the application better performance. What I find strange is the method not having code, where is this code anyway? This is not the first time I have entered a method and there is nothing inside.

partial class frmMain
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(105, 95);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(90, 67);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 22);
            this.textBox1.TabIndex = 1;
            // 
            // frmMain
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(282, 253);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button1);
            this.Name = "frmMain";
            this.Text = "frmMain";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox1;
    }
    
asked by anonymous 09.05.2018 / 15:43

2 answers

1

As leandro mentioned in the comments, I believe you are trying to see the method code by pressing F12 and this appears:

Asshownintheimage,frommetadatathismeansthatthemethodiscomingfromthelibraryalreadycompiled(inthecaseSystem.Windows.Forms.dll)andyouhaveaccesstothemethodsignatures,butnottotheircode.

Tofindoutwhatthemethoddoes,youhavetoaccesstheMicrosoftdocumentation(thatis,whomadethelibrary): link

And no, visual studio does not search for any site codes. You can add packages by nuget, etc., but there is a command that you have to execute.

    
09.05.2018 / 16:29
2

When you say that the method has no code, I imagine you should have navigated to the method definition using Visual Studio (F12 in the default shortcuts setting) and found no logic there.

You can configure Visual Studio to display (and even debug the Framework source). Another way to inspect the source code of the .NET Framework implementation is through Microsoft's "Source Source" website, which allows browsing and searching the source.

In the case of SuspendLayout (), you can see more details of implementing the method in the Control class at this link link

Your conclusions about SuspendLayout () are correct. When you invoke SuspendLayout (), the control's layout logic processing is interrupted, that is, you can make multiple layout changes (size, positioning, color, docking, anchoring, etc.) without rendering the control whenever some property is changed. When invoking the ResumeLayout () the changes are made all at once.

I hope I have helped to clarify.

Abs

    
09.05.2018 / 16:43