Page #126 (Causing Text to Appear from Underneath a Control)

 

Removing Installed Controls

Recall that you remove a control by highlighting the control, right-clicking it, and choosing Delete when the context menu appears. If you have created event handlers for controls that you are deleting, the text in the source code may or may not disappear. If the event handler has no code inside the curly brackets, then the event handler code will probably disappear. But if the programmer has typed anything into the event handler, it will remain when the control is deleted. As far as the project is concerned at this time, the event handler code has nothing to do with the project! If you are concerned that the handler code may still be included in the project, then comment the code out by placing /* at the start of the method and */ at the end. This way, if the project produces error statements the next time the project is compiled, you will know that the method is not removable. Simply remove the /* and */ to keep the compiler happy.

IMPORTANT  

The biggest mistake-maker in the vicinity of the IDE window template is the mouse , and we know who controls the mouse. Since all controls can be dragged and dropped it is easy to mistakenly drop one control one top of another, and then all kinds of bad things happen. When this happens, the control underneath absorbs the control that is erroneously dropped on top of it (if the underneath control is larger in size than the control on top), and sorting out this mess may require the removal of some controls and replacement with new controls.

The listing for LostControls is given below.

LostControls (LC) Listing

 Form1.cs: LC002:        using System; LC003:        using System.Collections.Generic; LC004:        using System.ComponentModel; LC005:        using System.Data; LC006:        using System.Drawing; LC007:        using System.Windows.Forms; LC009:        namespace LostControls LC010:        { LC011:          partial class Form1 : Form LC012:          { LC013:            public Form1() LC014:            {InitializeComponent(); } //-----------------------------------------------------------------------------------------// LC020:            private void button1_Click(object sender, EventArgs e) LC021:            { // Quit. LC022:              Close(); LC023:            } LC024:          } LC025:        } //=========================================================================================// Form1.Designer.cs: LC050:        namespace LostControls LC051:        { LC052:          partial class Form1 LC053:          {                   // Required designer variable. LC054:            private System.ComponentModel.IContainer components = null;                   // Clean up any resources being used. LC055:            protected override void Dispose(bool disposing) LC056:            { LC057:              if (disposing && (components != null)) components.Dispose(); LC058:              base.Dispose(disposing); LC059:            } LC060:            #region Windows Form Designer generated code                   // Required method for Designer support. LC061:            private void InitializeComponent() LC062:            { LC063:              this.label1 = new System.Windows.Forms.Label(); LC064:              this.panel1 = new System.Windows.Forms.Panel(); LC065:              this.button1 = new System.Windows.Forms.Button(); LC066:              this.label2 = new System.Windows.Forms.Label(); LC067:              this.panel1.SuspendLayout(); LC068:              this.SuspendLayout();                     //                     // label1                     // LC069:              this.label1.AutoSize = true; LC070:              this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F,                       System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point,                       ((byte)(0))); LC071:              this.label1.Location = new System.Drawing.Point(190, 20); LC072:              this.label1.Name = "label1"; LC073:              this.label1.Size = new System.Drawing.Size(120, 24); LC074:              this.label1.TabIndex = 0; LC075:              this.label1.Text = "Lost Controls";                     //                     // panel1                     // LC076:              this.panel1.BackColor = System.Drawing.SystemColors.Control; LC077:              this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; LC078:              this.panel1.Controls.Add(this.label2); LC079:              this.panel1.Location = new System.Drawing.Point(100, 60); LC080:              this.panel1.Name = "panel1"; LC081:              this.panel1.Size = new System.Drawing.Size(300, 150); LC082:              this.panel1.TabIndex = 1;                     //                     // button1                     // LC083:              this.button1.Location = new System.Drawing.Point(16, 232); LC084:              this.button1.Name = "button1"; LC085:              this.button1.Size = new System.Drawing.Size(75, 25); LC086:              this.button1.TabIndex = 2; LC087:              this.button1.Text = "Quit"; LC088:              this.button1.Click += new System.EventHandler(this.button1_Click);                     //                     // label2                     // LC089:              this.label2.AutoSize = true; LC090:              this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F,                       System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,                       ((byte)(0))); LC091:              this.label2.Location = new System.Drawing.Point(85, 96); LC092:              this.label2.Name = "label2"; LC093:              this.label2.Size = new System.Drawing.Size(150, 17); LC094:              this.label2.TabIndex = 0; LC095:              this.label2.Text = "Label on Top of Panel 1";                     //                     // Form1                     // LC096:              this.AutoScaleDimensions = new System.Drawing.SizeF(5F, 13F); LC097:              this.ClientSize = new System.Drawing.Size(484, 272); LC098:              this.Controls.Add(this.button1); LC099:              this.Controls.Add(this.panel1); LC100:              this.Controls.Add(this.label1); LC101:              this.Name = "Form1"; LC102:              this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; LC103:              this.Text = "Lost Controls"; LC104:              this.panel1.ResumeLayout(false); LC105:              this.panel1.PerformLayout(); LC106:              this.ResumeLayout(false); LC107:              this.PerformLayout(); LC108:            } LC109:            #endregion LC110:            private System.Windows.Forms.Label label1; LC111:            private System.Windows.Forms.Panel panel1; LC112:            private System.Windows.Forms.Button button1; LC113:            private System.Windows.Forms.Label label2; LC114:          } LC115:        } 
 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net