2017-01-19 1 views
0

私はユーザーコントロールに奇妙な問題があります。基本的には、C1 .... C31という31のラベルで構成されています。 私は、アプリケーションのフォームから、に、できるようにしたい: 変更Cxとの背景および/またはテキストUserControlプロパティ

(1..31さX)だから私は

Public Class CellDay 
Public Event PropertyItemChanged As EventHandler(Of ItemArgs) 

Private _name As String 'handle the name of the Label 
Private _color As Color ' handles the background of the Label 
Private _text As String ' handle the Text of the Label 

Public Sub New() 
    '_label = New Label 
    _name = "" 
    _color = Color.White 
    _text = "" 
End Sub 

Public Sub New(pname As String,pcolor As Color, ptext As String) 
    _name = pname 
    _color = pcolor 
    _text = ptext 
End Sub 

Public Property CellName As String 
    Get 
     Return _name 
    End Get 
    Set(value As String) 
     If Not _name.Equals(value) Then 
      _name = value 
      OnItemCPropertyChanged() 
     End If 

    End Set 
End Property 
Public Property CellColor As Color 
    Get 
     Return _color 
    End Get 
    Set(value As Color) 
     If _color <> value Then 
      _color = value 
      OnItemCPropertyChanged() 
     End If 

    End Set 
End Property 
Public Property CellText As String 
    Get 
     Return _text 
    End Get 
    Set(value As String) 
     If Not _name.Equals(value) Then 
      _text = value 
      OnItemCPropertyChanged() 
     End If 

    End Set 
End Property 

Private Sub OnItemCPropertyChanged() 

    RaiseEvent PropertyItemChanged(Me, New ItemArgs(_name, _color,_text)) 

End Sub 
End Class 

Public Class ItemArgs 
Inherits EventArgs 

Public Class ItemArgs 
Inherits EventArgs 
Public Sub New(ByVal pname As String, ByVal pcolor As Color, ByVal ptext As String) 
    CellName = pname 
    CellColor = pcolor 
    CellText = ptext 
End Sub 

Public Property CellName As String 
Public Property CellColor As Color 
Public Property CellText As String 
End Class` 
ラベルのための1つのクラスを追加しました

それから私はクラスウィッヒは、前のクラスの集まりです作成します。その後、ユーザーコントロールのコードで

Imports System.Collections.ObjectModel 
Public Class Days 
Inherits Collection(Of CellDay) 

'Public Sub New() 

' End Sub 
End Class 

私が持っている:

Public Class Calendrier 
Inherits System.Windows.Forms.UserControl 


Private _cellClicked As CellDay 
Private _Cells As New Days 


Public Sub New() 

    ' Cet appel est requis par le concepteur. 
    InitializeComponent() 

    Me.BackColor = Color.Transparent 

    DrawDays() ' 

End Sub 

Public ReadOnly Property Days(ByVal Index As Integer) As CellDay 
    Get 
     Return _Cells(Index - 1) 
    End Get 
End Property 


Private Sub DrawDays() 
    Dim i As Int16 
    Dim lblRef As Label 

    _Cells.Clear() 

    'now fill the collection 
    For i = 1 To 31 

     lblRef = Me.Controls("C" & (i).ToString)    

     Dim cell As New CellDay With {.CellText = i.ToString, .CellName = lblRef.Name, .CellColor = _bgcolor} 
     AddHandler cell.PropertyItemChanged, AddressOf ItemPropChanged 
     _Cells.Add(cell) 

    Next 

End Sub 

Private Sub ItemPropChanged(sender As Object, ByVal args As ItemArgs) 
    Dim Cell As CellDay 
    Dim lblName As String, Labelx As Label 

    Cell = CType(sender, CellDay) 

    lblName = Cell.CellName 
    Labelx = CType(Me.Controls(lblName), Label) 

    With Labelx 
     .BackColor = args.CellColor 
     .Text = args.CellText 
     .ForeColor = args.CellTextColor 
    End With 
End Sub 

End Class 

私は、フォーム上の(すべてのラベルのデフォルトの背景はグレーです)このコントロールを配置し、コードとボタンを追加しました:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    With Calendrier1.Days(15) 

     .CellColor = Color.AliceBlue 
     .CellText = "X" 

    End With 
End Sub 

まあ結果はテキスト「X」で第15回ラベルを与えるが、背景色は白です! デバッグに数時間を費やしましたが、なぜ色が期待通りでないのか分かりません。

コード化された方法で誰もが "バグ"を見ていますか?あなたの助けのための

どうもありがとう

オリヴィエ

答えて

0

実際にはありませんバグ... AliceBlueは白のようなものです!

関連する問題