第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# 設(shè)計模式和代碼頁面的切換疑問?

C# 設(shè)計模式和代碼頁面的切換疑問?

陪伴而非守候 2018-12-06 22:01:30
這樣一段代碼為什么設(shè)計頁面要報錯? ? 1 using System.Windows.Forms; 2 using System.Collections.Generic; 3 namespace WFAListViewer 4 { 5 partial class Form1 6 { 7 /// 8 /// Required designer variable. 9 /// 10 private System.ComponentModel.IContainer components = null; 11 12 /// 13 /// Clean up any resources being used. 14 /// 15 /// true if managed resources should be disposed; otherwise, false. 16 protected override void Dispose(bool disposing) 17 { 18 if (disposing && (components != null)) 19 { 20 components.Dispose(); 21 } 22 base.Dispose(disposing); 23 } 24 25 #region Windows Form Designer generated code 26 27 /// 28 /// Required method for Designer support - do not modify 29 /// the contents of this method with the code editor. 30 /// 31 private void InitializeComponent() 32 { 33 this.SuspendLayout(); 34 // 35 // Form1 36 // 37 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 38 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 39 this.ClientSize = new System.Drawing.Size(284, 262); 40 this.Name = "Form1"; 41 this.Text = "Form1"; 42 this.ResumeLayout(false); 43 44 this.ListView1 = new System.Windows.Forms.ListView(); 45 this.ListView1.BackColor = System.Drawing.SystemColors.Control; 46 this.ListView1.Dock = System.Windows.Forms.DockStyle.Top; 47 this.ListView1.Location = new System.Drawing.Point(0, 0); 48 this.ListView1.Name = "ListView1"; 49 this.ListView1.Size = new System.Drawing.Size(292, 130); 50 this.ListView1.TabIndex = 0; 51 this.ListView1.View = System.Windows.Forms.View.Details; 52 this.ListView1.MultiSelect = true; 53 this.ListView1.HideSelection = false; 54 this.ListView1.HeaderStyle = ColumnHeaderStyle.Clickable; 55 56 ColumnHeader columnHeader1 = new ColumnHeader(); 57 columnHeader1.Text = "Breakfast Item"; 58 columnHeader1.TextAlign = HorizontalAlignment.Left; 59 columnHeader1.Width = 146; 60 61 ColumnHeader columnHeader2 = new ColumnHeader(); 62 columnHeader2.Text = "Price Each"; 63 columnHeader2.TextAlign = HorizontalAlignment.Center; 64 columnHeader2.Width = 142; 65 66 this.ListView1.Columns.Add(columnHeader1); 67 this.ListView1.Columns.Add(columnHeader2); 68 69 string[] foodList = new string[] { "Juice", "Coffee", "Cereal & Milk", "Fruit Plate", "Toast & Jelly", "Bagel & Cream Cheese" }; 70 string[] foodPrice = new string[] { "1.09", "1.09", "2.19", "2.49", "1.49", "1.49" }; 71 72 for (int count = 0; count < foodList.Length; count++) 73 { 74 ListViewItem listItem = new ListViewItem(foodList[count]); 75 listItem.SubItems.Add(foodPrice[count]); 76 ListView1.Items.Add(listItem); 77 } 78 this.Controls.Add(ListView1); 79 80 81 } 82 83 #endregion 84 85 private System.Windows.Forms.ListView ListView1; 86 private System.Windows.Forms.TextBox TextBox1; 87 } 88 } 主要就是插入foodList和foodprice那塊,我理解是Form1是靜態(tài)類?所以不允許實例化? 報的錯是? ? The designer cannot process the code at line 72: for (int count = 0; count < foodList.Length; count++) { ListViewItem listItem = new ListViewItem(foodList[count]); listItem.SubItems.Add(foodPrice[count]); ListView1.Items.Add(listItem); } The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.? ? ? 我印象中學C#的時候和vb差不多,設(shè)計頁面里改什么代碼頁也會變什么,怎么現(xiàn)在會這樣?還出來個 InitializeComponent啥啥的。。
查看完整描述

3 回答

?
楊魅力

TA貢獻1811條經(jīng)驗 獲得超6個贊

因為那個循環(huán)吧,在開發(fā)的時候,其實IDE是會運行l(wèi)oad的代碼的,貌似是這個意思。。。
查看完整回答
反對 回復(fù) 2018-12-09
?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

Form1不是靜態(tài)類,Winform分為設(shè)計時和運行時,默認地,designer.cs中的代碼是由DesignerSerializer按字母的順序生成的,當你拖控件時會執(zhí)行序列化,當你打開Designer的時候,它會去反序列化,你自己寫的無關(guān)代碼并不能被反序列化,所以打開Designer出錯,但是,編譯可能會通過,運行也OK。盡量不要改動Designer.cs中的代碼。
查看完整回答
反對 回復(fù) 2018-12-09
?
烙印99

TA貢獻1829條經(jīng)驗 獲得超13個贊

應(yīng)該是循環(huán)的問題,現(xiàn)實的問題是拖動控件并不能滿足所有的需求,所以才動手去修改Designer.cs對于我們這些新手來說,最好全都可以圖形化處理,減少手動代碼。
查看完整回答
反對 回復(fù) 2018-12-09
  • 3 回答
  • 0 關(guān)注
  • 514 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號