为了开发省力一点-写了通用的textbox类
来源:互联网 发布:excel抓取数据 编辑:程序博客网 时间:2024/05/03 03:48
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows
Imports System.Windows.Forms
Imports BaseItem.BaseDataOperations
Public Class CommTextBox
Inherits System.Windows.Forms.TextBox
#Region " 组件设计器生成的代码 "
Public Sub New()
MyBase.New()
' 该调用是组件设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'Control 重写 dispose 以清理组件列表。
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
'控件设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是组件设计器所必需的
' 可以使用组件设计器修改此过程。不要使用
' 代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
#End Region
#Region "Properties"
Dim _ConnString As String
Public Property ConnString() As String
Get
Return _ConnString
End Get
Set(ByVal Value As String)
_ConnString = Value
End Set
End Property
Dim _strKey As String = ""
Public Property strKey() As String
Get
Return _strKey
End Get
Set(ByVal Value As String)
_strKey = Value
End Set
End Property
Dim _objRefFrm As Windows.Forms.Form
Public Property objRefFrm() As Windows.Forms.Form '设置参考窗体
Get
Return _objRefFrm
End Get
Set(ByVal Value As Windows.Forms.Form)
_objRefFrm = Value
End Set
End Property
Dim _strTableName As String = ""
Public Property strTableName() As String
Get
Return _strTableName
End Get
Set(ByVal Value As String)
_strTableName = Value
End Set
End Property
Dim _strColumnName As String = ""
Public Property strColumnName() As String
Get
Return _strColumnName
End Get
Set(ByVal Value As String)
_strColumnName = Value
End Set
End Property
Dim _strTargetColumn As String = ""
Public Property strTargetColumn() As String
Get
Return _strTargetColumn
End Get
Set(ByVal Value As String)
_strTargetColumn = Value
End Set
End Property
Dim _blValidate As Boolean = False
Public Property blValidate() As Boolean
Get
Return _blValidate
End Get
Set(ByVal Value As Boolean)
_blValidate = Value
End Set
End Property
Dim _IsValidated As Boolean = False
Public ReadOnly Property IsValidated() As Boolean
Get
Return _IsValidated
End Get
End Property
#End Region
Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
'在此添加自定义绘画代码
End Sub
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
MyBase.OnKeyDown(e)
If e.KeyCode = Keys.F3 Then
If Not IsNothing(_objRefFrm) Then
Dim frm As New Form
frm = _objRefFrm
frm.Text = MyBase.Text
If frm.ShowDialog = DialogResult.OK Then
_strKey = frm.Text
If _strTargetColumn <> _strColumnName Then
MyBase.Text = BaseDataOperation.getValue(_strTableName, _strColumnName, _strKey, _strTargetColumn, _ConnString)
Else
MyBase.Text = _strKey
End If
_IsValidated = True
End If
End If
End If
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then
If MyBase.Text <> _strKey Then
If MyBase.Text = "" Then
_strKey = ""
Else
If IsNothing(_objRefFrm) Then
Exit Sub
End If
If _strTableName = "" Then
Exit Sub
End If
Dim tString As String = MdComm.GetUniqueValue(_strTableName, MyBase.Text, _strColumnName, _strTargetColumn, True)
If tString = "" Then
Dim frm As New Form
frm = _objRefFrm
frm.Text = MyBase.Text
If frm.ShowDialog = DialogResult.OK Then
_strKey = frm.Text
If _strTargetColumn <> _strColumnName Then
MyBase.Text = BaseDataOperation.getValue(_strTableName, _strColumnName, _strKey, _strTargetColumn, _ConnString)
Else
MyBase.Text = _strKey
End If
_IsValidated = True
End If
Else
_strKey = tString
If _strTargetColumn <> _strColumnName Then
MyBase.Text = BaseDataOperation.getValue(_strTableName, _strColumnName, _strKey, _strTargetColumn, _ConnString)
Else
MyBase.Text = _strKey
End If
_IsValidated = True
End If
End If
End If
End If
End Sub
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
If _blValidate Then
If Not _IsValidated Then
MessageBox.Show("未能确定唯一项", "提示", MessageBoxButtons.OK)
e.Cancel = True
End If
End If
'If _strKey <> MyBase.Text Then
'If _blValidate Then
'MessageBox.Show("未能确定唯一项", "提示", MessageBoxButtons.OK)
'e.Cancel = True
'Else
' _strKey = ""
' 'MyBase.Text = ""
'End If
'End If
End Sub
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
If _IsValidated Then
_IsValidated = False
End If
End Sub
End Class
- 为了开发省力一点-写了通用的textbox类
- 为了开发省力一点
- 为了开发省力一点-基本数据操作
- 为了开发省力一点-数字输入框
- 为了开发省力一点_做个分级树
- 为了开发省力一点_定义表格控件
- 工程师写Code的聪明省力法
- textBox控件的一点
- textBox控件的一点
- textBox控件的一点
- 写了一个分页通用的
- 该是写一点东西的时候了
- 转帖-----我的WinCE5.0入门全过程,为了方便后来者,写了一天多,仅供大家参考!(开发环境建立+流驱动开发+相关资料)
- 转帖-----我的WinCE5.0入门全过程,为了方便后来者,写了一天多,仅供大家参考!(开发环境建立+流驱动开发+相关资料)
- 开发了一个纯粹为了比赛的机器人功能
- 为了学习android,开始写博客了
- 新近写了个通用的数据库访问类(c#)
- 针对select写了一个通用的option输出函数
- 任务栏里的显示桌面丢失了怎么办?
- ruby学习笔记(11)--基本的输入输出
- 转:常用ASCII码对照表
- 关于sqldatareader和sqlconnection
- ECO视频教程下载
- 为了开发省力一点-写了通用的textbox类
- 在Sql Server 2000中区分大小写
- 用Javascript作消息提示框(类似于QQ用户上线的消息提示)
- 读取 MP3 文件属性
- 什么是CAN总线?
- 用GDB调试程序【一】
- 用GDB调试程序【二】
- Zachman框架
- windowsvista首页的一个css瑕疵