2017-12-07 23 views
-1

내 코드를 게시했습니다. 매번 C#의 내 Windows Forms App에서이 양식의 내용을 변경하면 결국 "public static"변경 사항이 "public"으로 변경된 다음 "this"가 추가됩니다. 그 (것)들에 각 단일 참조에. 내 코드는 다시 편집 한 후에 정상적으로 실행되는 것처럼 보이지만 실제로는 성가시다. 나는 단지 내가 뭔가를 놓치지 않거나 이것에 대해 가난한 접근법을 취하지 않고 있는지 확인하고 싶었다.C#의 양식에서 임의의 개체를 변경 한 후에 Visual Studio 2017에서 공용 정적 진술을 "공개"로 변경하는 이유

공공 정적 문장을 사용하는 이유는 다른 양식에서 내 기본 양식의 일부 Textbox 및 DataGridView 개체를 수정하기 때문입니다. 즉, 한 양식의 데이터베이스에서 고객 정보를 찾고 기본 양식을 작성하고 한 장의 WebBrowser 컨트롤에서 장바구니 정보를 가져 와서 다른 양식의 DataGridView 개체에 넣습니다. 이것이 다른 양식에서 양식을 채우는 방법이 아니라면 C#을 처음 접했을 때 어떻게 구체적이고 구체적인지 알려주십시오. 미안 내가 너무 많은 코드를 게시 한 경우 - 이것은 내 form1.cs 파일의 거의 전부이며 내가 여기에있는 것이 무엇이 문제를 일으키는 지 알지 못했습니다. 관련 "공개 정적"진술은 결국 있습니다.

(이 글을 읽은 후에 누군가가 폼이 "특정 인스턴스화"라고되어있는 다른 스레드를 찾아 보았습니다. 그래서 개발자 환경은 "정적"을 계속 가져옵니다). 그럴 경우 ... 도움이됩니다! 한 양식의 값을 다른 양식에서 변경하는 방법을 이해하지 못하고 절대적으로 그렇게해야합니다. -이 코드는 작동하지만 나쁜 습관이라고 생각합니다. - 완전히 분실되어이 작업을하기 위해 매우 구체적인 지침이 필요함)

미리 감사드립니다. 당신이 .designer.cs 파일에 보면

namespace WindowsFormsApp1 
{ 
    public partial class frmMain 
    { 
     private System.ComponentModel.IContainer components = null; 

    protected override void Dispose(bool disposing) 
    { 
     if (disposing && (components != null)) 
     { 
      components.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

    #region Windows Form Designer generated code 

    private void InitializeComponent() 
    { 
     this.cmdSendEmail = new System.Windows.Forms.Button(); 
     this.cmdExit = new System.Windows.Forms.Button(); 
     this.cmdLookup = new System.Windows.Forms.Button(); 
     this.txtTransactionNumber = new System.Windows.Forms.TextBox(); 
     this.cmdEdit = new System.Windows.Forms.Button(); 
     this.groupBox1 = new System.Windows.Forms.GroupBox(); 
     this.cmdBrowse = new System.Windows.Forms.Button(); 
     this.groupBox2 = new System.Windows.Forms.GroupBox(); 
     this.cmdCustomer = new System.Windows.Forms.Button(); 
     this.txtNotes = new System.Windows.Forms.TextBox(); 
     txtZip = new System.Windows.Forms.TextBox(); 
     txtCountry = new System.Windows.Forms.TextBox(); 
     txtState = new System.Windows.Forms.TextBox(); 
     txtCity = new System.Windows.Forms.TextBox(); 
     txtAddress = new System.Windows.Forms.TextBox(); 
     txtName = new System.Windows.Forms.TextBox(); 
     txtPayPalEmail = new System.Windows.Forms.TextBox(); 
     txtEmail = new System.Windows.Forms.TextBox(); 
     txtPhone = new System.Windows.Forms.TextBox(); 
     txtLast = new System.Windows.Forms.TextBox(); 
     txtFirst = new System.Windows.Forms.TextBox(); 
     grdOrderItems = new System.Windows.Forms.DataGridView(); 
     this.Qty = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.Description = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.UnitPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.ExtPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.SCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.Options1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.Options2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
     this.groupBox3 = new System.Windows.Forms.GroupBox(); 
     this.lblSubTotal = new System.Windows.Forms.Label(); 
     this.lblTotal = new System.Windows.Forms.Label(); 
     this.txtTax = new System.Windows.Forms.TextBox(); 
     this.txtShipping = new System.Windows.Forms.TextBox(); 
     this.txtShippingMethod = new System.Windows.Forms.TextBox(); 
     this.cmdTaxLookup = new System.Windows.Forms.Button(); 
     this.lstShipping = new System.Windows.Forms.ListBox(); 
     this.cmdBrowser = new System.Windows.Forms.Button(); 
     this.groupBox4 = new System.Windows.Forms.GroupBox(); 
     this.cmdSendRequest = new System.Windows.Forms.Button(); 
     this.cmdClear = new System.Windows.Forms.Button(); 
     this.cmdSave = new System.Windows.Forms.Button(); 
     this.cmdPrint = new System.Windows.Forms.Button(); 
     this.cmdSavePrintEmail = new System.Windows.Forms.Button(); 
     this.groupBox1.SuspendLayout(); 
     this.groupBox2.SuspendLayout(); 
     ((System.ComponentModel.ISupportInitialize)(grdOrderItems)).BeginInit(); 
     this.groupBox3.SuspendLayout(); 
     this.groupBox4.SuspendLayout(); 
     this.SuspendLayout(); 
     // 
     // cmdLookup 
     // 
     this.cmdLookup.Location = new System.Drawing.Point(88, 15); 
     this.cmdLookup.Name = "cmdLookup"; 
     this.cmdLookup.Size = new System.Drawing.Size(197, 33); 
     this.cmdLookup.TabIndex = 3; 
     this.cmdLookup.Text = "Look up order to attach request to"; 
     this.cmdLookup.UseVisualStyleBackColor = true; 
     // 
     // txtTransactionNumber 
     // 
     this.txtTransactionNumber.Location = new System.Drawing.Point(91, 57); 
     this.txtTransactionNumber.Name = "txtTransactionNumber"; 
     this.txtTransactionNumber.Size = new System.Drawing.Size(158, 20); 
     this.txtTransactionNumber.TabIndex = 5; 
     // 
     // cmdEdit 
     // 
     this.cmdEdit.Location = new System.Drawing.Point(260, 57); 
     this.cmdEdit.Name = "cmdEdit"; 
     this.cmdEdit.Size = new System.Drawing.Size(87, 30); 
     this.cmdEdit.TabIndex = 6; 
     this.cmdEdit.Text = "Edit"; 
     this.cmdEdit.UseVisualStyleBackColor = true; 
     // 
     // 
     // groupBox1 
     // 
     this.groupBox1.Location = new System.Drawing.Point(438, 125); 
     this.groupBox1.Name = "groupBox1"; 
     this.groupBox1.Size = new System.Drawing.Size(345, 56); 
     this.groupBox1.TabIndex = 10; 
     this.groupBox1.TabStop = false; 
     // 
     // cmdBrowse 
     // 
     this.cmdBrowse.Location = new System.Drawing.Point(14, 139); 
     this.cmdBrowse.Name = "cmdBrowse"; 
     this.cmdBrowse.Size = new System.Drawing.Size(220, 22); 
     this.cmdBrowse.TabIndex = 11; 
     this.cmdBrowse.Text = "Browse Unpaid Payment Requests"; 
     this.cmdBrowse.UseVisualStyleBackColor = true; 
     // 
     // groupBox2 
     // 
     this.groupBox2.BackColor = System.Drawing.Color.WhiteSmoke; 
     this.groupBox2.Controls.Add(this.cmdCustomer); 
     this.groupBox2.Controls.Add(this.txtNotes); 
     this.groupBox2.Controls.Add(txtZip); 
     this.groupBox2.Controls.Add(txtCountry); 
     this.groupBox2.Controls.Add(txtState); 
     this.groupBox2.Controls.Add(txtCity); 
     this.groupBox2.Controls.Add(txtAddress); 
     this.groupBox2.Controls.Add(txtName); 
     this.groupBox2.Controls.Add(txtPayPalEmail); 
     this.groupBox2.Controls.Add(txtEmail); 
     this.groupBox2.Controls.Add(txtPhone); 
     this.groupBox2.Controls.Add(txtLast); 
     this.groupBox2.Controls.Add(txtFirst); 
     this.groupBox2.Location = new System.Drawing.Point(14, 168); 
     this.groupBox2.Name = "groupBox2"; 
     this.groupBox2.Size = new System.Drawing.Size(749, 264); 
     this.groupBox2.TabIndex = 12; 
     this.groupBox2.TabStop = false; 
     this.groupBox2.Text = "Customer Information"; 
     this.groupBox2.Enter += new System.EventHandler(this.groupBox2_Enter); 
     // 
     // label21 
     // 
     this.label21.AutoSize = true; 
     this.label21.Location = new System.Drawing.Point(186, 215); 
     this.label21.Name = "label21"; 
     this.label21.Size = new System.Drawing.Size(25, 13); 
     this.label21.TabIndex = 24; 
     this.label21.Text = "Zip:"; 
     // 
     // cmdCustomer 
     // 
     this.cmdCustomer.Location = new System.Drawing.Point(657, 136); 
     this.cmdCustomer.Name = "cmdCustomer"; 
     this.cmdCustomer.Size = new System.Drawing.Size(86, 69); 
     this.cmdCustomer.TabIndex = 23; 
     this.cmdCustomer.Text = "Load Customer Info from Prior Order"; 
     this.cmdCustomer.UseVisualStyleBackColor = true; 
     this.cmdCustomer.Click += new System.EventHandler(this.cmdCustomer_Click); 
     // 
     // txtNotes 
     // 
     this.txtNotes.AcceptsReturn = true; 
     this.txtNotes.Location = new System.Drawing.Point(404, 136); 
     this.txtNotes.Multiline = true; 
     this.txtNotes.Name = "txtNotes"; 
     this.txtNotes.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 
     this.txtNotes.Size = new System.Drawing.Size(247, 122); 
     this.txtNotes.TabIndex = 19; 
     // 
     // txtZip 
     // 
     txtZip.Location = new System.Drawing.Point(211, 212); 
     txtZip.Name = "txtZip"; 
     txtZip.Size = new System.Drawing.Size(99, 20); 
     txtZip.TabIndex = 25; 
     txtZip.TextChanged += new System.EventHandler(this.txtZip_TextChanged); 
     // 
     // txtCountry 
     // 
     txtCountry.Location = new System.Drawing.Point(72, 237); 
     txtCountry.Name = "txtCountry"; 
     txtCountry.Size = new System.Drawing.Size(238, 20); 
     txtCountry.TabIndex = 22; 
     txtCountry.TextChanged += new System.EventHandler(this.txtCountry_TextChanged); 
     // 
     // txtState 
     // 
     txtState.Location = new System.Drawing.Point(72, 210); 
     txtState.Name = "txtState"; 
     txtState.Size = new System.Drawing.Size(108, 20); 
     txtState.TabIndex = 21; 
     txtState.TextChanged += new System.EventHandler(this.txtState_TextChanged); 
     // 
     // txtCity 
     // 
     txtCity.Location = new System.Drawing.Point(72, 185); 
     txtCity.Name = "txtCity"; 
     txtCity.Size = new System.Drawing.Size(238, 20); 
     txtCity.TabIndex = 20; 
     txtCity.TextChanged += new System.EventHandler(this.txtCity_TextChanged); 
     // 
     // txtAddress 
     // 
     txtAddress.AcceptsReturn = true; 
     txtAddress.Location = new System.Drawing.Point(72, 92); 
     txtAddress.Multiline = true; 
     txtAddress.Name = "txtAddress"; 
     txtAddress.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 
     txtAddress.Size = new System.Drawing.Size(236, 87); 
     txtAddress.TabIndex = 18; 
     txtAddress.TextChanged += new System.EventHandler(this.txtAddress_TextChanged); 
     // 
     // txtName 
     // 
     txtName.Location = new System.Drawing.Point(72, 68); 
     txtName.Name = "txtName"; 
     txtName.Size = new System.Drawing.Size(238, 20); 
     txtName.TabIndex = 17; 
     txtName.TextChanged += new System.EventHandler(this.txtName_TextChanged); 
     // 
     // txtPayPalEmail 
     // 
     txtPayPalEmail.Location = new System.Drawing.Point(405, 98); 
     txtPayPalEmail.Name = "txtPayPalEmail"; 
     txtPayPalEmail.Size = new System.Drawing.Size(203, 20); 
     txtPayPalEmail.TabIndex = 16; 
     // 
     // txtEmail 
     // 
     txtEmail.Location = new System.Drawing.Point(404, 65); 
     txtEmail.Name = "txtEmail"; 
     txtEmail.Size = new System.Drawing.Size(204, 20); 
     txtEmail.TabIndex = 15; 
     // 
     // txtPhone 
     // 
     txtPhone.Location = new System.Drawing.Point(405, 39); 
     txtPhone.Name = "txtPhone"; 
     txtPhone.Size = new System.Drawing.Size(203, 20); 
     txtPhone.TabIndex = 14; 
     txtPhone.TextChanged += new System.EventHandler(this.txtPhone_TextChanged); 
     // 
     // txtLast 
     // 
     txtLast.Location = new System.Drawing.Point(189, 39); 
     txtLast.Name = "txtLast"; 
     txtLast.Size = new System.Drawing.Size(121, 20); 
     txtLast.TabIndex = 13; 
     txtLast.TextChanged += new System.EventHandler(this.txtLast_TextChanged); 
     // 
     // txtFirst 
     // 
     txtFirst.Location = new System.Drawing.Point(72, 39); 
     txtFirst.Name = "txtFirst"; 
     txtFirst.Size = new System.Drawing.Size(84, 20); 
     txtFirst.TabIndex = 12; 
     txtFirst.TextChanged += new System.EventHandler(this.txtFirst_TextChanged); 

     // grdOrderItems 
     // 
     grdOrderItems.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; 
     grdOrderItems.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 
     grdOrderItems.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { 
     this.Qty, 
     this.Description, 
     this.UnitPrice, 
     this.ExtPrice, 
     this.SCode, 
     this.Options1, 
     this.Options2}); 
     grdOrderItems.Location = new System.Drawing.Point(10, 19); 
     grdOrderItems.Name = "grdOrderItems"; 
     grdOrderItems.Size = new System.Drawing.Size(732, 81); 
     grdOrderItems.TabIndex = 0; 
     grdOrderItems.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(grdOrderItems_CellValueChanged); 
     grdOrderItems.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.grdOrderItems_RowsAdded); 
     // 
     // Qty 
     // 
     this.Qty.HeaderText = "Qty"; 
     this.Qty.Name = "Qty"; 
     this.Qty.Width = 48; 
     // 
     // Description 
     // 
     this.Description.HeaderText = "Description"; 
     this.Description.Name = "Description"; 
     this.Description.Width = 85; 
     // 
     // UnitPrice 
     // 
     this.UnitPrice.HeaderText = "Unit Price"; 
     this.UnitPrice.Name = "UnitPrice"; 
     this.UnitPrice.Width = 78; 
     // 
     // ExtPrice 
     // 
     this.ExtPrice.HeaderText = "Ext. Price3"; 
     this.ExtPrice.Name = "ExtPrice"; 
     this.ExtPrice.ReadOnly = true; 
     this.ExtPrice.Width = 83; 
     // 
     // SCode 
     // 
     this.SCode.HeaderText = "S-Code"; 
     this.SCode.Name = "SCode"; 
     this.SCode.Width = 67; 
     // 
     // Options1 
     // 
     this.Options1.HeaderText = "Options1"; 
     this.Options1.Name = "Options1"; 
     this.Options1.Width = 74; 
     // 
     // Options2 
     // 
     this.Options2.HeaderText = "Options2"; 
     this.Options2.Name = "Options2"; 
     this.Options2.Width = 74; 
     // 
     // groupBox3 
     // 
     this.groupBox3.BackColor = System.Drawing.Color.WhiteSmoke; 
     this.groupBox3.Controls.Add(this.checkBox1); 
     this.groupBox3.Controls.Add(this.cmdApplyTaxRate); 
     this.groupBox3.Controls.Add(this.txtTaxRate); 
     this.groupBox3.Controls.Add(this.lblSubTotal); 
     this.groupBox3.Controls.Add(this.lblTotal); 
     this.groupBox3.Controls.Add(this.txtTax); 
     this.groupBox3.Controls.Add(this.txtShipping); 
     this.groupBox3.Controls.Add(this.txtShippingMethod); 
     this.groupBox3.Controls.Add(this.cmdTaxLookup); 
     this.groupBox3.Controls.Add(this.lstShipping); 
     this.groupBox3.Controls.Add(this.cmdBrowser); 
     this.groupBox3.Controls.Add(this.groupBox4); 
     this.groupBox3.Controls.Add(grdOrderItems); 
     this.groupBox3.Location = new System.Drawing.Point(14, 443); 
     this.groupBox3.Name = "groupBox3"; 
     this.groupBox3.Size = new System.Drawing.Size(749, 242); 
     this.groupBox3.TabIndex = 13; 
     this.groupBox3.TabStop = false; 
     this.groupBox3.Text = "Order Information"; 
     // 
     // checkBox1 
     // 
     this.checkBox1.AutoSize = true; 
     this.checkBox1.Checked = true; 
     this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; 
     this.checkBox1.Location = new System.Drawing.Point(253, 224); 
     this.checkBox1.Name = "checkBox1"; 
     this.checkBox1.Size = new System.Drawing.Size(257, 17); 
     this.checkBox1.TabIndex = 21; 
     this.checkBox1.Text = "Automatically Apply Tax Rate with order changes"; 
     this.checkBox1.UseVisualStyleBackColor = true; 
     // 
     // cmdApplyTaxRate 
     // 
     this.cmdApplyTaxRate.Location = new System.Drawing.Point(313, 194); 
     this.cmdApplyTaxRate.Name = "cmdApplyTaxRate"; 
     this.cmdApplyTaxRate.Size = new System.Drawing.Size(126, 24); 
     this.cmdApplyTaxRate.TabIndex = 20; 
     this.cmdApplyTaxRate.Text = "Apply Tax Rate"; 
     this.cmdApplyTaxRate.UseVisualStyleBackColor = true; 
     // 
     // txtTaxRate 
     // 
     this.txtTaxRate.Location = new System.Drawing.Point(186, 198); 
     this.txtTaxRate.Name = "txtTaxRate"; 
     this.txtTaxRate.Size = new System.Drawing.Size(101, 20); 
     this.txtTaxRate.TabIndex = 19; 
     // 
     // lblSubTotal 
     // 
     this.lblSubTotal.AutoSize = true; 
     this.lblSubTotal.Location = new System.Drawing.Point(571, 128); 
     this.lblSubTotal.Name = "lblSubTotal"; 
     this.lblSubTotal.Size = new System.Drawing.Size(13, 13); 
     this.lblSubTotal.TabIndex = 18; 
     this.lblSubTotal.Text = "$"; 
     // 
     // lblTotal 
     // 
     this.lblTotal.AutoSize = true; 
     this.lblTotal.Location = new System.Drawing.Point(571, 210); 
     this.lblTotal.Name = "lblTotal"; 
     this.lblTotal.Size = new System.Drawing.Size(13, 13); 
     this.lblTotal.TabIndex = 17; 
     this.lblTotal.Text = "$"; 
     // 
     // txtTax 
     // 
     this.txtTax.Location = new System.Drawing.Point(561, 177); 
     this.txtTax.Name = "txtTax"; 
     this.txtTax.Size = new System.Drawing.Size(182, 20); 
     this.txtTax.TabIndex = 16; 
     // 
     // txtShipping 
     // 
     this.txtShipping.Location = new System.Drawing.Point(561, 149); 
     this.txtShipping.Name = "txtShipping"; 
     this.txtShipping.Size = new System.Drawing.Size(182, 20); 
     this.txtShipping.TabIndex = 15; 
     // 
     // txtShippingMethod 
     // 
     this.txtShippingMethod.Location = new System.Drawing.Point(559, 105); 
     this.txtShippingMethod.Name = "txtShippingMethod"; 
     this.txtShippingMethod.Size = new System.Drawing.Size(182, 20); 
     this.txtShippingMethod.TabIndex = 14; 
     // 
     // cmdTaxLookup 
     // 
     this.cmdTaxLookup.Location = new System.Drawing.Point(138, 218); 
     this.cmdTaxLookup.Name = "cmdTaxLookup"; 
     this.cmdTaxLookup.Size = new System.Drawing.Size(99, 21); 
     this.cmdTaxLookup.TabIndex = 13; 
     this.cmdTaxLookup.Text = "Lookup Tax Rate"; 
     this.cmdTaxLookup.UseVisualStyleBackColor = true; 
     // 
     // lstShipping 
     // 
     this.lstShipping.FormattingEnabled = true; 
     this.lstShipping.Location = new System.Drawing.Point(304, 106); 
     this.lstShipping.Name = "lstShipping"; 
     this.lstShipping.Size = new System.Drawing.Size(150, 69); 
     this.lstShipping.TabIndex = 5; 
     // 
     // cmdBrowser 
     // 
     this.cmdBrowser.Location = new System.Drawing.Point(16, 106); 
     this.cmdBrowser.Name = "cmdBrowser"; 
     this.cmdBrowser.Size = new System.Drawing.Size(164, 21); 
     this.cmdBrowser.TabIndex = 2; 
     this.cmdBrowser.Text = "Launch Browser Form"; 
     this.cmdBrowser.UseVisualStyleBackColor = true; 
     this.cmdBrowser.Click += new System.EventHandler(this.cmdBrowser_Click); 
     // 
     // groupBox4 
     // 
     this.groupBox4.Controls.Add(this.cmdSendRequest); 
     this.groupBox4.Location = new System.Drawing.Point(18, 133); 
     this.groupBox4.Name = "groupBox4"; 
     this.groupBox4.Size = new System.Drawing.Size(162, 57); 
     this.groupBox4.TabIndex = 1; 
     this.groupBox4.TabStop = false; 
     this.groupBox4.Text = "PayPal"; 
     // 
     // cmdSendRequest 
     // 
     this.cmdSendRequest.Location = new System.Drawing.Point(7, 19); 
     this.cmdSendRequest.Name = "cmdSendRequest"; 
     this.cmdSendRequest.Size = new System.Drawing.Size(131, 32); 
     this.cmdSendRequest.TabIndex = 2; 
     this.cmdSendRequest.Text = "Send Payment Request"; 
     this.cmdSendRequest.UseVisualStyleBackColor = true; 
     this.cmdSendRequest.Click += new System.EventHandler(this.cmdSendRequest_Click_1); 
     // 
     // cmdClear 
     // 
     this.cmdClear.Location = new System.Drawing.Point(16, 696); 
     this.cmdClear.Name = "cmdClear"; 
     this.cmdClear.Size = new System.Drawing.Size(67, 25); 
     this.cmdClear.TabIndex = 14; 
     this.cmdClear.Text = "Clear"; 
     this.cmdClear.UseVisualStyleBackColor = true; 
     // 
     // cmdSave 
     // 
     this.cmdSave.Location = new System.Drawing.Point(91, 697); 
     this.cmdSave.Name = "cmdSave"; 
     this.cmdSave.Size = new System.Drawing.Size(67, 25); 
     this.cmdSave.TabIndex = 15; 
     this.cmdSave.Text = "Save"; 
     this.cmdSave.UseVisualStyleBackColor = true; 
     // 
     // cmdPrint 
     // 
     this.cmdPrint.Location = new System.Drawing.Point(164, 697); 
     this.cmdPrint.Name = "cmdPrint"; 
     this.cmdPrint.Size = new System.Drawing.Size(67, 25); 
     this.cmdPrint.TabIndex = 16; 
     this.cmdPrint.Text = "Print"; 
     this.cmdPrint.UseVisualStyleBackColor = true; 
     // 
     // cmdSavePrintEmail 
     // 
     this.cmdSavePrintEmail.Location = new System.Drawing.Point(393, 694); 
     this.cmdSavePrintEmail.Name = "cmdSavePrintEmail"; 
     this.cmdSavePrintEmail.Size = new System.Drawing.Size(131, 31); 
     this.cmdSavePrintEmail.TabIndex = 17; 
     this.cmdSavePrintEmail.Text = "Save, Print, and Email"; 
     this.cmdSavePrintEmail.UseVisualStyleBackColor = true; 
     // 
     // frmMain 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.BackColor = System.Drawing.Color.Aqua; 
     this.ClientSize = new System.Drawing.Size(790, 725); 
     this.Controls.Add(this.cmdSavePrintEmail); 
     this.Controls.Add(this.cmdPrint); 
     this.Controls.Add(this.cmdSave); 
     this.Controls.Add(this.cmdClear); 
     this.Controls.Add(this.groupBox3); 
     this.Controls.Add(this.groupBox2); 
     this.Controls.Add(this.cmdBrowse); 
     this.Controls.Add(this.groupBox1); 
     this.Controls.Add(this.optRequestNew); 
     this.Controls.Add(this.optRequestShipping); 
     this.Controls.Add(this.optRequestAdd); 
     this.Controls.Add(this.cmdEdit); 
     this.Controls.Add(this.txtTransactionNumber); 
     this.Controls.Add(this.cmdLookup); 
     this.Controls.Add(this.cmdExit); 
     this.Controls.Add(this.cmdSendEmail); 
     this.Name = "frmMain"; 
     this.Text = "PayPal Payment Request Program version C1"; 
     this.Load += new System.EventHandler(this.Form1_Load); 
     this.groupBox1.ResumeLayout(false); 
     this.groupBox1.PerformLayout(); 
     this.groupBox2.ResumeLayout(false); 
     this.groupBox2.PerformLayout(); 
     ((System.ComponentModel.ISupportInitialize)(grdOrderItems)).EndInit(); 
     this.groupBox3.ResumeLayout(false); 
     this.groupBox3.PerformLayout(); 
     this.groupBox4.ResumeLayout(false); 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 

    #endregion 

    private System.Windows.Forms.Button cmdSendEmail; 
    private System.Windows.Forms.Button cmdExit; 
    private System.Windows.Forms.Button cmdLookup; 
    private System.Windows.Forms.TextBox txtTransactionNumber; 
    private System.Windows.Forms.Button cmdEdit; 
    private System.Windows.Forms.GroupBox groupBox1; 
    private System.Windows.Forms.Button cmdBrowse; 
    private System.Windows.Forms.GroupBox groupBox2; 
    private System.Windows.Forms.Button cmdCustomer; 
    private System.Windows.Forms.TextBox txtNotes; 
    private System.Windows.Forms.GroupBox groupBox3; 
    private System.Windows.Forms.GroupBox groupBox4; 
    private System.Windows.Forms.Button cmdSendRequest; 
    private System.Windows.Forms.Button cmdBrowser; 
    private System.Windows.Forms.CheckBox checkBox1; 
    private System.Windows.Forms.Button cmdApplyTaxRate; 
    private System.Windows.Forms.TextBox txtTaxRate; 
    private System.Windows.Forms.TextBox txtTax; 
    private System.Windows.Forms.TextBox txtShipping; 
    private System.Windows.Forms.TextBox txtShippingMethod; 
    private System.Windows.Forms.Button cmdTaxLookup; 
    private System.Windows.Forms.ListBox lstShipping; 
    private System.Windows.Forms.Button cmdClear; 
    private System.Windows.Forms.Button cmdSave; 
    private System.Windows.Forms.Button cmdPrint; 
    private System.Windows.Forms.Button cmdSavePrintEmail; 
    private System.Windows.Forms.DataGridViewTextBoxColumn Qty; 
    private System.Windows.Forms.DataGridViewTextBoxColumn Description; 
    private System.Windows.Forms.DataGridViewTextBoxColumn UnitPrice; 
    private System.Windows.Forms.DataGridViewTextBoxColumn ExtPrice; 
    private System.Windows.Forms.DataGridViewTextBoxColumn SCode; 
    private System.Windows.Forms.DataGridViewTextBoxColumn Options1; 
    private System.Windows.Forms.DataGridViewTextBoxColumn Options2; 
    public static System.Windows.Forms.TextBox txtEmail; 
    public static System.Windows.Forms.TextBox txtPhone; 
    public static System.Windows.Forms.TextBox txtLast; 
    public static System.Windows.Forms.TextBox txtCountry; 
    public static System.Windows.Forms.TextBox txtState; 
    public static System.Windows.Forms.TextBox txtAddress; 
    public static System.Windows.Forms.TextBox txtPayPalEmail; 
    public static System.Windows.Forms.DataGridView grdOrderItems; 
    public static System.Windows.Forms.TextBox txtZip; 
    public static System.Windows.Forms.TextBox txtCity; 
    public static System.Windows.Forms.TextBox txtName; 
    public static System.Windows.Forms.TextBox txtFirst; 
} 

}

+2

TL; ** 결코 ** .designer.cs 확장자를 가진 파일을 변경하지 마십시오. Visual Studio에 의해 자동으로 대체됩니다. –

+0

'static '은 그 클래스의 모든 인스턴스가 같은 값을 사용할 것임을 의미합니다. 당신은 일반적으로 양식에 그것을 원하지 않습니다. Form 인스턴스를 전달하는 더 좋은 방법이 있습니다. –

답변

1

주의 깊게 자동 디자이너에 의해 생성되는이 작은 코멘트 기본적으로

/// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 

코드의 일부를 발견하고 수정해서는 안됩니다 수동으로.

네, 이것은 나쁜 관행으로 간주됩니다. 첫째, 컨트롤은 정적 인 것이 아니라 폼 내부에 포함되어야합니다. Static은 동일한 클래스의 모든 양식에서 인스턴스가 하나만 존재한다는 것을 의미합니다.

한 양식에서 다른 양식으로 UI를 직접 수정하는 것도 안티 패턴으로 간주됩니다. 데이터 모델을 만들고 변경된 UI가 업데이트 된 데이터를 읽도록해야합니다. 나는 이것이 초보자들에게도 winform을 위해 조금 도전적일지도 모른다는 것을 안다.

따라서 바로 가기를 사용하려면 다른 양식의 공용 속성을 노출 할 수 있으며 속성을 수정하면 다른 양식이 해당 컨트롤을 업데이트합니다.

편집 : 뒤에 다른 형태의 코드 (.cs 파일)에서

당신이

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    public string SelectedUser { get; private set; } 
} 

과 같이 할 수는 다음의 주요 형태로는 close 이벤트

Form1 other = new Form1(); 
    other.FormClosed += Other_FormClosed; 
    other.Show(); 
을들을 것

...

private void Other_FormClosed(object sender, FormClosedEventArgs e) 
{ 
    Form1 other = (Form1)sender; 
    string selectedUser = other.SelectedUser; 

    //do something 
} 
+0

"공공 재산을 다른 형태로 공개하는 것"이 ​​무슨 뜻인지 말해 줄 수 있습니까? 토론의 목적으로 두 가지 형식이 있다고 가정 해 봅시다. 하나는 다른 양식을 시작하는 기본 양식이고 다른 하나는 사용자가 데이터베이스에서 고객을 찾을 수있는 데이터 수집 양식입니다. 기본 양식의 명령 단추에서 데이터 수집 양식을 실행 한 다음 사용자가 선택한 고객과 기본 양식의 텍스트 상자를 채 웁니다. 어떤 양식이 "공공 재산"을 가져야합니까? 어떻게 공개하고, 그 정보에 정확히 어떻게 접근합니까? –

+0

@AlanDenke 코드 예제 – Steve

+0

참조 또는이 "데이터 모델"개념에 대해 읽으려면 다른 곳으로 안내 할 수 있습니까? 저는 VB6에서 몇 년 전에 쓴 프로그램을 업그레이드하고 있습니다 만, 앞으로해야 할 일이 더 많습니다. 다른 프로그램들 중 몇 가지가 이와 같은 종류의 개념을 가지고 있기 때문에이를 수행하는 방법을 이해하고 싶습니다. 메인 폼에서 폼을 시작하여 메인 폼의 데이터를 채 웁니다. 이 방법을 올바른 방법으로 파악할 수 있다면 좋을 것입니다. 감사! –