我想做一个程序,在将数字输入文本框后会显示适当的图像。例如,如果您键入 1 和 2,将显示蜡烛和天鹅,程序将帮助记住数字的助记系统。这是我的代码:
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 WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string dane = textBox1.Text;
if (dane == "")
{
MessageBox.Show("No number");
}
else
{
bool jest_liczba = true;
try
{
double dane_ok = System.Convert.ToDouble(dane);
}
catch
{
MessageBox.Show("no int");
jest_liczba = false;
}
if (jest_liczba == true)
{
}
}
}
private void button1_Click(object sender, EventArgs e)
{
string temp = textBox1.Text; //table
for (int i = 0; i < temp.Length; i++)
{
textBox1.Text = char.ToString(temp[i]);
}
string _katalog = @"c:\obrazki\"; //load picture
string _typ = ".jpg";
int _liczba;
if (Int32.TryParse(textBox1.Text, out _liczba))
{
pictureBox1.Image = Image.FromFile(_katalog + _liczba + _typ);
}
}
}
}
输入几个数字后的程序,只显示一个图像。请帮忙