I am using class library in vb 2010 to make a custom textbox control.
i'm trying to add the list of control components which are in the main form
to the textbox property,
when i add a new textbox (my custom textbox) to the form
i need the class to get the form component like (AxComms, Labels, ...etc) and deal with this component from my class (my custom textbox),
like get it's name as i tried below "CXComm = Comms.Name" before run the application
just when i drop the custom textbox in the form.
I trid the code below at sub new but the "
Application.OpenForms.Item(0)
" just work and get the open Forms when the application is running.
and so on i can't access the form Control Components
What I have tried:
Imports System.Windows.Forms
Imports System.IO
Imports System.ComponentModel
Imports System.Drawing
Imports CXSERVERCOMMUNICATIONSCONTROLLib
Imports System.Drawing.Drawing2D
Public Class Fit_TextBox
Inherits System.Windows.Forms.TextBox
Public Comms As New AxCXSERVERCOMMUNICATIONSCONTROLLib.AxComms
Dim CommsInForm As AxCXSERVERCOMMUNICATIONSCONTROLLib.AxComms
Dim curColor As Color
Dim lastData As Single
Dim MaxValue As Decimal
Dim MinValue As Decimal
Dim FactorVal As Decimal = 1
Dim mainToolTip As String
Dim txtval As String
Dim FormName As String = "frmMain"
Dim pnlName As String = "Panel1"
Dim CXComm As String = "AxComms1"
Dim tagname As String = "Tag"
Dim plcName As String = "PLC"
Dim ErrorProvider1 As New System.Windows.Forms.ErrorProvider
Public x As TextBox
Dim Error_Bit As Boolean = False
Dim frm As Form
Dim toolTip1 As New ToolTip()
Dim lbl As Label
Dim txt As TextBox
Dim pnl, pnlC As Panel
Dim Highlighter1 As New DevComponents.DotNetBar.Validator.Highlighter
Public Sub New()
frm = Application.OpenForms.Item(0)
For Each c As Control In frm.Controls
If InStr(c.Name, "AxComms1") Then
Comms = c
CXComm = Comms.Name
End If
Next
End Sub
Property Comms_In_Form As AxCXSERVERCOMMUNICATIONSCONTROLLib.AxComms
Get
Return CommsInForm
End Get
Set(value As AxCXSERVERCOMMUNICATIONSCONTROLLib.AxComms)
CommsInForm = value
End Set
End Property
Property CX_Comms As String
Get
Return CXComm
End Get
Set(value As String)
CXComm = value
End Set
End Property
Private Sub Class1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim err As Boolean = False
If (Me.Text = "") Then GoTo lblErr
If e.KeyValue = 27 Then
Me.Refresh()
Me.Text = lastData
pnl.Focus()
Exit Sub
End If
If e.KeyValue = 13 Then
If Not IsNumeric(Me.Text) Then
ErrorProvider1.SetError(Me, "Not Numeric Number")
HighLighter_Sub(True)
err = True
GoTo lblErr
End If
If Max_Value <> 0 Or Min_Value <> 0 Then
If Me.Text < Min_Value Then
ErrorProvider1.SetError(Me, "Exceeds Min Limit '" & MinValue & "'")
HighLighter_Sub(True)
err = True
GoTo lblErr
End If
If Me.Text > Max_Value Then
ErrorProvider1.SetError(Me, "Exceeds Max Limit '" & Max_Value & "'")
HighLighter_Sub(True)
err = True
GoTo lblErr
End If
End If
frm.Comms.Write("CJ1M", tagname, Me.Text * Factor)
lastData = Me.Text
pnl.Focus()
End If
lblErr:
If Not err Then
toolTip1.SetToolTip(Me, mainToolTip)
HighLighter_Sub(False)
ErrorProvider1.SetError(Me, "")
Else
Error_Bit = True
End If
End Sub