-8
// FrmWaterDepth.cs
// Graphical User Interface class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Ch12_WaterDepth
{
public partial class FrmWaterDepth : Form
{
private ShoalArea anArea;
public FrmWaterDepth( )
{
InitializeComponent( );
}
    private void btnSubmit_Click(object sender, EventArgs e)
{
double[ ] lowTides = new double[4];
double[ ] hiTides = new double[4];
anArea.Location = txtbxLocation.Text;
try
{
lowTides[0] = double.Parse(txtbLow1.Text);
lowTides[1] = double.Parse(txtbLow2.Text);
lowTides[2] = double.Parse(txtbLow3.Text);
lowTides[3] = double.Parse(txtbLow4.Text);
hiTides[0] = double.Parse(txtbxHi1.Text);
hiTides[1] = double.Parse(txtbxHi2.Text);
hiTides[2] = double.Parse(txtbxHi3.Text);
hiTides[3] = double.Parse(txtbxHi4.Text);
anArea.State = txtbxState.Text;
anArea.MileMarker = double.Parse(txtbxMile.Text);
anArea.LoTideDepth = lowTides;
anArea.HiTideDepth = hiTides;
MessageBox.Show(anArea.ToString( ),
"ICW Problem Area");
}
catch (TestOfStateException ex)
{
Trace.WriteLine("\nException: " + ex.Message);
lblError.Text += "\nException: " + ex.Message;
}
catch (System.FormatException ex)
{
Trace.WriteLine("Method's actual argument does " +
"not match formal parameter." +
"\nException: " + ex.Message);
lblError.Text += "\nException: " + ex.Message;
}
catch (System.ArithmeticException ex)
{
Debug.WriteLine("Errors in an arithmetic, " +
"casting, " +
"or conversion." +
"\nException: " + ex.Message);
lblError.Text += "\nException: " + ex.Message;
}
catch (System.ArrayTypeMismatchException ex)
{
    Trace.WriteLine("Trying to store an element of " +
    "wrong type in an array." +
    "\nException: " + ex.Message);
    lblError.Text += "\nException: " + ex.Message;
}
catch (System.IndexOutOfRangeException ex)
{
    Trace.WriteLine("Trying to access element of an " +
    "array with index outside" +
    " bounds of the array." +
    "\nException: " + ex.Message);
    lblError.Text += "\nException: " + ex.Message;
}
catch (System.Exception ex)
{
    lblError.Text += "\nException: " + ex.Message;
    Trace.WriteLine("Exception: " + ex.Message);
}
}
    private void FrmWaterDepth_Load(object sender, EventArgs e)
    {
        anArea = new ShoalArea();
    }

    private Button btnSubmit;
    private TextBox txtbxLocation;
    private TextBox txtbxState;
    private TextBox txtbxMile;
    private TextBox txtbLow1;
    private TextBox txtbLow2;
    private TextBox txtbLow3;
    private TextBox txtbLow4;
    private TextBox txtbxHi1;
    private TextBox txtbxHi2;
    private TextBox txtbxHi3;
    private TextBox txtbxHi4;
    private Label lblError;
    private Label label1;
    private Label label2;
    private Label label3;
    private Label label4;
    private Label label5;

    private void InitializeComponent()
    {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmWaterDepth));
            this.btnSubmit = new System.Windows.Forms.Button();
            this.txtbxLocation = new System.Windows.Forms.TextBox();
            this.txtbxState = new System.Windows.Forms.TextBox();
            this.txtbxMile = new System.Windows.Forms.TextBox();
            this.txtbLow1 = new System.Windows.Forms.TextBox();
            this.txtbLow2 = new System.Windows.Forms.TextBox();
            this.txtbLow3 = new System.Windows.Forms.TextBox();
            this.txtbLow4 = new System.Windows.Forms.TextBox();
            this.txtbxHi1 = new System.Windows.Forms.TextBox();
            this.txtbxHi2 = new System.Windows.Forms.TextBox();
            this.txtbxHi3 = new System.Windows.Forms.TextBox();
            this.txtbxHi4 = new System.Windows.Forms.TextBox();
            this.lblError = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // btnSubmit
            // 
            this.btnSubmit.Location = new System.Drawing.Point(288, 196);
            this.btnSubmit.Name = "btnSubmit";
            this.btnSubmit.Size = new System.Drawing.Size(75, 23);
            this.btnSubmit.TabIndex = 11;
            this.btnSubmit.Text = "Submit";
            this.btnSubmit.UseVisualStyleBackColor = true;
            this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click_1);
            // 
            // txtbxLocation
            // 
            this.txtbxLocation.Location = new System.Drawing.Point(184, 69);
            this.txtbxLocation.Name = "txtbxLocation";
            this.txtbxLocation.Size = new System.Drawing.Size(179, 20);
            this.txtbxLocation.TabIndex = 0;
            // 
            // txtbxState
            // 
            this.txtbxState.Location = new System.Drawing.Point(184, 95);
            this.txtbxState.Name = "txtbxState";
            this.txtbxState.Size = new System.Drawing.Size(46, 20);
            this.txtbxState.TabIndex = 1;
            // 
            // txtbxMile
            // 
            this.txtbxMile.Location = new System.Drawing.Point(184, 121);
            this.txtbxMile.Name = "txtbxMile";
            this.txtbxMile.Size = new System.Drawing.Size(100, 20);
            this.txtbxMile.TabIndex = 2;
            // 
            // txtbLow1
            // 
            this.txtbLow1.Location = new System.Drawing.Point(23, 215);
            this.txtbLow1.Name = "txtbLow1";
            this.txtbLow1.Size = new System.Drawing.Size(37, 20);
            this.txtbLow1.TabIndex = 3;
            // 
            // txtbLow2
            // 
            this.txtbLow2.Location = new System.Drawing.Point(23, 247);
            this.txtbLow2.Name = "txtbLow2";
            this.txtbLow2.Size = new System.Drawing.Size(37, 20);
            this.txtbLow2.TabIndex = 5;
            // 
            // txtbLow3
            // 
            this.txtbLow3.Location = new System.Drawing.Point(23, 280);
            this.txtbLow3.Name = "txtbLow3";
            this.txtbLow3.Size = new System.Drawing.Size(37, 20);
            this.txtbLow3.TabIndex = 7;
            // 
            // txtbLow4
            // 
            this.txtbLow4.Location = new System.Drawing.Point(23, 308);
            this.txtbLow4.Name = "txtbLow4";
            this.txtbLow4.Size = new System.Drawing.Size(37, 20);
            this.txtbLow4.TabIndex = 9;
            // 
            // txtbxHi1
            // 
            this.txtbxHi1.Location = new System.Drawing.Point(134, 215);
            this.txtbxHi1.Name = "txtbxHi1";
            this.txtbxHi1.Size = new System.Drawing.Size(39, 20);
            this.txtbxHi1.TabIndex = 4;
            // 
            // txtbxHi2
            // 
            this.txtbxHi2.Location = new System.Drawing.Point(134, 247);
            this.txtbxHi2.Name = "txtbxHi2";
            this.txtbxHi2.Size = new System.Drawing.Size(39, 20);
            this.txtbxHi2.TabIndex = 6;
            // 
            // txtbxHi3
            // 
            this.txtbxHi3.Location = new System.Drawing.Point(134, 280);
            this.txtbxHi3.Name = "txtbxHi3";
            this.txtbxHi3.Size = new System.Drawing.Size(39, 20);
            this.txtbxHi3.TabIndex = 8;
            // 
            // txtbxHi4
            // 
            this.txtbxHi4.Location = new System.Drawing.Point(134, 308);
            this.txtbxHi4.Name = "txtbxHi4";
            this.txtbxHi4.Size = new System.Drawing.Size(39, 20);
            this.txtbxHi4.TabIndex = 10;
            // 
            // lblError
            // 
            this.lblError.AutoSize = true;
            this.lblError.Location = new System.Drawing.Point(246, 294);
            this.lblError.Name = "lblError";
            this.lblError.Size = new System.Drawing.Size(20, 13);
            this.lblError.TabIndex = 12;
            this.lblError.Text = "\" \"";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(77, 71);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(48, 13);
            this.label1.TabIndex = 13;
            this.label1.Text = "Location";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(74, 126);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(62, 13);
            this.label2.TabIndex = 14;
            this.label2.Text = "Mile Marker";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(80, 100);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(32, 13);
            this.label3.TabIndex = 15;
            this.label3.Text = "State";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(17, 188);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(51, 13);
            this.label4.TabIndex = 16;
            this.label4.Text = "Low Tide";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(127, 190);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(53, 13);
            this.label5.TabIndex = 17;
            this.label5.Text = "High Tide";
            // 
            // FrmWaterDepth
            // 
            this.AcceptButton = this.btnSubmit;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
            this.ClientSize = new System.Drawing.Size(392, 379);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lblError);
            this.Controls.Add(this.txtbxHi4);
            this.Controls.Add(this.txtbxHi3);
            this.Controls.Add(this.txtbxHi2);
            this.Controls.Add(this.txtbxHi1);
            this.Controls.Add(this.txtbLow4);
            this.Controls.Add(this.txtbLow3);
            this.Controls.Add(this.txtbLow2);
            this.Controls.Add(this.txtbLow1);
            this.Controls.Add(this.txtbxMile);
            this.Controls.Add(this.txtbxState);
            this.Controls.Add(this.txtbxLocation);
            this.Controls.Add(this.btnSubmit);
            this.Name = "FrmWaterDepth";
            this.Text = "ICW SHoal Reporter";
            this.ResumeLayout(false);
            this.PerformLayout();

    }

    private void btnSubmit_Click_1(object sender, EventArgs e)
    {

    }
}
}

提交按钮不起作用。当我在字段中输入信息后单击提交时,它什么也不做。我不确定在 private void btnSubmit_Click_1 之后放入。我正在使用 VB 2010 及其 Windows 窗体项目。

4

3 回答 3

2

您已将两种方法链接到您的按钮。

private void btnSubmit_Click_1(object sender, EventArgs e)

private void btnSubmit_Click(object sender, EventArgs e)

将您的代码放入btnSubmit_Click_1.

或者

您可以调整附加到单击事件的方法,方法是在设计视图中选择按钮的属性,然后单击黄色闪电,找到click事件并更改方法名称。

于 2013-05-06T19:20:59.150 回答
1
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click_1);

您在该方法中的代码:

private void btnSubmit_Click_1(object sender, EventArgs e)
{

}

你期待它到底做什么?

我想你想要:

this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);

您的代码还有很多其他问题,其中一个是真正 的“必须抓住所有”异常处理btnSubmit_click

于 2013-05-06T19:23:03.683 回答
1

您必须单击处理程序方法:btnSubmit_ClickbtnSubmit_Click_1.

OnlybtnSubmit_Click_1被注册来处理点击,它的body是空的。您可以删除该方法并将注册更改为:

this.btnSubmit.Click += btnSubmit_Click;
于 2013-05-06T19:23:30.643 回答