|
|
|
จาก Code ผมจะเอาค่า Array ที่เก็บมาแสดงเฉพาะที่มันซ้ำกัน เช่น 2,3,4,5,5,6,7,8 แล้วผมใส่เลข 5 ลง TextSearch ให้มันแสดงผลออกมาว่า 5 อยู่ TextBox ไหน มีกี่ตัว แบบนี้ทำได้มั้ยครับ รบกวนหน่อยครับ |
|
|
|
|
|
|
|
จาก Code ผมจะเอาค่า Array ที่เก็บมาแสดงเฉพาะที่มันซ้ำกัน เช่น 2,3,4,5,5,6,7,8
แล้วผมใส่เลข 5 ลง TextSearch ให้มันแสดงผลออกมาว่า
5 อยู่ TextBox ไหน มีกี่ตัว แบบนี้ทำได้มั้ยครับ รบกวนหน่อยครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FirstP
{
public partial class TestForm : Form
{
private bool restart;
public TestForm()
{
InitializeComponent();
}private void OnlyNumber(object sender,KeyEventArgs e) {
TextBox tb1 = (TextBox)sender;
if (restart)
{
sender = "";
restart = false;
}
if (!(e.KeyValue == '0'
|| e.KeyValue == '1'
|| e.KeyValue == '2'
|| e.KeyValue == '3'
|| e.KeyValue == '4'
|| e.KeyValue == '5'
|| e.KeyValue == '6'
|| e.KeyValue == '7'
|| e.KeyValue == '8'
|| e.KeyValue == '9'
))
{
e.SuppressKeyPress = true;
}
}
private void btn1_Click(object sender, EventArgs e)
{
string[] str1 = txt1.Text.Split(',');
int len = str1.Length;
string[] str2 = txt2.Text.Split(',');
len = str2.Length;
string[] str3 = txt3.Text.Split(',');
len = str3.Length;
string[] str4 = txt4.Text.Split(',');
len = str4.Length;
string[] str5 = txt5.Text.Split(',');
len = str5.Length;
string[] str6 = txt6.Text.Split(',');
len = str6.Length;
string[] str7 = txt7.Text.Split(',');
len = str7.Length;
string[] str8 = txt8.Text.Split(',');
len = str8.Length;
string[] str9 = txt9.Text.Split(',');
len = str9.Length;
string[] str10 = txt10.Text.Split(',');
len = str10.Length;
int[] a = new int[len];
int[] b = new int[len];
int[] c = new int[len];
int[] d = new int[len];
int[] z = new int[len];
int[] f = new int[len];
int[] g = new int[len];
int[] h = new int[len];
int[] j = new int[len];
int[] k = new int[len];
for (int i = 0; i < len; i++)
{
a[i] = Convert.ToInt32(str1[i]);
b[i] = Convert.ToInt32(str2[i]);
c[i] = Convert.ToInt32(str3[i]);
d[i] = Convert.ToInt32(str4[i]);
z[i] = Convert.ToInt32(str5[i]);
f[i] = Convert.ToInt32(str6[i]);
g[i] = Convert.ToInt32(str7[i]);
h[i] = Convert.ToInt32(str8[i]);
j[i] = Convert.ToInt32(str9[i]);
k[i] = Convert.ToInt32(str10[i]);
}
string str11 = "";
for(int i = len - 1; i >= 0; i--)
{
str11 = str11 + a[i].ToString() + "," + b[i].ToString() +"," +c[i].ToString()+ ","
+ d[i].ToString() + "," +z[i].ToString() + "," + f[i].ToString() + ","
+ g[i].ToString() + "," + h[i].ToString() + "," + j[i].ToString() + ","
+ k[i].ToString() + ",";
}
if (txtSearch.Text == txtSearch.Text) {
lbl1.Text = txtSearch.Text;
}
}
private void txt1_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt2_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt3_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt4_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt5_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt6_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt7_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt8_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt9_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txt10_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
private void txtSearch_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb1 = (TextBox)sender;
OnlyNumber(sender, e);
}
}
}
Tag : Win (Windows App), C#
|
ประวัติการแก้ไข 2018-12-19 22:24:28
|
|
|
|
|
Date :
2018-12-19 16:34:23 |
By :
wiraphon |
View :
687 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองไปใช้พวก Lit<T> และ LINQ ครับ จะสามารถจัดการพวกตัวแปรพวกนี้ได้ง่ายขึ้นครับ
|
|
|
|
|
Date :
2018-12-20 17:43:40 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|