我從解析C#中的文本框出現問題。基本上我試圖設置一些值爲整數,然後當人在文本框中輸入數字時,如果增加計數器相同。但我必須解析int到字符串,在這裏我失敗了。在C#中解析文本框#
下面是代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace kontrolno {
public partial class Form1: Form {
int counter;
int A = 13;
int B = 2116;
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
label3.Text = counter.ToString();
}
private void label3_Click(object sender, EventArgs e) {}
private void groupBox1_Enter(object sender, EventArgs e) {}
private void textBox1_TextChanged(object sender, EventArgs e) {
int A = Int32.Parse(textBox1.Text);
if (textBox1.Text = A) /*As you see somewhere here i have a problem*/
}
private void textBox2_TextChanged(object sender, EventArgs e) {
/*Here must be parsed second textBox*/
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
switch (comboBox1.SelectedIndex) //comboBox 1st case
{
case 0:
button1.Enabled = false;
textBox1.Text = "13";
textBox2.Text = "2116";
radioButton1.Checked = true;
checkBox1.Checked = true;
/*Those 3 answers should
checkBox2.Checked = true; be counted as one
checkBox4.Checked = true; when mark is formed*/
checkBox5.Checked = true;
break;
case 1:
/*comboBox 2nd case*/
button1.Enabled = true;
textBox1.Text = "";
textBox2.Text = "";
radioButton1.Checked = false;
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox4.Checked = false;
checkBox5.Checked = false;
break;
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e) {
if (radioButton1.Checked) {
counter++;
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e) {
if (checkBox1.Checked) {
counter++;
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e) {
if (checkBox2.Checked) {
counter++;
}
}
private void checkBox4_CheckedChanged(object sender, EventArgs e) {
if (checkBox4.Checked) {
counter++;
} else {
counter--;
}
}
private void checkBox5_CheckedChanged(object sender, EventArgs e) {
if (checkBox5.Checked) {
counter++;
} else {
counter--;
}
}
}
}
所以我有問題,但我不知道如何解決後援代碼的想法是test.The組合框在第一個項目實踐2項用戶看到所有的問題和答案。在第二項用戶填寫答案和按下按鈕時,他收到他的標記。我還沒有實現標記的公式,因爲無法從textBox中得到結果。
另外我想問是否有可能從checkboxes得到3個答案被算作一個?
它應該很簡單,但我只是墜毀,不能解決這個問題。
太多的代碼。經驗法則:如果有滾動條,它太多了。 –
我讀了幾次,我仍然不知道你想要做什麼或者你的問題。也許你可以嘗試重寫這個。 – Bit