开发者

Windows components in .net

I need a component in .net which able me to partition a year to some part which is making by clicking at the beginning of the part and click again at the end of that. the shape below is a sample of my need but I create it by buttons 开发者_JAVA技巧and back-color of them for showing for you:

alt text http://www.imagechicken.com/uploads/1274539634038682400.png

I don't know the name of this component to search for that. does anyone know this component or something like this? thank you


I'm sure the code can be cleaned up a little, but your question inspired me to actually do something in reflection. I use reflection in this code to where you name each button "Button1", "Button2", "Button3", etc. You can have 365 for all the days in the year, just make sure you change the variable intTotalButtonCount to however many buttons you have in your app. This will allow the user to click a start button and it will change its backcolor to red. When the user selects a finish button, it will change the color of all of the buttons in between the start and finish to red. A user can change the finish button (it will update the colors) or reselect the start button or one prior to it to start from scratch, which will change it back to the default control color (which it grabs from a generic save button named "btnSaveVacation"). (Notice that Button1_Click handles every single buttonX_Click event, so if you have 365 buttons, you will have to make sure that Button_1 click handles all of them.)

Dim intStart As Integer = 0
Dim intFinish As Integer = 0
Dim intButtonPushed As Integer = 0
Private Sub UpdateControls(ByVal Start As Integer, ByVal Finish As Integer, ByVal ButtonColor As Color)
    Dim myButton As Button
    For X = Start To Finish
        myButton = Me.Controls("Button" & X.ToString)
        myButton.BackColor = ButtonColor
    Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
    Dim property_value As Object
    Dim X As Integer = 0
    Dim strButtonName As String = ""
    Dim properties_info As PropertyInfo() = GetType(Button).GetProperties()
    Dim intTotalButtonCount As Integer = 3 'Total number of buttons

    For i As Integer = 0 To properties_info.Length - 1
        With properties_info(i)
            If .GetIndexParameters().Length = 0 Then
                property_value = .GetValue(sender, Nothing)
                If property_value Is Nothing Then
                Else
                    If .Name = "Text" Then
                        strButtonName += property_value.ToString
                        intButtonPushed = CInt(Mid(strButtonName, 7, (Len(strButtonName) - 6)))
                        Dim myButton As Button = Me.Controls(strButtonName)
                        If intStart < 1 Then
                            intStart = intButtonPushed
                            myButton.BackColor = Color.Red
                        Else
                            If intStart = intButtonPushed Then
                                UpdateControls(1, intTotalButtonCount, btnSaveVacation.BackColor)
                                intStart = 0
                                intFinish = 0
                            Else
                                If intFinish < 1 Then
                                    intFinish = intButtonPushed
                                    UpdateControls(intStart, intFinish, Color.Red)
                                Else
                                    If intButtonPushed <= intStart Then
                                        If intFinish > 0 Then
                                            UpdateControls(intStart, intFinish, btnSaveVacation.BackColor)
                                        End If
                                        intStart = intButtonPushed
                                        myButton = Me.Controls("Button" & intButtonPushed.ToString)
                                        myButton.BackColor = Color.Red
                                    Else
                                        intFinish = intButtonPushed
                                        UpdateControls(intStart, intFinish, Color.Red)
                                        If intFinish < intTotalButtonCount Then
                                            UpdateControls(intFinish + 1, intTotalButtonCount, btnSaveVacation.BackColor)
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End With
    Next i
End Sub


If you'd be willing to have all the rows be the same length (31 days in each row but the last day(s) greyed out for shorter months or something) I think it would be fairly easy to use a standard WinForms DataGridView. It supports both row and column headers so you could easily add month name and day number if you want.

Just store what cell the first click was in and on the next cell click you change the colour on those two controls and all controls between them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜