要求:
1、实时读取textbox29中的数据
2、在button1_MouseUp和(不是或)button2_MouseUp时,将读到的数据发送下去(发送的部分已经写好,timer3里面那个就是 现在是一个计时器发送的)
代码如下sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
    public partial class Form2 : Form
    {        public const int TAG_CMD = 0xff;
        public const int TAG_STATUS = 0xfe;
        public const int TAG_DATA = 0xfd;
        public const int CMD_ID_TARGET = 0x00;
        public const int RESP_ID_TARGET_BLDC = 0x00;
        public const int RESP_ID_TARGET_STEPPER = 0x01;
        public const int RESP_ID_TARGET_ACIM = 0x02;
        public const int CMD_UPGRADE = 0x01;
        public const int CMD_DISCOVER_TARGET = 0x02;
        public const int CMD_GET_PARAMS = 0x10;
        public const int CMD_GET_PARAM_DESC = 0x11;
        public const int CMD_GET_PARAM_VALUE = 0x12;
        public const int CMD_SET_PARAM_VALUE = 0x13;
        public const int CMD_LOAD_PARAMS = 0x14;
        public const int CMD_SAVE_PARAMS = 0x15;
        public const int CMD_GET_DATA_ITEMS = 0x20;
        public const int CMD_ENABLE_DATA_ITEM = 0x21;
        public const int CMD_DISABLE_DATA_ITEM = 0x22;
        public const int CMD_START_DATA_STREAM = 0x23;
        public const int CMD_STOP_DATA_STREAM = 0x24;
        public const int CMD_RUN = 0x30;
        public const int CMD_STOP = 0x31;
        public const int CMD_EMERGENCY_STOP = 0x32;
        public const int PARAM_FIRMWARE_VERSION = 0x00;
        public const int PARAM_DATA_RATE = 0x01;
        public const int PARAM_MIN_SPEED = 0x02;
        public const int PARAM_MAX_SPEED = 0x03;
        public const int PARAM_TARGET_SPEED = 0x04;
        public const int PARAM_CURRENT_SPEED = 0x05;
        public const int PARAM_ACCEL = 0x06;
        public const int PARAM_DECEL = 0x07;
        public const int PARAM_TARGET_POS = 0x08;
        public const int PARAM_CURRENT_POS = 0x09;
        public const int PARAM_CLOSED_LOOP = 0x0a;
        public const int PARAM_ENCODER_PRESENT = 0x0b;
        public const int PARAM_MODULATION = 0x0c;
        public const int PARAM_DIRECTION = 0x0d;
        public const int PARAM_VF_TABLE = 0x0e;
        public const int PARAM_PWM_FREQUENCY = 0x0f;
        public const int PARAM_PWM_DEAD_TIME = 0x10;
        public const int PARAM_PWM_UPDATE = 0x11;
        public const int PARAM_PWM_MIN_PULSE = 0x12;
        public const int PARAM_MOTOR_TYPE = 0x13;
        public const int PARAM_NUM_POLES = 0x14;
        public const int PARAM_NUM_LINES = 0x15;
        public const int PARAM_MIN_CURRENT = 0x16;
        public const int PARAM_MAX_CURRENT = 0x17;
        public const int PARAM_MIN_BUS_VOLTAGE = 0x18;
        public const int PARAM_MAX_BUS_VOLTAGE = 0x19;
        public const int PARAM_SPEED_P = 0x1a;
        public const int PARAM_SPEED_I = 0x1b;
        public const int PARAM_BRAKE_ON_VOLTAGE = 0x1c;
        public const int PARAM_BRAKE_OFF_VOLTAGE = 0x1d;
        public const int PARAM_USE_ONBOARD_UI = 0x1e;
        public const int PARAM_PRECHARGE_TIME = 0x1f;
        public const int PARAM_USE_BUS_COMP = 0x20;
        public const int PARAM_VF_RANGE = 0x21;
        public const int PARAM_CONTROL_MODE = 0x22;
        public const int PARAM_DECAY_MODE = 0x23;
        public const int PARAM_STEP_MODE = 0x24;
        public const int PARAM_FIXED_ON_TIME = 0x25;
        public const int PARAM_RESISTANCE = 0x26;
        public const int PARAM_BLANK_OFF = 0x27;
        public const int PARAM_HOLDING_CURRENT = 0x28;
        public const int PARAM_USE_DYNAM_BRAKE = 0x29;
        public const int PARAM_MAX_BRAKE_TIME = 0x2a;
        public const int PARAM_BRAKE_COOL_TIME = 0x2b;
        public const int PARAM_FAULT_STATUS = 0x2c;
        public const int PARAM_MOTOR_STATUS = 0x2d;
        public const int PARAM_USE_DC_BRAKE = 0x2e;
        public const int PARAM_DC_BRAKE_V = 0x2f;
        public const int PARAM_DC_BRAKE_TIME = 0x30;
        public const int PARAM_DECEL_VOLTAGE = 0x31;
        public const int PARAM_TARGET_CURRENT = 0x32;
        public const int PARAM_MAX_TEMPERATURE = 0x33;
        public const int PARAM_ACCEL_CURRENT = 0x34;
        public const int PARAM_SENSOR_PRESENT = 0x35;
        public const int PARAM_SENSOR_TYPE = 0x36;
        public const int PARAM_GPIO_DATA = 0x37;
        public const int PARAM_CAN_RX_COUNT = 0x38;
        public const int PARAM_CAN_TX_COUNT = 0x39;
        public const int PARAM_ETH_RX_COUNT = 0x3a;
        public const int PARAM_ETH_TX_COUNT = 0x3b;
        public const int PARAM_ETH_TCP_TIMEOUT = 0x3c;
        public const int PARAM_SENSOR_POLARITY = 0x3d;
        public const int PARAM_STARTUP_DUTY = 0x3e;
        public const int PARAM_STARTUP_COUNT = 0x3f;
        public const int PARAM_STARTUP_STARTV = 0x40;
        public const int PARAM_STARTUP_ENDV = 0x41;
        public const int PARAM_STARTUP_STARTSP = 0x42;
        public const int PARAM_STARTUP_ENDSP = 0x43;
        public const int PARAM_TARGET_POWER = 0x44;
        public const int PARAM_CURRENT_POWER = 0x45;
        public const int PARAM_MIN_POWER = 0x46;
        public const int PARAM_MAX_POWER = 0x47;
        public const int PARAM_POWER_P = 0x48;
        public const int PARAM_POWER_I = 0x49;
        public const int PARAM_ACCEL_POWER = 0x4a;
        public const int PARAM_DECEL_POWER = 0x4b;
        public const int PARAM_STARTUP_RAMP = 0x4c;
        public const int PARAM_STARTUP_THRESH = 0x4d;
        public const int PARAM_BEMF_SKIP_COUNT = 0x4e;
        public const int DATA_PHASE_A_CURRENT = 0x00;
        public const int DATA_PHASE_B_CURRENT = 0x01;
        public const int DATA_PHASE_C_CURRENT = 0x02;
        public const int DATA_MOTOR_CURRENT = 0x03;
        public const int DATA_BUS_VOLTAGE = 0x04;
        public const int DATA_MOTOR_POSITION = 0x05;
        public const int DATA_STATOR_SPEED = 0x06;
        public const int DATA_ROTOR_SPEED = 0x07;
        public const int DATA_PROCESSOR_USAGE = 0x08;
        public const int DATA_MOTOR_STATUS = 0x09;
        public const int DATA_DIRECTION = 0x0a;
        public const int DATA_FAULT_STATUS = 0x0b;
        public const int DATA_TEMPERATURE = 0x0c;
        public const int DATA_ANALOG_INPUT = 0x0d;
        public const int DATA_DEBUG_INFO = 0x0e;
        public const int DATA_MOTOR_POWER = 0x0f;
        public const int DATA_NUM_ITEMS = 0x10;
        public const int MOTOR_STATUS_STOP = 0x00;
        public const int MOTOR_STATUS_RUN = 0x01;
        public const int MOTOR_STATUS_ACCEL = 0x02;
        public const int MOTOR_STATUS_DECEL = 0x03;
        public int CheckIn;        public byte[] SendBuffer = new byte[256];
        public int[] SendBufferout = new int[512];
        Form1 frm1 = null;
        public Form2()
        {
            InitializeComponent();
            
        }
        public int tyz=0;        private void textBox1_MouseUp(object sender, MouseEventArgs e)
        {
            tyz = 1;
        }        private void textBox2_MouseUp(object sender, MouseEventArgs e)
        {
            tyz = 2;
        }        private void textBox3_MouseUp(object sender, MouseEventArgs e)
        {
            tyz = 3;
        } 
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((char.IsNumber(e.KeyChar) == false) && (e.KeyChar != 46))
            {
                e.Handled = true;
            }
 
        }        private void button7_Click(object sender, EventArgs e)
        {
            
            this.Hide();
        }        private void button2_Click(object sender, EventArgs e)
        {
            double aa;
            switch (tyz)
            {
                case 1:
                    aa = Convert.ToDouble(textBox1.Text);
                    if (aa > 0)
                        aa = aa - 0.1;
                    if (aa < 0)
                        aa = 0;                    aa = Math.Round(aa, 1);
                    if (aa > 40)
                        aa = 40;
                    textBox1.Text = aa.ToString();
                    break;
                case 2:
                    aa = Convert.ToDouble(textBox2.Text);
                    if (aa > 0)
                        aa = aa - 0.1;
                    aa = Math.Round(aa, 1);
                    if (aa < 0)
                        aa = 0;                    if (aa > 40)
                        aa = 40;
                    textBox2.Text = aa.ToString();
                    break;
                case 3:
                    aa = Convert.ToDouble(textBox3.Text);
                    if (aa > 0)
                        aa = aa - 0.1;
                    aa = Math.Round(aa, 1);
                    if (aa < 0)
                        aa = 0;
 
                    if (aa > 40)
                        aa = 40;
                    textBox3.Text = aa.ToString();
                    break;            }
        }
一次贴不完

解决方案 »

  1.   


      private void textBox5_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 4;
            }        private void textBox4_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 5;
            }        private void textBox7_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 6;
            }        private void textBox6_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 7;
            }        private void textBox9_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 8;
            }        private void textBox8_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 9;
            }  
            private void AddOne()
            {
                double aa;
                switch (tyz)
                {
                    case 1:
                        aa = Convert.ToDouble(textBox1.Text) + 0.1;
                        aa = Math.Round(aa, 1);
                        if (aa > 40)
                            aa = 40;
                        textBox1.Text = aa.ToString();
                        break;
                    case 2:
                        aa = Convert.ToDouble(textBox2.Text) + 0.1;
                        aa = Math.Round(aa, 1);
                        if (aa > 40)
                            aa = 40;
                        textBox2.Text = aa.ToString();
                        break;
                    case 3:
                        aa = Convert.ToDouble(textBox3.Text) + 0.1;
                        aa = Math.Round(aa, 1);
                        if (aa > 40)
                            aa = 40;
                        textBox3.Text = aa.ToString();
                        break;
                    case 4:
                        aa = Convert.ToDouble(textBox5.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 60000)
                            aa = 60000;
                        textBox5.Text = aa.ToString();
                        break;
                    case 5:
                        aa = Convert.ToDouble(textBox4.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 60000)
                            aa = 60000;
                        textBox4.Text = aa.ToString();
                        break;
                    case 6:
                        aa = Convert.ToDouble(textBox7.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 50000)
                            aa = 50000;
                        textBox7.Text = aa.ToString();
                        break;
                    case 7:
                        aa = Convert.ToDouble(textBox6.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 50000)
                            aa = 50000;
                        textBox6.Text = aa.ToString();
                        break;
                    case 8:
                        aa = Convert.ToDouble(textBox9.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 2147483647)
                            aa = 2147483647;
                        textBox9.Text = aa.ToString();
                        break;
      

  2.   

    case 9:
                        aa = Convert.ToDouble(textBox8.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 2147483647)
                            aa = 2147483647;
                        textBox8.Text = aa.ToString();
                        break;
                    case 10:
                        aa = double.Parse(textBox15.Text) + 0.01;
                        if (aa > 360)
                            aa = 360;
                        aa = Math.Round(aa, 2);
                        textBox15.Text = aa.ToString();
                        break;
                    case 11:
                        aa = double.Parse(textBox14.Text) + 0.01;
                        if (aa > 360)
                            aa = 360;
                        aa = Math.Round(aa, 2);
                        textBox14.Text = aa.ToString();
                        break;
                    case 12:
                        aa = double.Parse(textBox13.Text) + 0.01;
                        if (aa > 50)
                            aa = 50;
                        aa = Math.Round(aa, 2);
                        textBox13.Text = aa.ToString();
                        break;
                    case 13:
                        aa = double.Parse(textBox12.Text) + 0.01;
                        if (aa > 50)
                            aa = 50;
                        aa = Math.Round(aa, 2);
                        textBox12.Text = aa.ToString();
                        break;
                    case 14:
                        aa = Convert.ToDouble(textBox11.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 2147483647)
                            aa = 2147483647;
                        textBox11.Text = aa.ToString();
                        break;
                    case 15:
                        aa = Convert.ToDouble(textBox10.Text) + 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 2147483647)
                            aa = 2147483647;
                        textBox10.Text = aa.ToString();
                        break;
                    case 16:
                        aa = double.Parse(textBox18.Text) + 0.1;
                        if (aa > 50)
                            aa = 50;
                        aa = Math.Round(aa, 1);
                        textBox18.Text = aa.ToString();
                        break;
                    case 17:
                        aa = double.Parse(textBox17.Text) + 0.1;
                        if (aa > 50)
                            aa = 50;
                        aa = Math.Round(aa, 1);
                        textBox17.Text = aa.ToString();
                        break;
                    case 18:
                        aa = double.Parse(textBox19.Text) + 0.1;
                        if (aa > 50)
                            aa = 50;
                        aa = Math.Round(aa, 1);
                        textBox19.Text = aa.ToString();
                        break;
                    case 19:
                        aa = double.Parse(textBox16.Text) + 0.1;
                        if (aa > 15)
                            aa = 15;
                        aa = Math.Round(aa, 1);
                        textBox16.Text = aa.ToString();
                        break;
                    case 20:
                        aa = double.Parse(textBox22.Text) + 0.1;
                        if (aa > 60)
                            aa = 60;
                        aa = Math.Round(aa, 1);
                        textBox22.Text = aa.ToString();
                        break;
                    case 21:
                        aa = double.Parse(textBox21.Text) + 0.1;
                        if (aa > 60)
                            aa = 60;
                        aa = Math.Round(aa, 1);
                        textBox21.Text = aa.ToString();
                        break;
                    case 22:
                        aa = double.Parse(textBox20.Text) + 0.1;
                        if (aa > 40)
                            aa = 40;
                        aa = Math.Round(aa, 1);
                        textBox20.Text = aa.ToString();
                        break;
                    case 23:
                        aa = double.Parse(textBox23.Text) + 0.1;
                        if (aa > 40)
                            aa = 40;
                        aa = Math.Round(aa, 1);
                        textBox23.Text = aa.ToString();
                        break;
                    case 24:
                        aa = double.Parse(textBox24.Text) + 1;
                        if (aa > 85)
                            aa = 85;
                        aa = Math.Round(aa, 0);
                        textBox24.Text = aa.ToString();
                        break;
                    case 25:
                        aa = double.Parse(textBox28.Text) + 20;
                        if (aa > 5100)
                            aa = 5100;
                        if (aa < 2000)
                            aa = 2000;
                        aa = Math.Round(aa, 1);
                        textBox28.Text = aa.ToString();
                        break;
                    case 26:
                        aa = double.Parse(textBox27.Text) + 1;
                        if (aa > 255)
                            aa = 255;
                        aa = Math.Round(aa, 0);
                        textBox27.Text = aa.ToString();
                        break;
                    case 27:
                        aa = double.Parse(textBox26.Text) + 0.1;
                        if (aa > 25)
                            aa = 25;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox26.Text = aa.ToString();
                        break;
                    case 28:
                        aa = double.Parse(textBox25.Text) + 1;
                        if (aa > 255)
                            aa = 255;
                        if (aa < 0)
                            aa = 0;                    aa = Math.Round(aa, 0);
                        textBox25.Text = aa.ToString();
                        break;
                    case 29:
                        aa = double.Parse(textBox30.Text) + 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 1)
                            aa = 1;
                        aa = Math.Round(aa, 0);
                        textBox30.Text = aa.ToString();
                        break;
                    case 30:
                        aa = double.Parse(textBox29.Text) + 2;
                        if (aa > 148)
                            aa =148;
                        if (aa < 2)
                            aa = 2;
                        aa = Math.Round(aa/2, 0) * 2;
                        textBox29.Text = aa.ToString();
                        break;
                    case 31:
                        aa = double.Parse(textBox33.Text) + 1;
                        if (aa > 255)
                            aa = 255;
                        if (aa < 1)
                            aa = 1;
                        aa = Math.Round(aa , 0) ;
                        textBox33.Text = aa.ToString();
                        break;
                    case 32:
                        aa = double.Parse(textBox32.Text) + 1;
                        if (aa > 40000)
                            aa = 40000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox32.Text = aa.ToString();
                        break;
                    case 33:
                        aa = double.Parse(textBox31.Text) + 1;
                        if (aa > 40000)
                            aa = 40000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox31.Text = aa.ToString();
                        break;
                    case 34:
                        aa = double.Parse(textBox34.Text) + 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox34.Text = aa.ToString();
                        break;
                    case 38:
                        aa = double.Parse(textBox38.Text) + 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox38.Text = aa.ToString();
                        break;
                    case 35:
                        aa = double.Parse(textBox37.Text) + 1;
                        if (aa > 60000)
                            aa = 60000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox37.Text = aa.ToString();
                        break;
                    case 36:
                        aa = double.Parse(textBox36.Text) + 1;
                        if (aa > 60000)
                            aa = 60000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox36.Text = aa.ToString();
                        break;
                    case 37:
                        aa = double.Parse(textBox35.Text) + 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox35.Text = aa.ToString();
                        break;            }
            }
      

  3.   

    private void SubOne()
            {
                double aa;
                switch (tyz)
                {
                    case 1:
                        aa = Convert.ToDouble(textBox1.Text);
                        if (aa > 0)
                            aa = aa - 0.1;
                        if (aa < 0)
                            aa = 0;                    aa = Math.Round(aa, 1);
                        if (aa > 40)
                            aa = 40;
                        textBox1.Text = aa.ToString();
                        break;
                    case 2:
                        aa = Convert.ToDouble(textBox2.Text);
                        if (aa > 0)
                            aa = aa - 0.1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;                    if (aa > 40)
                            aa = 40;
                        textBox2.Text = aa.ToString();
                        break;
                    case 3:
                        aa = Convert.ToDouble(textBox3.Text);
                        if (aa > 0)
                            aa = aa - 0.1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;
     
                        if (aa > 40)
                            aa = 40;
                        textBox3.Text = aa.ToString();
                        break;
                    case 4:
                        aa = Convert.ToDouble(textBox5.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;
                        if (aa > 60000)
                            aa = 60000;
                        textBox5.Text = aa.ToString();
                        break;
                    case 5:
                        aa = Convert.ToDouble(textBox4.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;                    if (aa > 60000)
                            aa = 60000;
                        textBox4.Text = aa.ToString();
                        break;
                    case 6:
                        aa = Convert.ToDouble(textBox7.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;                    if (aa > 50000)
                            aa = 50000;
                        textBox7.Text = aa.ToString();
                        break;
                    case 7:
                        aa = Convert.ToDouble(textBox6.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;                    if (aa > 50000)
                            aa = 50000;
                        textBox6.Text = aa.ToString();
                        break;
                    case 8:
                        aa = Convert.ToDouble(textBox9.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;                    if (aa > 50000)
                            aa = 50000;
                        textBox9.Text = aa.ToString();
                        break;
                    case 9:
                        aa = Convert.ToDouble(textBox8.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa < 0)
                            aa = 0;
                        if (aa > 50000)
                            aa = 50000;
                        textBox8.Text = aa.ToString();
                        break;
                    case 10:
                        aa = double.Parse(textBox15.Text) - 0.01;
                        if (aa > 360)
                            aa = 360;
                        aa = Math.Round(aa, 2);
                        textBox15.Text = aa.ToString();
                        break;
                    case 11:
                        aa = double.Parse(textBox14.Text) - 0.01;
                        if (aa > 360)
                            aa = 360;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 2);
                        textBox14.Text = aa.ToString();
                        break;
                    case 12:
                        aa = double.Parse(textBox13.Text) - 0.01;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 2);
                        textBox13.Text = aa.ToString();
                        break;
                    case 13:
                        aa = double.Parse(textBox12.Text) - 0.01;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 2);
                        textBox12.Text = aa.ToString();
                        break;
                    case 14:
                        aa = Convert.ToDouble(textBox11.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 2147483647)
                            aa = 2147483647;
                        if (aa < 0)
                            aa = 0; 
                        textBox11.Text = aa.ToString();
                        break;
                    case 15:
                        aa = Convert.ToDouble(textBox10.Text) - 1;
                        aa = Math.Round(aa, 1);
                        if (aa > 2147483647)
                            aa = 2147483647;
                        if (aa < 0)
                            aa = 0;
                        textBox10.Text = aa.ToString();
                        break;
                    case 16:
                        aa = double.Parse(textBox18.Text) - 0.1;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox18.Text = aa.ToString();
                        break;
                    case 17:
                        aa = double.Parse(textBox17.Text) - 0.1;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox17.Text = aa.ToString();
                        break;
                    case 18:
                        aa = double.Parse(textBox19.Text) - 0.1;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox19.Text = aa.ToString();
                        break;
                    case 19:
                        aa = double.Parse(textBox16.Text) - 0.1;
                        if (aa > 15)
                            aa =15;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox16.Text = aa.ToString();
                        break;
                    case 20:
                        aa = double.Parse(textBox22.Text) - 0.1;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox22.Text = aa.ToString();
                        break;
                    case 21:
                        aa = double.Parse(textBox21.Text) - 0.1;
                        if (aa > 50)
                            aa = 50;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox21.Text = aa.ToString();
                        break;
      

  4.   

    case 22:
                        aa = double.Parse(textBox20.Text) - 0.1;
                        if (aa > 40)
                            aa = 40;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox20.Text = aa.ToString();
                        break;
                    case 23:
                        aa = double.Parse(textBox23.Text) - 0.1;
                        if (aa > 40)
                            aa = 40;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox23.Text = aa.ToString();
                        break;
                    case 24:
                        aa = double.Parse(textBox24.Text) - 1;
                        if (aa > 85)
                            aa = 85;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox24.Text = aa.ToString();
                        break;
                    case 25:
                        aa = double.Parse(textBox28.Text) - 20;
                        if (aa > 5100)
                            aa = 5100;
                        if (aa < 2000)
                            aa = 2000;
                        aa = Math.Round(aa, 0);
                        textBox28.Text = aa.ToString();
                        break;
                    case 26:
                        aa = double.Parse(textBox27.Text) - 1;
                        if (aa > 255)
                            aa = 255;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox27.Text = aa.ToString();
                        break;
                    case 27:
                        aa = double.Parse(textBox26.Text) - 0.1;
                        if (aa > 25)
                            aa = 25;
                        if (aa <0)
                            aa = 0;
                        aa = Math.Round(aa, 1);
                        textBox26.Text = aa.ToString();
                        break;
                    case 28:
                        aa = double.Parse(textBox25.Text) - 1;
                        if (aa > 255)
                            aa = 255;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox25.Text = aa.ToString();
                        break;
                    case 29:
                        aa = double.Parse(textBox30.Text) - 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 1)
                            aa = 1;
                        aa = Math.Round(aa, 0);
                        textBox30.Text = aa.ToString();
                        break;
                    case 30:
                        aa = double.Parse(textBox29.Text) - 2;
                        if (aa > 148)
                            aa = 148;
                        if (aa < 2)
                            aa = 2;
                        aa = Math.Round(aa / 2, 0) * 2;
                        textBox29.Text = aa.ToString();
                        break;
                    case 31:
                        aa = double.Parse(textBox33.Text) - 1;
                        if (aa > 255)
                            aa = 255;
                        if (aa < 1)
                            aa = 1;
                        aa = Math.Round(aa, 0);
                        textBox33.Text = aa.ToString();
                        break;
                    case 32:
                        aa = double.Parse(textBox32.Text) - 1;
                        if (aa > 40000)
                            aa = 40000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox32.Text = aa.ToString();
                        break;
                    case 33:
                        aa = double.Parse(textBox31.Text) - 1;
                        if (aa > 40000)
                            aa = 40000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox31.Text = aa.ToString();
                        break;
                    case 34:
                        aa = double.Parse(textBox34.Text) - 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox34.Text = aa.ToString();
                        break;
                    case 38:
                        aa = double.Parse(textBox38.Text) - 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox38.Text = aa.ToString();
                        break;                case 35:
                        aa = double.Parse(textBox37.Text) - 1;
                        if (aa > 60000)
                            aa = 60000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox37.Text = aa.ToString();
                        break;
                    case 36:
                        aa = double.Parse(textBox36.Text) - 1;
                        if (aa > 60000)
                            aa = 60000;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox36.Text = aa.ToString();
                        break;
                    case 37:
                        aa = double.Parse(textBox35.Text) - 1;
                        if (aa > 65535)
                            aa = 65535;
                        if (aa < 0)
                            aa = 0;
                        aa = Math.Round(aa, 0);
                        textBox35.Text = aa.ToString();
                        break;
                }
            }
      

  5.   

    小汗一下,建议楼主先把
    TextBox<--->Type
    TextBox<--->MaxValue
    TextBox<--->MinValue
    之间的关系先做个对应,可以用Dictionary大致的示例,只写了Type对应,以及如何处理MouseUp事件
     Dictionary<TextBox, int> typeTextBoxMap = new Dictionary<TextBox, int>();
                typeTextBoxMap.Add(textBox1, 1);
                //...
                typeTextBoxMap.Add(textbox2, n);
                foreach (TextBox tb in typeTextBoxMap.Keys)
                {
                    tb.MouseUp += delegate(object sender, EventArgs e)
                    {
                        typeTextBoxMap.TryGetValue(tb, out tyz);
                    };
                }
      

  6.   

        private void extBox5_MouseUp(object sender, MouseEventArgs e)
            {        }        private void button1_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz>0) && (tyz<4))
                {
                    AddOne();
                    this.timer1.Interval=300;
                    this.timer1.Enabled=true;
                }
            }        private void button1_MouseUp(object sender, MouseEventArgs e)
            {
                  this.timer1.Enabled=false ;
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                this.timer1.Interval = 100;
                AddOne();
            }        private void button4_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 4) && (tyz < 10))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }        private void button2_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz > 0) && (tyz < 4))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }        }        private void timer2_Tick(object sender, EventArgs e)
            {
                this.timer2.Interval = 100;
                SubOne(); ;
            }        private void button3_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >=4) && (tyz < 10))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }        }        private void button2_MouseUp(object sender, MouseEventArgs e)
            {
                this.timer2.Enabled = false;
            }        private void button6_Click(object sender, EventArgs e)
            {
             } 
            private void textBox15_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 10;
            }        private void button6_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 10) && (tyz < 16))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }        private void textBox14_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 11;
            }        private void textBox13_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 12;
            }        private void textBox12_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 13;
            }        private void textBox11_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 14;
            }        private void textBox10_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 15;
            }        private void button5_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 10) && (tyz < 16))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }        }        private void textBox18_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 16;
            }        private void textBox17_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 17;
            }        private void textBox19_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 18;
            }        private void textBox16_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 19;
            }        private void textBox22_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 20;
            }        private void textBox21_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 21;
            }        private void textBox20_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 22;
            }        private void textBox23_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 23;
            }        private void textBox24_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 24;
            }        private void button10_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 16) && (tyz < 18))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }        private void button9_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 16) && (tyz < 18))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }
            }        private void button12_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 18;
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
            }        private void button11_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 18;
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
            }        private void button14_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 19;
                AddOne();
                this.timer1.Interval = 300;
                this.timer1.Enabled = true;
            }        private void button13_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 19;
                SubOne();
                this.timer2.Interval = 300;
                this.timer2.Enabled = true;
            }        private void button16_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 20) && (tyz < 24))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }        private void button15_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 20) && (tyz < 24))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }
            }        private void button18_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 24;
                AddOne();
                this.timer1.Interval = 300;
                this.timer1.Enabled = true;        }        private void button17_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 24;
                SubOne();
                this.timer2.Interval = 300;
                this.timer2.Enabled = true;
            }        private void textBox28_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 25;
            }        private void textBox27_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 26;
            }        private void textBox26_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 27;
            }        private void textBox25_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 28;
            }        private void button20_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 25) && (tyz < 27))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }
            private void button19_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 25) && (tyz < 27))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }        }        private void button22_Click(object sender, EventArgs e)
            {        }        private void button22_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 27) && (tyz < 29))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }
      

  7.   

     private void button21_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 27) && (tyz < 29))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }        }        private void textBox30_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 29;
            }        private void textBox29_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 30;
                int ee;
                ee = Convert.ToInt16(textBox29.Text);
            }        private void textBox33_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 31;
            }        private void textBox32_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 32;
            }        private void textBox31_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 33;
            }        private void textBox34_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 34;
            }        private void textBox38_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 38;
            }        private void textBox37_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 35;
            }        private void textBox36_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 36;
            }        private void textBox35_MouseUp(object sender, MouseEventArgs e)
            {
                tyz = 37;
            } 
            private void button24_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 29;
                AddOne();
                this.timer1.Interval = 300;
                this.timer1.Enabled = true;        }        private void button23_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 29;
                SubOne();
                this.timer2.Interval = 300;
                this.timer2.Enabled = true;
     
            }        private void button26_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 30;
                AddOne();
                this.timer1.Interval = 300;
                this.timer1.Enabled = true;
            }        private void button25_MouseDown(object sender, MouseEventArgs e)
            {
                tyz = 30;
                SubOne();
                this.timer2.Interval = 300;
                this.timer2.Enabled = true;
     
            }        private void button28_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 31) && (tyz < 39))
                {
                    AddOne();
                    this.timer1.Interval = 300;
                    this.timer1.Enabled = true;
                }        }        private void button27_MouseDown(object sender, MouseEventArgs e)
            {
                if ((tyz >= 31) && (tyz < 39))
                {
                    SubOne();
                    this.timer2.Interval = 300;
                    this.timer2.Enabled = true;
                }        }        private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {
                if (frm1 == null)
                {
                    frm1 = (Form1)this.Owner;
                    
                }
                if (this.radioButton1.Checked == true)
                {
                    groupBox2.Enabled = true;
                    groupBox16.Enabled = false;
                    groupBox13.Enabled = true;            }
                if (this.radioButton2.Checked == true)
                {
                    groupBox2.Enabled = true;
                    groupBox16.Enabled = true;
                    groupBox13.Enabled =false;            }
                if (this.radioButton3.Checked == true)
                {
                    radioButton4.Checked = true;
                    groupBox2.Enabled =false;
                    groupBox16.Enabled = false;
                    groupBox13.Enabled = true;            }
                if (this.radioButton4.Checked == true)
                {
                    groupBox5.Enabled = false;
                    groupBox4.Enabled = true;
                    frm1.groupBox2.Enabled = true;
                    frm1.groupBox3.Enabled = false;
                }
                if (this.radioButton5.Checked == true)
                {
                    groupBox5.Enabled =true;
                    groupBox4.Enabled =false;
                    frm1.groupBox2.Enabled =false ;
                    frm1.groupBox3.Enabled =true ;
                }        }        private void checkBox4_CheckedChanged(object sender, EventArgs e)
            {
                if (checkBox4.Checked == true)
                {
                    textBox30.Enabled = true;
                    button24.Enabled = true;
                    button23.Enabled = true;
                }
                else
                {
                    textBox30.Enabled = false;
                    button24.Enabled =false;
                    button23.Enabled =false;
               }        }        private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                if (checkBox1.Checked == true)
                {
                    textBox20.Enabled = true;
                    textBox21.Enabled = true;
                    textBox22.Enabled = true;
                    textBox23.Enabled = true;
                    button15.Enabled = true;
                    button16.Enabled = true;
                }
                else
                {
                    textBox20.Enabled = false;
                    textBox21.Enabled = false;
                    textBox22.Enabled = false;
                    textBox23.Enabled = false;
                    button15.Enabled = false;
                    button16.Enabled = false;
                }        }        private void button1_Click(object sender, EventArgs e)
            {        }        private void button2_Click_1(object sender, EventArgs e)
            {        }        private void tabPage2_Click(object sender, EventArgs e)
            {        }        private void textBox29_TextChanged(object sender, EventArgs e)
            {
              int ee;
              ee = Convert.ToInt16(textBox29.Text);
            }        private void button26_Click(object sender, EventArgs e)
            {        }
            private int checksum(int len)
            {
                int ret = 0;
                for (int i = 0; i < len; i++)
                    ret = ret + SendBuffer[i];
                ret = 0x10000 - ret;
                return (ret);
            }
            private int pu = 0;
            private void timer3_Tick(object sender, EventArgs e)
            {
                this.timer3.Interval = 100;
                int cc;
                int gg;            cc = SendBufferout[pu++];
                for (gg = 0; gg < cc; gg++) ;
                SendBufferout[pu++] = SendBuffer[gg];
                this.timer3.Interval = 100;
                if ((cc > 0) && (cc < 150))
                {
                    SendBuffer[0] = TAG_CMD;
                    SendBuffer[1] = 0x07;
                    SendBuffer[2] = CMD_SET_PARAM_VALUE;
                    SendBuffer[3] = PARAM_NUM_POLES;
                    SendBuffer[4] = (byte)(cc & 0xff);
                    SendBuffer[5] = (byte)(cc >> 8);
                    SendBuffer[6] = (byte)(checksum(6));
                    frm1.serialPort1.Write(SendBuffer, 0, SendBuffer[1]);            }
                else
                {
                    this.timer3.Enabled = false;
                }
            }        private void button8_Click(object sender, EventArgs e)
            {        }
        }
    }
      

  8.   

    程序比较长 有热心的请加我MSN:[email protected]
    我会传给你完整程序 分也可以给你 谢谢指教
      

  9.   

    我认为你那一大堆case没几个人看的下去,为什么不考虑用一下反射和委托呢,你这代码实在太那个了...
      

  10.   

    <a href="#">我晕啦</a>
      

  11.   

    还有一大堆的aa bb 这不是一个好习惯
      

  12.   

    那么多case  哎,,,case
      

  13.   

    光看到 textbox后面的数字我就决定留名接分了
      

  14.   

    习惯不好啊.aa,bb的变量名字看着都会死人的.这还不说,还有一大堆的case...超级不规范啊..还有就是先提出问题,想想看是什么问题,在贴出疑惑的代码猜效率高........