Google
 
Web itpro-blogger.blogspot.com
日曜日, 3月 30, 2008

[VB2005]ReadOnlyコンボボックス

Public Class useComboBox
Inherits System.Windows.Forms.ComboBox
Private blnReadOnly As Boolean = False
Private iSelectedIndex As Integer = Me.SelectedIndex
'-------------------------------------------------------------------------------
'
' コンストラクタ処理
'
Public Sub New()

End Sub

'-------------------------------------------------------------------------------
'
' デストラクタ処理
'
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

'-------------------------------------------------------------------------------
'
' 概要 : 読み取り専用かどうかを示す値を取得または設定します。
'
' 戻り値 : 読み取り専用の場合は true。それ以外の場合は false。既定値は false です。
'
Public Property ControlReadOnly() As Boolean
Get
Return blnReadOnly
End Get
Set(ByVal value As Boolean)
Me.Enabled = True
If (value) Then
Me.BackColor = SystemColors.Control
iSelectedIndex = Me.SelectedIndex
Else
Me.BackColor = SystemColors.Window
End If
blnReadOnly = value
End Set
End Property

Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
If (blnReadOnly) Then Me.Parent.Focus() : Return
MyBase.OnMouseUp(e)
End Sub

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
If (blnReadOnly) Then Me.Parent.Focus() : Return
MyBase.OnMouseDown(e)
End Sub

Protected Overrides Sub OnMouseClick(ByVal e As System.Windows.Forms.MouseEventArgs)
If (blnReadOnly) Then Me.Parent.Focus() : Return
MyBase.OnMouseClick(e)
End Sub

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
If (blnReadOnly) Then Me.Parent.Focus() : Return
MyBase.OnGotFocus(e)
End Sub

End Class






Comments: コメントを投稿

<< Home

This page is powered by Blogger. Isn't yours?