none
i don't understand this code ? RRS feed

  • Question

  •   partial class NQueen
        {
            /// <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.components = new System.ComponentModel.Container();
                this.btnSolve = new System.Windows.Forms.Button();
                this.pnlChess = new System.Windows.Forms.Panel();
                this.label1 = new System.Windows.Forms.Label();
                this.txtN = new System.Windows.Forms.TextBox();
                this.timerStep = new System.Windows.Forms.Timer(this.components);
                this.btnStop = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // btnSolve
                // 
                this.btnSolve.Location = new System.Drawing.Point(208, 36);
                this.btnSolve.Name = "btnSolve";
                this.btnSolve.Size = new System.Drawing.Size(216, 33);
                this.btnSolve.TabIndex = 0;
                this.btnSolve.Text = "Start Solving";
                this.btnSolve.UseVisualStyleBackColor = true;
                this.btnSolve.Click += new System.EventHandler(this.btnSolve_Click);
                // 
                // pnlChess
                // 
                this.pnlChess.Location = new System.Drawing.Point(29, 73);
                this.pnlChess.Name = "pnlChess";
                this.pnlChess.Size = new System.Drawing.Size(550, 550);
                this.pnlChess.TabIndex = 1;
                // 
                // label1
                // 
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(205, 9);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(73, 13);
                this.label1.TabIndex = 2;
                this.label1.Text = "Queen Count:";
                // 
                // txtN
                // 
                this.txtN.Location = new System.Drawing.Point(276, 9);
                this.txtN.Name = "txtN";
                this.txtN.Size = new System.Drawing.Size(148, 20);
                this.txtN.TabIndex = 3;
                // 
                // timerStep
                // 
                this.timerStep.Interval = 300;
                this.timerStep.Tick += new System.EventHandler(this.timerStep_Tick);
                // 
                // btnStop
                // 
                this.btnStop.Location = new System.Drawing.Point(29, 36);
                this.btnStop.Name = "btnStop";
                this.btnStop.Size = new System.Drawing.Size(147, 33);
                this.btnStop.TabIndex = 4;
                this.btnStop.Text = "Stop Solving";
                this.btnStop.UseVisualStyleBackColor = true;
                this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
                // 
                // NQueen
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(604, 637);
                this.Controls.Add(this.btnStop);
                this.Controls.Add(this.txtN);
                this.Controls.Add(this.label1);
                this.Controls.Add(this.pnlChess);
                this.Controls.Add(this.btnSolve);
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
                this.MaximizeBox = false;
                this.Name = "NQueen";
                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                this.Text = "N Queen Problem - BFS";
                this.ResumeLayout(false);
                this.PerformLayout();

            }

            #endregion

            private System.Windows.Forms.Button btnSolve;
            private System.Windows.Forms.Panel pnlChess;
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.TextBox txtN;
            private System.Windows.Forms.Timer timerStep;
            private System.Windows.Forms.Button btnStop;
        }
    }
    Thursday, December 13, 2018 7:12 PM

All replies

  • This code appears to be from the .designer.cs file generated by Visual Studio when you design a form on screen.

    Essentially, what it does is that it creates an instance of every control that you added to the designer, and add those instances to the Controls collection of the form.

    When it is executed at runtime, the result is that each of these controls is rendered on screen by the Form class.

    If your question is about some specific part in the code, please refine it a bit (for instance, 'what means "partial"', or 'what is #region' or 'why do we have all the private declarations at the bottom', etc.)

    • Proposed as answer by Ante Meridian Thursday, December 13, 2018 10:17 PM
    Thursday, December 13, 2018 9:44 PM
    Moderator
  • Hi Esraa_Mohamed,

    Thank you for posting here.

    The code you provided is from Form.Designer.cs file.

    Form.Designer.cs is the design code of your screen, which is usually generated automatically by the system or manually.

    In general, you do not need to the change for the code you provided. I description button in the code for reference.

    1. Define a button btnSolve.

      private System.Windows.Forms.Button btnSolve;

    2. Create instance of a button btnSolve.

    this.btnSolve = new System.Windows.Forms.Button();

    3. Assign the value of button btnSolve (like location, size, name, etc.).

     this.btnSolve.Location = new System.Drawing.Point(208, 36);
                this.btnSolve.Name = "btnSolve";
                this.btnSolve.Size = new System.Drawing.Size(216, 33);
                this.btnSolve.TabIndex = 0;
                this.btnSolve.Text = "Start Solving";
                this.btnSolve.UseVisualStyleBackColor = true;

    4. Add button btnSolve to the control of the form.

    this.Controls.Add(this.btnSolve);


    5. Register button event for button btnSolve.

    this.btnSolve.Click += new System.EventHandler(this.btnSolve_Click);

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Friday, December 21, 2018 1:42 AM
    Monday, December 17, 2018 7:54 AM
    Moderator