2017-12-07 8 views
-1

コードを投稿しました。私のWindowsフォームアプリケーションでC#のフォームを変更するたびに、 "public static"変更が最後に "public"に変更され、 "this"が追加されます。それらへのすべての単一の参照に。私のコードはもう一度編集した後に正常に動作するようですが、これは本当に面倒です。私はちょうど私が何かを逃していないか、これに貧弱なアプローチをしていないことを確認したかった。C#でフォーム上の任意のオブジェクトのアスペクトを変更した後に、Visual Studio 2017がパブリック静的ステートメントを「パブリック」に変更し続けるのはなぜですか?

パブリック静的ステートメントを使用しているのは、主フォームの一部のテキストボックスとDataGridViewオブジェクトを他のフォームから変更しているためです。つまり、あるフォームのデータベースから顧客情報を検索し、 1つのフォーム上の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; DR; **決して '.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は、同じクラスのすべてのフォームに1つのインスタンスしか存在しないことを意味します。

あるフォームから別のフォームへのUIの直接修正も同様にアンチパターンとみなされます。データモデルを作成し、変更されたときに更新されたデータをUIに読み込ませる必要があります。私はこれが初心者のためだけでなく、winformのために少し挑戦かもしれないことを知っています。

したがって、ショートカットを使用する場合は、他のフォームのパブリックプロパティを公開することができます。プロパティを変更すると、他のフォームが適切なコントロールを更新します。

編集:背後にある他のフォームのコードで (ファイル.csファイル)

あなたは

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

    public string SelectedUser { get; private set; } 
} 

のように行うことができ、その後、あなたのメインフォームであなたが近いイベント

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

「公共財産を他の形式で公開する」という意味を教えてもらえますか?議論の目的のために、私は2つの形式を持っているとしましょう。 1つは他のフォームを起動するための主要なフォームであり、1つはユーザーがデータベースから顧客を検索できるデータ収集フォームです。メインフォームのコマンドボタンからデータ収集フォームを起動し、ユーザーが選択した顧客のメインフォームにテキストボックスを入力します。どのフォームに「公有財産」が必要ですか?どのように公開するのですか?その情報にどの程度正確にアクセスできますか? –

+0

@AlanDenkeコード例 – Steve

+0

を参照してください。また、この「データモデル」の概念について私に指示することができますか?私はVB6で何年も前に書いたプログラムをアップグレードしていますが、将来このようなことが増えています。私は他のいくつかのプログラムがこの同じ種類のコンセプトを持っているので、これを達成する方法を理解したいと思います。メインフォームからフォームを起動してメインフォームのデータを入力します。これを正しい方法で行う方法を理解できればいいと思います。ありがとう! –

関連する問題