본문 바로가기
VB.net

RadGridView 컨트롤 색상변경 예제

by 호야호잇 2019. 12. 4.

 

'-- 패널에 선그리기를 위한 함수(공통합수)

Public Sub panelLineColor(ByVal 패널 As Panel)

        '' -- 패널 사각형 그리기

        Dim myGraphices As Graphics = 패널.CreateGraphics

        Dim myPen As Pen

        myPen = New Pen(Brushes.LightGray, 1) '-- 색상하고 굵기

        myGraphices.DrawLine(myPen, 0, 패널.Height, 0, 0) '-- 왼쪽줄

        myGraphices.DrawLine(myPen, 0, 0, 패널.Width, 0) '-- 상단줄

        myGraphices.DrawLine(myPen, 패널.Width - 1, 패널.Height, 패널.Width - 1, 0) '-- 오른쪽세로

        myGraphices.DrawLine(myPen, 0, 패널.Height - 1, 패널.Width, 패널.Height - 1) '-- 하단줄

    End Sub

 

‘—개별 다른색을 칠하고 싶을때는 Panel_Paint 이벤트에 직접 그리면 됩니다.

 

 

'--RadGridview그리드 색상변경

Private Sub RadGridView1_RowFormatting(sender As Object, e As RowFormattingEventArgs) Handles RadGridView1.RowFormatting

        If e.RowElement.IsSelected = True Then

            e.RowElement.BackColor = Color.FromArgb(253, 233, 217)

            e.RowElement.ForeColor = Color.White

            e.RowElement.Font = New Font("맑은 고딕", 9, FontStyle.Bold)

        Else

            e.RowElement.BackColor = Color.White

            e.RowElement.ForeColor = Color.Black

            e.RowElement.Font = New Font("맑은 고딕", 9, FontStyle.Regular)

 

            e.RowElement.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local)

            e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)

            e.RowElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local)

            e.RowElement.ResetValue(LightVisualElement.BorderGradientStyleProperty, ValueResetFlags.Local)

            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)

        End If

 

    End Sub

 

Private Sub RadGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles RadGridView1.CellFormatting

        If e.CellElement.RowIndex < 0 Then

            'e.CellElement.BackColor = Color.FromArgb(55, 124, 147)

            e.CellElement.BackColor = Color.FromArgb(0, 122, 204)

            e.CellElement.ForeColor = Color.White

            e.CellElement.Font = New Font("맑은 고딕", 9, FontStyle.Bold)

        Else

            e.CellElement.BackColor = Nothing

            e.CellElement.ForeColor = Color.Black

            e.CellElement.Font = New Font("맑은 고딕", 9, FontStyle.Regular)

        End If

    End Sub

 

 

''-- Radlistcontrol 색상변경

Private Sub RadListControl3_VisualItemFormatting(sender As Object, args As VisualItemFormattingEventArgs) Handles RadListControl3.VisualItemFormatting

        '-- 클릭시 색상 바꿔봅시다

        If args.VisualItem.Selected Then

            args.VisualItem.NumberOfColors = 1

            args.VisualItem.BackColor = Color.FromArgb(255, 228, 209)

            args.VisualItem.ForeColor = Color.Crimson

            args.VisualItem.BorderColor = Color.FromArgb(255, 228, 209)

            args.VisualItem.Font = New Font("맑은 고딕", 9, FontStyle.Bold)

        Else

            args.VisualItem.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.ResetValue(LightVisualElement.BorderColorProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.Font = New Font("맑은 고딕", 9, FontStyle.Regular)

        End If

 

    End Sub

 

'--- 콤보박스 RadDropDownList 색상변경

Private Sub RadDropDownList2_VisualListItemFormatting(sender As Object, args As VisualItemFormattingEventArgs) Handles RadDropDownList2.VisualListItemFormatting

        '-- 클릭시 색상 바꿔봅시다

 

        If args.VisualItem.Selected Then

            args.VisualItem.NumberOfColors = 1

            args.VisualItem.BackColor = Color.FromArgb(255, 228, 209)

            args.VisualItem.ForeColor = Color.Crimson

            args.VisualItem.BorderColor = Color.FromArgb(255, 228, 209)

            args.VisualItem.Font = New Font("맑은 고딕", 9, FontStyle.Bold)

        Else

            args.VisualItem.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.ResetValue(LightVisualElement.BorderColorProperty, Telerik.WinControls.ValueResetFlags.Local)

            args.VisualItem.Font = New Font("맑은 고딕", 9, FontStyle.Regular)

 

        End If

    End Sub