 |
|
|
 |
|
 |
hello sir,
i am working on C# for window application. so time validation on 23:59 format
then error message.
thanks
|
|
|
|
 |
|
 |
Hi pooran singh niranjan;
In order to help you I would need more information on the problem and the exact error message you are getting. Also what version of Visual Studio are you using.
Fernando
|
|
|
|
 |
|
 |
I dont see the code,I only see the demo.
|
|
|
|
 |
|
 |
Private Sub txt1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_ProdSpec.KeyPress
e.Handled = NumbersOnlywithPercentage(e.KeyChar, txt1, txt1.SelectionStart)
End Sub
--------
Public Function NumbersOnlywithPercentage(ByVal pstrChar As Char, ByVal oTextBox As TextBox, ByVal i As Integer) As Boolean
'validate the entry for a textbox limiting it to only numeric values and one decimal point
If (Convert.ToString(pstrChar) = "." And InStr(oTextBox.Text, ".")) Then Return True 'accept only one instance of the decimal point
If (Convert.ToString(pstrChar) = "-") Then Return True 'accept only positive value
If (Val(oTextBox.Text) < 100) And Val(Trim(oTextBox.Text).Insert(i, Trim(pstrChar))) <= 100 Then
Return False
Else
Return True
End If
'If (Val(oTextBox.Text) <= 100 And Val(oTextBox.Text) >= 0) Then Return False 'accept only 0 to 100
If Convert.ToString(pstrChar) <> "." And pstrChar <> vbBack Then
Return IIf(IsNumeric(pstrChar), False, True) 'check if numeric is returned
End If
Return False 'for backspace
End Function
N.K.Veeramani
Software Engineer
InteriTech SDN. BHD.,
Malaysia
|
|
|
|
 |
|
 |
Hi,
I downloaded the code and tested it. What confuses me is that I don't get to see the provided toolbox image, but just the standard icon. Also, in the code I don't find any reference to the image provided. Can you shed any light on this?
I would have expexted it to be either a class level attribute, or passed to the class in an event fired when loaded into the toolbox. But then again - there's no real instance of the class being loaded at that moment is there? That would rule out a "normal" control event unless a separate interface needs to be implemented that handles the loading into the toolbox.
But then again - maybe this is just a case where the VS2005 beta 2 project conversion wizard screws up. Because that's what I'm currently playing around with.
Any ideas?
Cheers
Michael
|
|
|
|
 |
|
 |
Just found it: inserted <ToolboxBitmap(GetType(TextBoxValidator), "TextBoxValidator.bmp")> _ right before the class' definition Designer attribute. But I'd still like to know why it didn't work initially. Is this a problem of the import wizard, or does vs2003/2002 directly link the class definition to the bitmap file by using corresponding names...?
|
|
|
|
 |
|
 |
Hi Michael;
This line of code must have been added by the project conversion wizard in VS 2005 Beta 2 but not by me.
_
Fernando
|
|
|
|
 |
|
 |
Sorry; that last post should have read as follows. This line of code must have been added by the project conversion wizard in VS 2005 Beta 2 but not by me. <ToolboxBitmap(GetType(TextBoxValidator), "TextBoxValidator.bmp")> _ Fernando
|
|
|
|
 |
|
 |
Hi Fernando,
This line of code must have been added by the project conversion wizard in VS 2005 Beta 2 but not by me.
<ToolboxBitmap(GetType(TextBoxValidator), "TextBoxValidator.bmp")> _
No, I did it manually. This was what made it work for me.
If you go to the Solution Explorer window and right click on the image file TextBoxValidator.bmp that is in the TextBoxValidate project and select Properties from the floating menu you will see a property called “Build Action” and it should be set to “Embedded Resource”. This places the image into the dll itself and when loaded into the Toolbox the system will find the image resource and use it as the icon in the Toolbox.
yes, I noticed that in your example code. Still, the image didn't show up untill I manually set the class attribute using the code line above. Probably Beta 2 behaves a little differently than previous versions, intended or not...
Also, I actually prefer to set the bitmap reference manually, because you can of course compile one DLL file containing multiple control classes. And if it were done in some automatic way as your posting suggests - if you have a dll containing two control classes with two images, in which way would they be joined together? By name...?
Cheers
Michael
-- modified at 10:44 Monday 12th September, 2005
|
|
|
|
 |
|
 |
Hi Michael;
To your question:
“Also, I actually prefer to set the bitmap reference manually, because you can of course compile one DLL file containing multiple control classes. And if it were done in some automatic way as your posting suggests - if you have a dll containing two control classes with two images, in which way would they be joined together? By name...?”
The names of the images that is embedded into the dll has to have its filename on the system compiling the control the same as the controls name. So if you have two controls in a single dll, ControlA and ControlB then the two image files for those controls must be ControlA.bmp and ControlB.bmp, the system will find the correct image for the correct control.
Have a great day;
Fernando
|
|
|
|
 |
|
 |
Hi Michael;
To your question :
“What confuses me is that I don't get to see the provided toolbox image, but just the standard icon. Also, in the code I don't find any reference to the image provided. Can you shed any light on this?”
If you go to the Solution Explorer window and right click on the image file TextBoxValidator.bmp that is in the TextBoxValidate project and select Properties from the floating menu you will see a property called “Build Action” and it should be set to “Embedded Resource”. This places the image into the dll itself and when loaded into the Toolbox the system will find the image resource and use it as the icon in the Toolbox.
Your question:
“I would have expexted it to be either a class level attribute, or passed to the class in an event fired when loaded into the toolbox. But then again - there's no real instance of the class being loaded at that moment is there?”
The first instance of the object does not get created until you first drag the object from the Toolbox to your form. As stated above the image for the control is embedded in the dll and the system finds that resource and uses it as the icon.
I have yet to get a copy of Visual Studio 2005 Beta 2 and load it on my machine so I would not be able to tell you if the project conversion wizard screws up or not, sorry.
Fernando
|
|
|
|
 |
|
 |
Dear Fernando :
First of all, let me give my sincere thanks to providing us this useful tool.
And I have a little question: does it require VS.net 2003? Since I can't customize my toolbar in VS.net 2002.
Any comments are greatly appreciated.
c u
Dundas
|
|
|
|
 |
|
 |
Hi Dundas;
I am glad that you found this article and code useful. May I ask that if you have not already rated this article can you please do so, it would be greatly appreciated. To rate the article just under the author info near the bottom of the page you will find a section called “Rate this Article for us!” with ratings from Roor to Excellent, Thank you.
The VB .Net Validation Control should work fine in VB .Net 2002 although I have not tested it in that version of the product nor have I used VB .Net 2002 myself. I have looked on the net and found the following info about adding the control to the Toolbox so that it can be dragged onto a form.
In the Microsoft Documentation located at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconreferencechangesinvisualbasic70.asp It states the following.
In Visual Basic 6.0, controls were added to a project in the Components dialog box. Once added, they were visible in the Toolbox.
In Visual Basic .NET, controls are added to the Toolbox in the Customize Toolbox dialog box.
The following link will bring you to a page called “Managing Tabs and Items in the Toolbox” http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxtskmanagingtoolstabsontoolbox.asp
I hope that the above info was of some help.
Fernando
|
|
|
|
 |
|
 |
Hi Fernando:
I just voted high to thank you for this code.
I still can't get it added into VS.net 2002 since it reports "no components...can be added in the dll" or similar things, but yes, no prob wiz .net 2003. After curiosity, I tried it on another machine wiz VS.net 2002, and it worked, so I'm not sure what happened to the previous one.
Anyways, I just report the above situation, and never mind about it, life's got 2 move on, if i happen to figure out later, I'll let u know.
good luck.
Dundas
|
|
|
|
 |
|
 |
Only glad to help.
Thank you.
Fernando
|
|
|
|
 |
|
 |
Perhaps it makes sense to invoke revalidation while setting a validation pattern. If the pattern is changed in run-time it will show immediately that the text entered does not match a new pattern.
|
|
|
|
 |
|
 |
This is a good suggestion and I will update the control to check the validation of the data in the text box after the property "Validation" has been updated with a new pattern.
Thanks
|
|
|
|
 |