 |
|
 |
Hello Dear Mr Jibin Pan,
I have just downloaded your sample code "Masked C# TextBox Control" from Csharphelp.com and from here too. I'm from iran and here we use PersianDate format (Shamsi). recently I'm working on an Accounting Application in wich date field is frequently used, and your Control is EXACTLY what i was looking for !!! Since your control dose not support (shamsi) date i can not use it. I have tried to change its format but i got Confused !!! So I want you to help me on this, and change (only the Date format) of this control as the following format:
------------------------Persian Date Format
public readonly short[] Persian_Month_day = { 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 };
private bool CheckDayOfMonth_Pr(int mon, int day) { if (day > Persian_Month_day[mon-1] || day == 0) return false; else return true; } ------------------------------------------
yyyy/mm/dd like "1386/08/20" or "86/08/20"
year starts with "1" or "13" like "1386"
------------------------Persian Date Format
I appreciate your help.
Shahab
-- modified at 13:31 Monday 12th November, 2007
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |
|
 |
Hi,
i wil working in crystal report with ms-sql 2000. then eg query has select* from table_name where condition='condition' how can i do that above query statement in crystal report. i.e... table_name=any table_name, condition=any condition
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
what is mask 4 email...
is it this right?
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
how we analysis mask?
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Look for something called Expresso it is a tool someone told me to use and now I never code without it.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
This is regarding the PhoneWithArea Mask..if you start using the backspace from '-' i.e. middle of the string..you can type endless characters )
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Suppose I want to use this in what I imagine is almost the simplest possible scenario.
I have a very simple stateless list of characters that I will allow, let's say [A-Za-z!@#$%].
How do I set the masked text box to allow only and any of those characters, and no other?
I cannot find any decent documentation on MSDN, except silly little examples about how to do social security numbers. Maybe I'm just not looking in the right places.
(Moving beyond the simplest possible use, the next question would be how to do context-dependent regular expressions, ya?)
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Very usefull control!
It would be perfect if Copy/paste was also implemented with the mask function.
Jeff
|
| Sign In·View Thread·PermaLink | 3.50/5 |
|
|
|
 |
|
|
 |
|
 |
Does anybody know how to implement the MaskedTextBox.dll into SharpDevelop ? ( http://www.sharpdevelop.com/OpenSource/SD/Default.aspx ) 
Thank you for any answer !
|
| Sign In·View Thread·PermaLink | 1.33/5 |
|
|
|
 |
|
 |
hello, its a good work, but, it doesnt work fine with the ip mask... i could write numbers > 255 and its wrong...
im lookin to give a solution, but i am unable to find it...
thanks... great job....
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |
|
 |
the mask for an IP adress is : #^([O1]?\d\d?|2[0-4]\d|25[0-5]).([O1]?\d\d?|2[0-4]\d|25[0-5]).([O1]?\d\d?|2[0-4]\d|25[0-5]).([O1]?\d\d?|2[0-4]\d|25[0-5])$#
(I don't test it but I think it's ok)
details : ([O1]?\d\d?|2[0-4]\d|25[0-5]) : - number like 0 - 199 Or number like 200 - 249 Or number like 250 - 255
-- modified at 6:09 Wednesday 14th June, 2006
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Sometimes a user will pass over the masked text box not having an entry. Throughout the session the red exclamation icon remains on.
Is there a way I can clear/reset the Error Provider icon?
cb
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Well I finally figured out a way to clear the error provider icon.
You just have to enable = false; refresh; enable = true; refresh the control and it goes away.
Kind of clumsy would perfrer a mehtod to clear.
cb
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I know it is some time since you asked the question, but it may be useful for new readers
I have solved this by adding a new function to the class, called ResetError
public void ResetError() { this.errorProvider1.SetError(this, ""); }
and then calling it from my code
ie
this.txtBox.ResetError();
Hope it helps
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello! The german date format is dd/mm/yyyy How can I get the control to work with this format? I tried to understand the C# code, but... BTW: The locales are "germen" already (as told in another thread).
rm -rf /bin/laden
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello,
I hope my code will fit in this reply. This is code I found on the codeproject site but I changed it to dd/mm/yyyy format. There are two porblems with it : - you can not go in override mode, to change the day you need to use backspace till the beginning and then put in the data completely again. - If you use backspace to far, you will get a runtime error.
Hope it helps, any comments are apreciated Nicky
public class DateTextBox : System.Windows.Forms.TextBox { public enum Mask {None, DateOnly, PhoneWithArea, IpAddress, SSN, Decimal, Digit }; private Mask m_mask;
public Mask Masked { get { return m_mask;} set { m_mask = value; this.Text=""; } } private int digitPos=0; private int DelimitNumber=0; private bool CtrlV = false;
private System.ComponentModel.Container components = null;
public DateTextBox() { InitializeComponent(); if(Masked != Mask.None) m_mask = Masked; digitPos=0; // Positie van het cijfer binnen de groep DelimitNumber=0; // Aantal scheidingtekens this.Text=null;
this.ContextMenu = new ContextMenu(); }
protected override void Dispose( bool disposing ) { if( disposing ) { if( components != null ) components.Dispose(); } base.Dispose( disposing ); }
#region Component Designer generated code private void InitializeComponent() { this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnKeyPress); this.Leave += new System.EventHandler(this.OnLeave); } #endregion
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { // trap Ctrl-V paste and prevent invalid values // return false to allow further processing CtrlV = false; if(keyData == (Keys)Shortcut.CtrlV || keyData == (Keys)Shortcut.ShiftIns) { IDataObject iData = Clipboard.GetDataObject(); CtrlV = true;
// assemble new string and check IsValid string newText; newText = base.Text.Substring(0, base.SelectionStart) + (string)iData.GetData(DataFormats.Text) + base.Text.Substring(base.SelectionStart + base.SelectionLength);
// check if data to be pasted is convertable to inputType if(!IsValid(newText)) return true; } if(keyData == (Keys)Shortcut.Del) { // OPvangen delete this.Text = ""; digitPos = 0; DelimitNumber = 0; } if(keyData == (Keys)Shortcut.CtrlC) { // Kopieer in clipbord, verder gebeurt er niets CtrlV = true; Clipboard.SetDataObject(this.Text,true); }
return base.ProcessCmdKey(ref msg, keyData); }
private bool IsValid(string val) { // testen van een volledige string, meestal via copy verkregen
bool ret = true;
if(val.Equals("") || val.Equals(string.Empty)) return ret;
// Klopt de structuurweergave Regex regStr = new Regex(@"\d{2}/\d{2}/\d{4}"); if(!regStr.IsMatch(val)) return false;
// Test maand int m = Int32.Parse(val.Substring(3,2)); if (m <= 0 || m > 12) return false;
// Test dagen int d = Int32.Parse(val.Substring(0,2)); if(!CheckDayOfMonth(m,d)) return false;
// Test jaar int j = Int32.Parse(val.Substring(6,4)); if (j < 1900 || j > 2200) return false;
return ret; }
private void OnKeyPress(object sender, KeyPressEventArgs e) { DateTextBox sd = (DateTextBox) sender; if (!CtrlV) // Geen formatering doen als we via de paste komen of indien we Ctrl-C gedrukt hebbenh sd.MaskDate(e); }
private void OnLeave(object sender, EventArgs e) { DateTextBox sd = (DateTextBox) sender; Regex regStr; regStr = new Regex(@"\d{2}/\d{2}/\d{4}"); if (sd.Text != "") { if(!regStr.IsMatch(sd.Text)) sd.Focus(); } } private void MaskDate(KeyPressEventArgs e) { int len = this.Text.Length; int indx = this.Text.LastIndexOf("/"); if(Char.IsDigit(e.KeyChar) || e.KeyChar == '/' || e.KeyChar == 8) { if (e.KeyChar != 8) { if (e.KeyChar != '/' ) { // Bepaal positie in de groep if(indx > 0) // Er is al een scheidingteken digitPos = len-indx; // Bepaal positie binnen de groep (dag/Maand/jaar) else digitPos++; // Poistie binnen de eerste groep
if (digitPos == 3 && DelimitNumber < 2) { // Maximaal 2 posities voor dag of maand if (e.KeyChar != '/') { DelimitNumber++; this.AppendText("/"); } }
// 2e positie in dag of maand gedeelte of if (digitPos == 2) { if(DelimitNumber < 2) // daggedeelte of maandgedeelte { if(digitPos==1) this.AppendText("0"); // zet 0 voor this.AppendText(e.KeyChar.ToString()); // Daarna ingegeven cijfer if(indx < 0) // Eerste deel = dag { if(Int32.Parse(this.Text)> 31) // check validation { string str; str = this.Text.Insert(0, "0"); this.Text =str.Insert(2, "/0"); DelimitNumber++;
// Controle dagen int d = Int32.Parse(this.Text.Substring(0,2)); if(!CheckDayOfMonth(Int32.Parse(this.Text.Substring(3,2)),d)) { this.Text = ""; this.Select(0,0); // Om juiste positie te bepalen digitPos = 0; DelimitNumber = 0; } else { this.AppendText("/"); DelimitNumber++; } } else // dag <= 31 { if (Int32.Parse(this.Text) != 0) { // Voeg scheidingsteken toe this.AppendText("/"); DelimitNumber++; } else { this.Text = this.Text.Substring(0,this.Text.Length - 1); this.Select(2,0); digitPos=1; } } e.Handled=true; } else // Tweede (maand) deel of derde (jaar) deel { if( DelimitNumber == 1) // maand gedeelte { if(Int32.Parse(this.Text.Substring(3,2))> 12) // check validation { this.Text = this.Text.Substring(0,this.Text.Length - 1); this.Select(5,0); // Om juiste positie te bepalen digitPos=1; e.Handled=true; } else { // Bepaal max. aantal dagen int d = Int32.Parse(this.Text.Substring(0,indx)); if (Int32.Parse(this.Text.Substring(3,2)) == 0) { this.Text = this.Text.Substring(0,this.Text.Length - 1); this.Select(4,0); // Om juiste positie te bepalen digitPos=0; } else if(!CheckDayOfMonth(Int32.Parse(this.Text.Substring(3,2)),d)) { this.Text = ""; this.Select(0,0); // Om juiste positie te bepalen digitPos = 0; DelimitNumber = 0; } else { this.AppendText("/"); DelimitNumber++; } } e.Handled = true; } } } } else if(digitPos == 1 && Int32.Parse(e.KeyChar.ToString())>3 && DelimitNumber==0) { // Eerste poistie is > 3, dan zet men er een 0 voor, aantal dagen niet > 31 if(digitPos==1) this.AppendText("0"); this.AppendText(e.KeyChar.ToString()); this.AppendText("/"); DelimitNumber++; e.Handled = true; } else if(digitPos == 1 && Int32.Parse(e.KeyChar.ToString())>1 && DelimitNumber==1) { // Eerste poistie is > 1, dan zet men er een 0 voor, aantal maanden niet > 20 if(digitPos==1) this.AppendText("0"); this.AppendText(e.KeyChar.ToString()); // Bepaal max. aantal dagen int d = Int32.Parse(this.Text.Substring(0,indx)); if(!CheckDayOfMonth(Int32.Parse(this.Text.Substring(3,2)),d)) { this.Text = ""; this.Select(0,0); // Om juiste positie te bepalen digitPos = 0; DelimitNumber = 0; } else { this.AppendText("/"); DelimitNumber++; } e.Handled = true; } else { // Jaar moet in 1900 of 2000 liggen if(digitPos == 1 && DelimitNumber==2 && e.KeyChar > '2') e.Handled = true; } if( digitPos > 4) e.Handled = true; } else { // Ingave slash DelimitNumber++; if (DelimitNumber == 3) { // de laatste verwijderen //this.Text = this.Text.Substring(0,this.Text.Length - 1); //this.Select(this.Text.Length,0); DelimitNumber--; e.Handled = true; } else { if ((DelimitNumber == 2) && (this.Text.Substring(this.Text.Length - 1,1) == "/")) // 2 na elkaar { //this.Text = this.Text.Substring(0,this.Text.Length - 1); //this.Select(this.Text.Length,0); DelimitNumber--; e.Handled = true; } else { string tmp3; if(indx == -1) tmp3 = this.Text.Substring(indx+1); else tmp3 = this.Text; if(digitPos == 1) { this.Text = tmp3.Insert(indx+1,"0");; this.AppendText("/"); e.Handled = true; } } } } } else // BackSpace ingegeven char(8) { e.Handled = true; if((len-indx) == 1) { DelimitNumber--; if (indx > -1 ) digitPos = 2; else digitPos--; } else { if(indx > -1) digitPos=len-indx-1; else digitPos=len-1; } this.Text = this.Text.Substring(0,this.Text.Length - 1); this.Select(this.Text.Length,0); } } else { e.Handled = true; // opvangen return //if (e.KeyChar == 13) // this.OnLeave(sender, EventArgs);
} } private bool CheckDayOfMonth(int mon, int day) { bool ret=true; if(day==0) ret=false; switch(mon) { case 1: if(day > 31 ) ret=false; break; case 2: System.DateTime moment = DateTime.Now; int year = moment.Year; int d = ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 ; if(day > d) ret=false; break; case 3: if(day > 31 ) ret=false; break; case 4: if(day > 30 ) ret=false; break; case 5: if(day > 31 ) ret=false; break; case 6: if(day > 30 ) ret=false; break; case 7: if(day > 31 ) ret=false; break; case 8: if(day > 31 ) ret=false; break; case 9: if(day > 30 ) ret=false; break; case 10: if(day > 31 ) ret=false; break; case 11: if(day > 30 ) ret=false; break; case 12: if(day > 31 ) ret=false; break; default: ret=false; break; } return ret; } }
|
| Sign In·View Thread·PermaLink | 3.00/5 |
|
|
|
 |
|
 |
problems mentioned before are already solved in the new version of jian-ping . Mine is an old version I changed to the dd/mm/yyyy format
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Control work properly only if I put digit in sequence from left to right.
If I insert a date and then I change the day or month, the control don't process correctly new digit.
|
| Sign In·View Thread·PermaLink | 2.75/5 |
|
|
|
 |
|
 |
Hi Everybody,
The new src code include the changes:
you can insert char in the middle of the string you can replace the selected string with new type in char you can delete char in the middle of the string using backspace key. the decimal can have negative number.
Thanks for all the people who like the control.
Regards
Jibin Pan
|
| Sign In·View Thread·PermaLink | 3.25/5 |
|
|
|
 |
|
 |
hi i have a problem... i want that in winforms..when i press Enter button in text bos then focus should in next text box..... this is my problem only..
vvvvvv
|
| Sign In·View Thread·PermaLink | 2.50/5 |
|
|
|
 |
 | Cars  Oliver Jones | 5:15 28 Oct '03 |
|
|
 |
|
 |
I suppose it's easy for someone who studied (or wrote) the date only code. There are a lot of nested if-structures...
thx
|
| Sign In·View Thread·PermaLink | 2.25/5 |
|
|
|
 |
|
|
 |