Myanmar IT Resource Forum
Myanmar IT Resource Forum
Myanmar IT Resource Forum

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

sHa92

sHa92
Founder



Founder
Web Application ေတြမွာဆုိရင္ Validation Control ေတြကို ဖန္တီးရတာ လြယ္ပါတယ္။
ဒါေပမယ့္ Windows Application တစ္ခုမွာ Validation Control နဲ႔ ေရးေတာ့မယ္ဆုိရင္ေတာ့ နည္းနည္း ခက္ခဲတဲ့အလုပ္ပါ.
က်ေနာ္ စေရးတုန္းကဆို ေတာ္ေတာ္ တုိင္ပတ္ခဲ့တာ။ အခုေတာ့ အရင္က က်ေနာ္ေရးဖူးတဲ့ Code ေတြကို ၿပန္ရွဲေပးပါမယ္။

အခု ေအာက္မွာ ရွဲမယ့္ code ကေတာ့ textbox
တစ္ခုရဲ႕ Decimal Values ေတြကို Validate လုပ္မွာပါ။

ဥပမာ: က်ေနာ္တုိ႔ဟာ textbox decimal values တစ္ခုကို ရိုက္ထည့္ဖို႔လုိမယ္ဆုိပါစုိ႔။ ဥပမာ (123.34) ကိုရိုက္ထည့္မယ္ေပါ့။
text box ရဲ႕ Properties ကို လုံး၀မခ်ိန္းဘဲနဲ႔ Default Validate လုပ္သြားၾကည့္ရေအာင္ပါ။

KeyPress လုပ္လုိက္တဲ့ အခ်ိန္ေလးမွာ က်ေနာ္တို႔ဟာ ေအာက္မွာေပးထားတဲ့ Method ကို Call ၿပီးေတာ့ decimal values ေတြကို စစ္ၾကပါမယ္။
က်ေနာ္တို႔ (2124.98) ကိုရိုက္ခ်င္တယ္ဆုိရင္ pass bd value =4 နဲ႔ ad value = 2
ဆုိၿပီးေတာ့ ရိုက္ေပးရပါမယ္။

Code ကို Run ၾကည့္ရင္းနဲ႔ နားလည္သြားပါလိမ့္မယ္။

Shared Sub ChkDecimal(ByVal Ctxt As System.Windows.Forms.TextBox, ByVal x As System.Windows.Forms.KeyPressEventArgs, ByVal bd As Int16, ByVal ad As Int16)


Ctxt.Text = Ctxt.Text.Trim

If (Char.IsControl(x.KeyChar) Or Char.IsDigit(x.KeyChar) = True) Or Asc(x.KeyChar) = 46 Or Asc(x.KeyChar) = 45 Or



Asc(x.KeyChar) = 8 Then

If ((Ctxt.Text.IndexOf(".") <> -1 And x.KeyChar = ".") Or (Ctxt.Text.IndexOf("-") = 0 And x.KeyChar = "-") Or



(Ctxt.Text.IndexOf("-") = 0 And Ctxt.SelectionStart = 0 And Asc(x.KeyChar) <> Cool) And Ctxt.SelectionLength = 0 Then

x.Handled = True

ElseIf (Ctxt.Text <> "" And x.KeyChar = "-" And Ctxt.SelectionStart <> 0) Then

x.Handled = True

Else

If Ctxt.Text.IndexOf(".") <> -1 Then

If Ctxt.SelectionStart >= 0 And Asc(x.KeyChar) <> 8 Then

If ((((Mid(Ctxt.Text, Ctxt.Text.IndexOf(".") + 1).Length > ad + 1 And Ctxt.SelectionStart >



Ctxt.Text.IndexOf(".")) Or (Mid(Ctxt.Text, 1, Ctxt.Text.IndexOf(".") + 1).Length > bd And Ctxt.SelectionStart <> "-") And Ctxt.SelectionLength = 0) Or _

((((Mid(Ctxt.Text, Ctxt.Text.IndexOf(".") + 1).Length > ad And Ctxt.SelectionStart >



Ctxt.Text.IndexOf(".")) Or (Mid(Ctxt.Text, 2, Ctxt.Text.IndexOf(".")).Length > bd And Ctxt.SelectionStart <> -1)) And Ctxt.SelectionLength = 0) Then

x.Handled = True

End If

End If

Else

If (Ctxt.Text.IndexOf("-") <> -1 And Ctxt.SelectionLength = 0 And ((Mid(Ctxt.Text, 2).Length > bd - 1 And



x.KeyChar <> "." And Asc(x.KeyChar) <> Cool Or (Ctxt.SelectionStart > bd + 1 And x.KeyChar.ToString.Equals(".")))) Or _

(Ctxt.Text.IndexOf("-") = -1 And Ctxt.SelectionLength = 0 And (((Mid(Ctxt.Text, 1).Length > bd - 1



And x.KeyChar <> "." And Asc(x.KeyChar) <> Cool And Asc(x.KeyChar) <> 45) Or (Ctxt.SelectionStart > bd And



x.KeyChar.ToString.Equals(".")))) Then

x.Handled = True

End If

End If

End If

Else

x.Handled = True

End If

End Sub

http://www.myanmaritresource.info

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum

 

Create a forum on Forumotion | ©phpBB | Free forum support | Report an abuse | Cookies | Forumotion.com