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 WindowsFormsApplication1
{
public class MainButton : Button
{
private string m_ValueNumber;
public MainButton(string ValueNumber,Point PLocation)
{
this.Text = "ป " + ValueNumber.ToString();
m_ValueNumber = ValueNumber;
this.Size = new Size(60,60);
this.Font = new Font(Font.FontFamily,8);
this.BackColor = Color.Yellow;
this.Margin = new Padding(0);
this.Location = PLocation;
}
protected override void OnClick(EventArgs e)
{
MessageBox.Show(m_ValueNumber.ToString());
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
this.AutoScroll = true;
short x = 0;
for (int b = 1; b <= 12; b++)
{
for (int a = 1; a <= 25; a++)
{
Button Button_Child = new MainButton(Add_Zero(x+a,3), new Point(a * 80,b * 80));
this.Controls.Add(Button_Child);
}
x += 25;
}
}
private string Add_Zero(int Number, int Amount)
{
string result = Number.ToString();
string zero = string.Empty;
int LengthNum = result.Length;
for (; LengthNum < Amount; LengthNum++)
{
zero += "0";
}
result = zero + result;
return result;
}
}
}
Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
For Each c As Control In Me.Controls
If TypeOf c Is Button Then
AddHandler c.Click, AddressOf JimThai
End If
Next
End Sub
Private Sub JimThai()
'TODO
End Sub
***** GoodLuck *****
Date :
2013-07-30 20:16:30
By :
ผ่านมา
No. 10
Guest
แก้ไข Private Sub JimThai
(Dynamic Handler with Parameters)
Code (VB.NET)
Sub JimThai(sender As Object, e As EventArgs)
'TO DO
MsgBox(DirectCast(sender, Button).Text)
'TO DO
End Sub
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is Button)
c.Click += new EventHandler(ChildButton_Click);
}
}
โค้ดด้านบนนี้ คือการผูกเหตุการณ์ไว้กับ Control Button บนฟอร์มทุกตัว ให้มันทำที่ ChildButton_Click ที่เดียว
Public Shared Function CrossOrTranspose(Of T)(source As IEnumerable(Of IEnumerable(Of T))) As IEnumerable(Of IEnumerable(Of T))
Return From r In source
From c In r.Select(Function(x, i) New KeyValuePair(Of Integer, T)(i, x))
Group c.Value By c.Key Into c = Group
Select TryCast(c, IEnumerable(Of T))
End Function
Try
Dim P52 As New SqlDataAdapter("select zonestatus,ZONEDATEEXPIRE from zone where zonenamep='" & "ป52" & "'", strcon)
Dim d52 As New DataTable
P52.Fill(d52) 'นำคำสั่ง sql ที่รันจาก d1 มาโชไนตาราง
If d52.Rows(0)("ZONEDATEEXPIRE").ToString = Now.Date Then
ป52.Enabled = True
ป52.BackColor = Color.Yellow
ป52.Text = "ป 52"
Dim update As String
update = "update zone set zonestatus='" & "ว่าง" & "' where zonenamep='" & "ป52" & "'"
Savedata(update)
Else
If d52.Rows(0)("zonestatus").ToString = "ไม่ว่าง" Then
ป52.Enabled = False
ป52.BackColor = Color.Red
ป52.Text = "ไม่ว่าง"
Else
ป52.Enabled = True
ป52.BackColor = Color.Yellow
ป52.Text = "ป 52"
End If
End If
Catch ex As Exception
End Try
Sub JimThai(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
MsgBox(b)
'TO DO
Call Beautiful(b)
End Sub
Sub Beautiful(ByVal b As Button)
Dim strName As String = b.Name
Dim strMsg As String = b.Text
Dim strExt As String = b.Tag '*****
b.Eanbled = True
'"update zone set zonestatus='" & "ว่าง" & "' where zonenamep='" & strName & "'"
End Sub
Try
Dim P52 As New SqlDataAdapter("select zonestatus,ZONEDATEEXPIRE from zone where zonenamep='" & "ป52" & "'", strcon)
Dim d52 As New DataTable
P52.Fill(d52) 'นำคำสั่ง sql ที่รันจาก d1 มาโชไนตาราง
If d52.Rows.Count > 0 Then '*****
If d52.Rows(0)("ZONEDATEEXPIRE") = Now.Date Then '*****
ป52.Enabled = True
ป52.BackColor = Color.Yellow
ป52.Text = "ป 52"
Dim update As String
update = "update zone set zonestatus='" & "ว่าง" & "' where zonenamep='" & "ป52" & "'"
Savedata(update)
Else
If d52.Rows(0)("zonestatus").ToString = "ไม่ว่าง" Then
ป52.Enabled = False
ป52.BackColor = Color.Red
ป52.Text = "ไม่ว่าง"
Else
ป52.Enabled = True
ป52.BackColor = Color.Yellow
ป52.Text = "ป 52"
End If
End If
Else
'TODO
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Date :
2013-08-02 08:38:07
By :
ผ่านมา
No. 37
Guest
อ้างถึงหัวข้อที่ #NO27 ความมุ่งมั่นพยายาม
Code (VB.NET)
Sub JimThai(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
MsgBox(b)
'TO DO
Call Beautiful(b)
End Sub
Sub Beautiful(ByVal b As Button)
Try
Dim P52 As New SqlDataAdapter("select zonestatus,ZONEDATEEXPIRE from zone where zonenamep='" & b.Text & "'", strcon)
Dim d52 As New DataTable
P52.Fill(d52) 'นำคำสั่ง sql ที่รันจาก d1 มาโชไนตาราง
If d52.Rows.Count > 0 Then '*****
If d52.Rows(0)("ZONEDATEEXPIRE") = Now.Date Then '*****
b.Enabled = True
b.BackColor = Color.Yellow
'b.Text = b.Text
Dim update As String
update = "update zone set zonestatus='" & "ว่าง" & "' where zonenamep='" & b.Text & "'"
Savedata(update)
Else
If d52.Rows(0)("zonestatus").ToString().Trim() = "ไม่ว่าง" Then
b.Enabled = False
b.BackColor = Color.Red
b.Text = "ไม่ว่าง"
Else
b.Enabled = True
b.BackColor = Color.Yellow
'b.Text = b.Text
End If
End If
Else
'TODO
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Date :
2013-08-02 08:57:19
By :
ผ่านมา
No. 38
Guest
*****
Code (VB.NET)
Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
For Each c As Control In Me.Controls
If TypeOf c Is Button Then
AddHandler c.Click, AddressOf JimThai
c.Tag = c.Text '***** เก็บค่าเดิมเอาไว้อ้างอิง
End If
Next
End Sub
Sub JimThai(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
MsgBox(b)
'TO DO
Call Beautiful(b)
End Sub
Sub Beautiful(ByVal b As Button)
Try
Dim P52 As New SqlDataAdapter("select zonestatus,ZONEDATEEXPIRE from zone where zonenamep='" & b.Text & "'", strcon)
Dim d52 As New DataTable
P52.Fill(d52) 'นำคำสั่ง sql ที่รันจาก d1 มาโชไนตาราง
If d52.Rows.Count > 0 Then '*****
If d52.Rows(0)("ZONEDATEEXPIRE") = Now.Date Then '*****
b.Enabled = True
b.BackColor = Color.Yellow
b.Text = b.Tag ' *****
Dim update As String
update = "update zone set zonestatus='" & "ว่าง" & "' where zonenamep='" & b.Text & "'"
Savedata(update)
Else
If d52.Rows(0)("zonestatus").ToString().Trim() = "ไม่ว่าง" Then
b.Enabled = False
b.BackColor = Color.Red
b.Text = "ไม่ว่าง"
Else
b.Enabled = True
b.BackColor = Color.Yellow
b.Text = b.Tag ' *****
End If
End If
Else
'TODO
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
***** GoodLuck *****
Date :
2013-08-02 09:30:18
By :
ผ่านมา
No. 40
Guest
Code (VB.NET)
Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
For Each c As Control In Me.Controls
If TypeOf c Is Button Then
AddHandler c.Click, AddressOf JimThai
c.Tag = c.Text '***** เก็บค่าเดิมเอาไว้อ้างอิง
End If
Next
End Sub