Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sorry bcoz i pasted here full horrible code:-But i m unable to identify problem,so i pasted.

Code in vb.net (Working properly):-

'********* Code History 
Imports System.Text.RegularExpressions
Imports System.ComponentModel
Imports System.Drawing

Namespace ES.Components.Controls
    Public Class ESTextBox
        Inherits System.Windows.Forms.TextBox
#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
        End Sub

        'PCRMTextBox overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents ErrShow As System.Windows.Forms.ErrorProvider
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.ErrShow = New System.Windows.Forms.ErrorProvider
            '
            'ErrShow
            '
            Me.ErrShow.DataMember = ""
            '
            'ESTextBox
            '
            Me.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

        End Sub

#End Region

#Region " Variables "
        'This enum is used for the better understanding 
        'at the property window for the application user
        Public Enum enmValidateExpressions As Integer
            None = 1
            Numeric = 2
            Email = 3
            SSN = 4
            InPin = 5
            InPhone = 6
            IP = 7
            USPhone = 8
            USPin = 9
            WithoutSpecialCharacter = 10
            UpperCharWithoutSpecialCharacter = 11
            WebsiteAddress = 12
        End Enum

        ' enmValidateExpressions representation of the RegEx that will be used to 
        ' validate the text in the TextBox.  This is needed because
        ' the property needs to be exposed as a enmValidateExpressions to be set
        ' at design time.
        Protected validationPattern As enmValidateExpressions = enmValidateExpressions.None

        ' Message that should be available if the text does not 
        ' match the pattern.
        Protected mErrorMessage As String

        ' RegEx object that's used to perform the validation.
        Protected mValidationExpression As Regex

        ' Default color to use if the text in the TextBox is not
        ' valid.
        Protected mErrorColor As Color = Color.Black

        'Default value for after decimal numeric only
        Protected mAfterDecimal As Integer = 0

        'Default value for mMandatory field is false
        Protected mblnMandatory As Boolean = False

        'Message Id used set the message for the mandetory field
        Protected mstrMandatoryMsgId As String = ""

        'Message Id for setting error message if field is hving validation expression
        Protected mstrErrorId As String = ""

        Protected vIsLocked As Boolean = False
        Protected vValue As String = ""

        'To preserve Color value within GotFocus and LostFocus events call
        Protected BgColor As Color
#End Region

#Region " Property Region "
        Private vIsMandatory As Boolean = False
        Public Property IsMandatory() As Boolean
            Get
                Return vIsMandatory
            End Get
            Set(ByVal value As Boolean)
                vIsMandatory = value
            End Set
        End Property
        ' Allow to set the error message
        ' at design time or run time.
        <Description("Used to set the error message if validation not satisfies")> _
        Public Property ErrorMessage() As String
            Get
                Return mErrorMessage
            End Get
            Set(ByVal Value As String)
                mErrorMessage = Value
            End Set
        End Property

        ' If the TextBox text does not match the RegEx, then it
        ' will be changed to this color.
        <Description("If the TextBox text does not match the RegEx, then it will be changed to this color.")> _
        Public Property ErrorColor() As Color
            Get
                Return mErrorColor
            End Get
            Set(ByVal Value As Color)
                mErrorColor = Value
            End Set
        End Property

        <Description("Used to set the error message id to display message in multilingual")> _
        Public Property ErrorMessageId() As String
            Get
                Return mstrErrorId
            End Get
            Set(ByVal Value As String)
                mstrErrorId = Value
            End Set
        End Property

        ' Let's determine if the text in the TextBox
        ' is valid.
        <Description("Determine text in Textbox is valid")> _
        Public ReadOnly Property IsValid() As Boolean
            Get
                If Not mValidationExpression Is Nothing Then
                    Return mValidationExpression.IsMatch(Me.Text)
                Else
                    Return True
                End If
            End Get
        End Property

        Public ReadOnly Property CheckMandatory() As Boolean
            Get
                If MandatoryField Then
                    If Trim(Me.Text) = "" Then
                        '                    Me.Focus()
                        Return False
                    End If
                End If
                Return True
            End Get
        End Property

        ' Lets specify the regular expression (as a string) that will be 
        ' used to validate the text in the
        ' TextBox.  It's important that this be setable as a string
        ' (vs. a RegEx object) so that the developer can specify 
        ' the RegEx pattern using the properties window.
        <Description("Set the type of validation textbox should follow")> _
        Public Property ValidationExpression() As enmValidateExpressions
            Get
                Return validationPattern
            End Get
            Set(ByVal Value As enmValidateExpressions)
                Dim l_sValue As String
                l_sValue = ""
                Select Case Value
                    Case enmValidateExpressions.None
                        l_sValue = ""
                    Case enmValidateExpressions.Email
                        'user@seacomindia.com
                        l_sValue = "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$"
                    Case enmValidateExpressions.IP
                        '111.111.111.111
                        l_sValue = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$"
                    Case enmValidateExpressions.USPhone
                        '(123)123-1234
                        l_sValue = "^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$"
                    Case enmValidateExpressions.SSN
                        '123-23-1234
                        l_sValue = "^\d{3}-\d{2}-\d{4}$"
                    Case enmValidateExpressions.InPhone
                        '91-20-6125564 or 91-020-6125564 or 91-7235-6125564 
                        'Last part number digit can be 7 or 8 or 9 or 10
                        'l_sValue = "^\s*(\d{7}|(\d{2}-(\d{2}|\d{3}|\d{4})-(\d{7}|\d{8}|\d{9}|\d{10})))\s*$"
                        l_sValue = "^\s*(\d{7}|\d{8}|\d{9}|(\d{2}-(\d{2}|\d{3}|\d{4})-(\d{7}|\d{8}|\d{9}|\d{10})))\s*$"
                    Case enmValidateExpressions.InPin
                        l_sValue = "^(\d{6})$"
                    Case enmValidateExpressions.UpperCharWithoutSpecialCharacter
                        Me.CharacterCasing = CharacterCasing.Upper
                    Case enmValidateExpressions.WebsiteAddress
                        'www.seacomindia.com
                        l_sValue = "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*).(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$"

                End Select
                mValidationExpression = New Regex(l_sValue)
                validationPattern = Value
            End Set
        End Property

        <Description("Number of digits to consider after decimal points")> _
        Public Property AfterDecimalPt() As Integer
            Get
                Return mAfterDecimal
            End Get
            Set(ByVal Value As Integer)
                mAfterDecimal = Value
            End Set
        End Property

        <Description("Used to set the Mandatory filed option")> _
        Public Property MandatoryField() As Boolean
            Get
                Return mblnMandatory
            End Get
            Set(ByVal Value As Boolean)
                mblnMandatory = Value
            End Set
        End Property

        <Description("Property used to set the message Id for the Mandatory field")> _
        Public Property MandatoryMessageId() As String
            Get
                Return mstrMandatoryMsgId
            End Get
            Set(ByVal Value As String)
                mstrMandatoryMsgId = Value
            End Set
        End Property

        <Description("Used to set the Lock Editing")> _
        Public Property IsLocked() As Boolean
            Get
                IsLocked = vIsLocked
            End Get
            Set(ByVal Value As Boolean)
                vIsLocked = Value
            End Set
        End Property

        <Description("Used to set the Value")> _
        Public Property MyValue() As String
            Get
                MyValue = vValue
            End Get
            Set(ByVal Value As String)
                vValue = Value
            End Set
        End Property
#End Region

#Region " User defined function "
        Public Function IsTextBoxEmpty() As Boolean
            If Me.Text = "" Then
                Me.Focus()
                Return True
            Else
                Return False
            End If
        End Function
#End Region

#Region " Control Events "
        ' If the text does not match the RegEx, then change the
        ' color of the text to the ErrorColor.  If it does match
        ' then make sure it's displayed using the default color.
        <Description("Validating the text if it is not matched with validation then change error colour ")> _
        Protected Overrides Sub OnValidated(ByVal e As System.EventArgs)
            If Not Me.IsValid Then
                Me.ForeColor = mErrorColor
            Else
                Me.ForeColor = System.Windows.Forms.TextBox.DefaultForeColor
            End If

            ' Any time you inherit a control, and override one of
            ' the On... subs, it's critical that you call the On...
            ' method of the base class, or the control won't fire
            ' events like it's supposed to.
            MyBase.OnValidated(e)
        End Sub

        'This is base class event (TextBox) has trapped for numeric type 
        'to trapped the all keyboard button
        <Description("TextBox event trapped to check numeric values")> _
        Private Sub ESTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

            If vIsLocked = True Then e.Handled = True : Exit Sub

            Dim l_iKeyAscii As Integer


            If ValidationExpression = enmValidateExpressions.Numeric Then
                l_iKeyAscii = Asc(e.KeyChar)
                Select Case l_iKeyAscii
                    'These are 0-9 degits with backspace
                Case 48 To 57, 8, 13
                        If AfterDecimalPt > 0 Then
                            If InStr(Me.Text, ".") Then
                                If Len(Me.Text.Split(".")(1)) > AfterDecimalPt - 1 And l_iKeyAscii <> 8 Then
                                    'l_iKeyAscii = 0
                                End If
                            ElseIf Len(Me.Text) > Me.MaxLength - AfterDecimalPt - 2 And l_iKeyAscii <> 8 Then
                                l_iKeyAscii = 0
                            End If
                        End If
                        'Considering period
                    Case 46
                        'Checking number of points to consider after decimal points
                        If AfterDecimalPt > 0 Then
                            If InStr(Me.Text, ".") Then
                                l_iKeyAscii = 0
                            End If
                        Else
                            l_iKeyAscii = 0
                        End If
                        'If any key other than aboue key then no handling
                    Case Else
                        l_iKeyAscii = 0
                End Select
                'For trowing the key stroke
                If l_iKeyAscii = 0 Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            ElseIf (ValidationExpression = enmValidateExpressions.WithoutSpecialCharacter) Or (ValidationExpression = enmValidateExpressions.UpperCharWithoutSpecialCharacter) Then
                l_iKeyAscii = Asc(e.KeyChar)
                Select Case l_iKeyAscii
                    'These are special characters: (like !@#$%^&* etc)
                Case 33 To 47, 58 To 64, 91 To 96, 123 To 126
                        e.Handled = True
                    Case Else
                        e.Handled = False
                        ErrShow.SetError(Me, ErrorMessage)
                End Select
            ElseIf (ValidationExpression = enmValidateExpressions.Email) Then
                If Asc(e.KeyChar) = 32 Or InStr("~!`%^&*():"";'<>,/\+-", e.KeyChar) > 0 Then
                    e.Handled = True
                End If
            End If
        End Sub

        Private Sub ESTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus
            'Me.ForeColor = Me.DefaultForeColor
            'Added by Vijay B. Kodare
            BgColor = Me.BackColor
            '..........

            Me.BackColor = System.Drawing.Color.Honeydew
            Me.ForeColor = System.Drawing.Color.Blue
            If vIsLocked = True Then Exit Sub
            Me.SelectAll()
        End Sub

        Private Sub ESTextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus
            'Added by Vijay B. Kodare
            Me.BackColor = BgColor
            '............

            'Commented by Vijay B. Kodare
            ' System.Drawing.Color.White
            '...........
            Me.ForeColor = System.Drawing.Color.Black
        End Sub

        Private Sub ESTextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Validated
            Try
                If ValidationExpression = enmValidateExpressions.Numeric Then
                    ' Dim Num1 As Double
                    Dim I As Int16
                    If AfterDecimalPt > 0 Then
                        I = InStr(Me.Text, ".")
                        If Len(Mid(Me.Text, I)) > AfterDecimalPt Then
                            Me.Text = Mid(Me.Text, 1, I) & Mid(Me.Text, I + 1, AfterDecimalPt)
                        End If
                    End If
                ElseIf Me.CheckMandatory() Then
                    ErrShow.Dispose()
                Else
                    ErrShow.SetError(Me, ErrorMessage)
                End If
            Catch ex As Exception
            End Try
        End Sub

        Private Sub ESTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If e.KeyCode = Windows.Forms.Keys.Delete Then
                If vIsLocked = True Then e.Handled = True : Exit Sub
                'ElseIf e.KeyCode = Windows.Forms.Keys.Enter Then
                '    System.Windows.Forms.SendKeys.Send("{TAB}")
            End If
        End Sub
#End Region
    End Class
End Namespace


Converted this code to C# Through online code converter (Telrik):-But showing error:-(Converted code to c#):-

using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Drawing;

namespace NewJoinee
{
    public class ESTextBox : System.Windows.Forms.TextBox
    {
        #region " Windows Form Designer generated code "

        public ESTextBox()
            : base()
        {

            //This call is required by the Windows Form Designer.
            InitializeComponent();

            //Add any initialization after the InitializeComponent() call
        }

        //PCRMTextBox overrides dispose to clean up the component list.
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if ((components != null))
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        //Required by the Windows Form Designer

        private System.ComponentModel.IContainer components;
        //NOTE: The following procedure is required by the Windows Form Designer
        //It can be modified using the Windows Form Designer.  
        //Do not modify it using the code editor.
        internal System.Windows.Forms.ErrorProvider ErrShow;
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent()
        {
            this.ErrShow = new System.Windows.Forms.ErrorProvider();
            //
            //ErrShow
            //
            this.ErrShow.DataMember = "";
            //
            //ESTextBox
            //
            this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

        }

        #endregion

        #region " Variables "
        //This enum is used for the better understanding 
        //at the property window for the application user
        public enum enmValidateExpressions : int
        {
            None = 1,
            Numeric = 2,
            Email = 3,
            SSN = 4,
            InPin = 5,
            InPhone = 6,
            IP = 7,
            USPhone = 8,
            USPin = 9,
            WithoutSpecialCharacter = 10,
            UpperCharWithoutSpecialCharacter = 11,
            WebsiteAddress = 12
        }

        // enmValidateExpressions representation of the RegEx that will be used to 
        // validate the text in the TextBox.  This is needed because
        // the property needs to be exposed as a enmValidateExpressions to be set
        // at design time.

        protected enmValidateExpressions validationPattern = enmValidateExpressions.None;
        // Message that should be available if the text does not 
        // match the pattern.

        protected string mErrorMessage;
        // RegEx object that's used to perform the validation.

        protected Regex mValidationExpression;
        // Default color to use if the text in the TextBox is not
        // valid.

        protected Color mErrorColor = Color.Black;
        //Default value for after decimal numeric only

        protected int mAfterDecimal = 0;
        //Default value for mMandatory field is false

        protected bool mblnMandatory = false;
        //Message Id used set the message for the mandetory field

        protected string mstrMandatoryMsgId = "";
        //Message Id for setting error message if field is hving validation expression

        protected string mstrErrorId = "";
        protected bool vIsLocked = false;

        protected string vValue = "";
        //To preserve Color value within GotFocus and LostFocus events call
        #endregion
        protected Color BgColor;

        #region " Property Region "
        private bool vIsMandatory = false;
        public bool IsMandatory
        {
            get { return vIsMandatory; }
            set { vIsMandatory = value; }
        }
        // Allow to set the error message
        // at design time or run time.
        [Description("Used to set the error message if validation not satisfies")]
        public string ErrorMessage
        {
            get { return mErrorMessage; }
            set { mErrorMessage = value; }
        }

        // If the TextBox text does not match the RegEx, then it
        // will be changed to this color.
        [Description("If the TextBox text does not match the RegEx, then it will be changed to this color.")]
        public Color ErrorColor
        {
            get { return mErrorColor; }
            set { mErrorColor = value; }
        }

        [Description("Used to set the error message id to display message in multilingual")]
        public string ErrorMessageId
        {
            get { return mstrErrorId; }
            set { mstrErrorId = value; }
        }

        // Let's determine if the text in the TextBox
        // is valid.
        [Description("Determine text in Textbox is valid")]
        public bool IsValid
        {
            get
            {
                if ((mValidationExpression != null))
                {
                    return mValidationExpression.IsMatch(this.Text);
                }
                else
                {
                    return true;
                }
            }
        }

        public bool CheckMandatory
        {
            get
            {
                if (MandatoryField)
                {
                    if (string.IsNullOrEmpty((this.Text)))
                    {
                        //                    Me.Focus()
                        return false;
                    }
                }
                return true;
            }
        }

        // Lets specify the regular expression (as a string) that will be 
        // used to validate the text in the
        // TextBox.  It's important that this be setable as a string
        // (vs. a RegEx object) so that the developer can specify 
        // the RegEx pattern using the properties window.
        [Description("Set the type of validation textbox should follow")]
        public enmValidateExpressions ValidationExpression
        {
            get { return validationPattern; }
            set
            {
                string l_sValue = null;
                l_sValue = "";
                switch (value)
                {
                    case enmValidateExpressions.None:
                        l_sValue = "";
                        break;
                    case enmValidateExpressions.Email:
                        //user@seacomindia.com
                        l_sValue = "^([a-zA-Z0-9_\\-])([a-zA-Z0-9_\\-\\.]*)@(\\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}|((([a-zA-Z0-9\\-]+)\\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\])$";
                        break;
                    case enmValidateExpressions.IP:
                        //111.111.111.111
                        l_sValue = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$";
                        break;
                    case enmValidateExpressions.USPhone:
                        //(123)123-1234
                        l_sValue = "^((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}$";
                        break;
                    case enmValidateExpressions.SSN:
                        //123-23-1234
                        l_sValue = "^\\d{3}-\\d{2}-\\d{4}$";
                        break;
                    case enmValidateExpressions.InPhone:
                        //91-20-6125564 or 91-020-6125564 or 91-7235-6125564 
                        //Last part number digit can be 7 or 8 or 9 or 10
                        //l_sValue = "^\s*(\d{7}|(\d{2}-(\d{2}|\d{3}|\d{4})-(\d{7}|\d{8}|\d{9}|\d{10})))\s*$"
                        l_sValue = "^\\s*(\\d{7}|\\d{8}|\\d{9}|(\\d{2}-(\\d{2}|\\d{3}|\\d{4})-(\\d{7}|\\d{8}|\\d{9}|\\d{10})))\\s*$";
                        break;
                    case enmValidateExpressions.InPin:
                        l_sValue = "^(\\d{6})$";
                        break;
                    case enmValidateExpressions.UpperCharWithoutSpecialCharacter:
                        this.CharacterCasing = CharacterCasing;
                        break;
                    case enmValidateExpressions.WebsiteAddress:
                        //www.seacomindia.com
                        l_sValue = "^([a-zA-Z0-9_\\-])([a-zA-Z0-9_\\-\\.]*).(\\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}|((([a-zA-Z0-9\\-]+)\\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\])$";

                        break;
                }
                mValidationExpression = new Regex(l_sValue);
                validationPattern = value;
            }
        }

        [Description("Number of digits to consider after decimal points")]
        public int AfterDecimalPt
        {
            get { return mAfterDecimal; }
            set { mAfterDecimal = value; }
        }

        [Description("Used to set the Mandatory filed option")]
        public bool MandatoryField
        {
            get { return mblnMandatory; }
            set { mblnMandatory = value; }
        }

        [Description("Property used to set the message Id for the Mandatory field")]
        public string MandatoryMessageId
        {
            get { return mstrMandatoryMsgId; }
            set { mstrMandatoryMsgId = value; }
        }

        [Description("Used to set the Lock Editing")]
        public bool IsLocked
        {
            get { return IsLocked = vIsLocked; }
            set { vIsLocked = value; }
        }

        [Description("Used to set the Value")]
        public string MyValue
        {
            get { return MyValue = vValue; }
            set { vValue = value; }
        }
        #endregion

        #region " User defined function "
        public bool IsTextBoxEmpty()
        {
            if (string.IsNullOrEmpty(this.Text))
            {
                this.Focus();
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region " Control Events "
        // If the text does not match the RegEx, then change the
        // color of the text to the ErrorColor.  If it does match
        // then make sure it's displayed using the default color.
        [Description("Validating the text if it is not matched with validation then change error colour ")]
        protected override void OnValidated(System.EventArgs e)
        {
            if (!this.IsValid)
            {
                this.ForeColor = mErrorColor;
            }
            else
            {
                this.ForeColor = System.Windows.Forms.TextBox.DefaultForeColor;
            }

            // Any time you inherit a control, and override one of
            // the On... subs, it's critical that you call the On...
            // method of the base class, or the control won't fire
            // events like it's supposed to.
            base.OnValidated(e);
        }

        //This is base class event (TextBox) has trapped for numeric type 
        //to trapped the all keyboard button
        [Description("TextBox event trapped to check numeric values")]

        private void  // ERROR: Handles clauses are not supported in C#
ESTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (vIsLocked == true)
            {
                e.Handled = true; return;
            }

            int l_iKeyAscii = 0;


            if (ValidationExpression == enmValidateExpressions.Numeric)
            {
                l_iKeyAscii = Asc(e.KeyChar);
                switch (l_iKeyAscii)
                {
                    //These are 0-9 degits with backspace
                    case 48:
                    case 49:
                    case 50:
                    case 51:
                    case 52:
                    case 53:
                    case 54:
                    case 55:
                    case 56:
                    case 57:
                    case 8:
                    case 13:
                        if (AfterDecimalPt > 0)
                        {
                            if (InStr(this.Text, "."))
                            {                                
                                if (len(this.Text.Split(".")(1)) > AfterDecimalPt - 1 & l_iKeyAscii != 8)
                                {
                                    //l_iKeyAscii = 0
                                }
                            }
                            else if (Strings.Len(this.Text) > this.MaxLength - AfterDecimalPt - 2 & l_iKeyAscii != 8)
                            {
                                l_iKeyAscii = 0;
                            }
                        }
                        break;
                    //Considering period
                    case 46:
                        //Checking number of points to consider after decimal points
                        if (AfterDecimalPt > 0)
                        {
                            if (Strings.InStr(this.Text, "."))
                            {
                                l_iKeyAscii = 0;
                            }
                        }
                        else
                        {
                            l_iKeyAscii = 0;
                        }
                        break;
                    //If any key other than aboue key then no handling
                    default:
                        l_iKeyAscii = 0;
                        break;
                }
                //For trowing the key stroke
                if (l_iKeyAscii == 0)
                {
                    e.Handled = true;
                }
                else
                {
                    e.Handled = false;
                }
            }
            else if ((ValidationExpression == enmValidateExpressions.WithoutSpecialCharacter) | (ValidationExpression == enmValidateExpressions.UpperCharWithoutSpecialCharacter))
            {
                l_iKeyAscii = Strings.Asc(e.KeyChar);
                switch (l_iKeyAscii)
                {
                    //These are special characters: (like !@#$%^&* etc)
                    case 33: // TODO: to 47
                    case 58:
                    case 59:
                    case 60:
                    case 61:
                    case 62:
                    case 63:
                    case 64:
                    case 91:
                    case 92:
                    case 93:
                    case 94:
                    case 95:
                    case 96:
                    case 123:
                    case 124:
                    case 125:
                    case 126:
                        e.Handled = true;
                        break;
                    default:
                        e.Handled = false;
                        ErrShow.SetError(this, ErrorMessage);
                        break;
                }
            }
            else if ((ValidationExpression == enmValidateExpressions.Email))
            {
                if (Strings.Asc(e.KeyChar) == 32 | Strings.InStr("~!`%^&*():\";'<>,/\\+-", e.KeyChar) > 0)
                {
                    e.Handled = true;
                }
            }
        }

        private bool InStr(string p, string p_2)
        {
            throw new System.NotImplementedException();
        }

        private int Asc(char p)
        {
            throw new System.NotImplementedException();
        }

        private void  // ERROR: Handles clauses are not supported in C#
ESTextBox_GotFocus(object sender, System.EventArgs e)
        {
            //Me.ForeColor = Me.DefaultForeColor
            //Added by Vijay B. Kodare
            BgColor = this.BackColor;
            //..........

            this.BackColor = System.Drawing.Color.Honeydew;
            this.ForeColor = System.Drawing.Color.Blue;
            if (vIsLocked == true)
                return;
            this.SelectAll();
        }

        private void  // ERROR: Handles clauses are not supported in C#
ESTextBox_LostFocus(object sender, System.EventArgs e)
        {
            //Added by Vijay B. Kodare
            this.BackColor = BgColor;
            //............

            //Commented by Vijay B. Kodare
            // System.Drawing.Color.White
            //...........
            this.ForeColor = System.Drawing.Color.Black;
        }

        private void  // ERROR: Handles clauses are not supported in C#
ESTextBox_Validated(object sender, System.EventArgs e)
        {
            try
            {
                if (ValidationExpression == enmValidateExpressions.Numeric)
                {
                    // Dim Num1 As Double
                    System.Int16 I = default(System.Int16);
                    if (AfterDecimalPt > 0)
                    {
                        I = InStr(this.Text, ".");
                        if (Len(Strings.Mid(this.Text, I)) > AfterDecimalPt)
                        {
                            this.Text = Strings.Mid(this.Text, 1, I) + Strings.Mid(this.Text, I + 1, AfterDecimalPt);
                        }
                    }
                }
                else if (this.CheckMandatory())
                {
                    ErrShow.Dispose();
                }
                else
                {
                    ErrShow.SetError(this, ErrorMessage);
                }
            }
            catch (System.Exception ex)
            {
                
            }
        }

        private bool CheckMandatory()
        {
            throw new System.NotImplementedException();
        }

        private void  // ERROR: Handles clauses are not supported in C#
ESTextBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Delete)
            {
                if (vIsLocked == true)
                {
                    e.Handled = true; return;
                }
                //ElseIf e.KeyCode = Windows.Forms.Keys.Enter Then
                //    System.Windows.Forms.SendKeys.Send("{TAB}")
            }
        }
        #endregion
    }
}


Showing 13 error:-
1:-
The name 'len' does not exist in the current context	

2:-
VB
The best overloaded method match for 'string.Split(params char[])' has some invalid arguments  

3:-
VB
Argument '1': cannot convert from 'string' to 'char[]'  

4:-
The name 'Strings' does not exist in the current context

5,6,to 13 are same as 4th error.
Posted
Updated 18-Dec-12 20:39pm
v2
Comments
[no name] 19-Dec-12 2:26am    
Can you please tell us what exactly you want to do here?
Jibesh 19-Dec-12 7:33am    
This is sad. please do not post the WHOLE CODE. just the post the problem area unless otherwise some one requested for more code. you are simply dumping code project storage space!!
StackQ 19-Dec-12 11:47am    
Ya i agree with u,and i don't like this also,i m in problem so i pasted.Frm next time i will never do this mistake.

CheckMandatory() method is declared twice in your code.

Please check them. 1st one is a public and the second one is private.

Remove the second one which is not implemented.
 
Share this answer
 
Add Microsoft.VisualBasic reference to you Application/Project.

In your page, make use of the below

C#
using Microsoft.VisualBasic;


It should solve your problem. Happy Coding... :)

Regards,
Vamsi
 
Share this answer
 
Comments
StackQ 19-Dec-12 2:48am    
when i build my solution this shows only 1 error:-The type 'NewJoinee.ESTextBox' already contains a definition for 'CheckMandatory'

but after sometime again showing 13 error,can u tell me solution for this problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900