-1
Following a book, I created a project windows forms application
. I put in the form
one textBox
and a button
. In the onclick
of button
taken the value of textBox
and the attribute to the text of form
.
The book asks you to look at the method InitializeComponents()
of form
. So I came across the method SuspendLayout()
. I went to the method to see what he was doing and there was no code in it. But researching, from what I understand, when it is added several controls (I understand how buttons
, textBox
, etc.) the SuspendLayout()
takes care to assemble the layout after processing all of them, making the application perform better. What I find strange is the method not having code, where is this code after all? It is not the first time that I enter 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;
}
Give more context, show code. It’s a class
partial
?– Maniero
I do not know what is partial, I will search. But I added the code in the post.
– HeyJoe
Where is the empty method?
– Maniero
Where did you look at the code of this method? It is part of . Net Framework, more specifically from the Control class of Windowsforms, the source code you can see here: https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/Winforms/Control.Cs,12393
– Leandro Godoy Rosa
I think his doubt is when we navigate through some method/object of
framework
(F12 in VS) and it is shown what thatframework
implements– Barbetta
If it is with F12 by default VS.Net shows only the metadata, then only the method names appear and not the source code
– Leandro Godoy Rosa
What I don’t understand is a method of doing something, in the case of Suspendlayout(), and having no code inside.
– HeyJoe
@Heyjoe look at the link I passed in my first comment
– Leandro Godoy Rosa
@Maniero the Suspendlayout() method is within the Initializecomponents() method, I put the code in the post. And this Suspendlayout() method is in the public class Control class.
– HeyJoe
Also I don’t know what metadata is. I saw the link, it seems that the codes are there on that site, so VS searches the codes there? Now it makes sense.
– HeyJoe
No, inside the
InitializeComponents()
is just calling theSuspendLayout()
, the method itself is not there.– Maniero
@Maniero yes, that’s what I meant, but I didn’t put it in the right words.
– HeyJoe