Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/VB/RibbonSimplePad/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/VB/RibbonSimplePad/ColorBox.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Reflection
Imports DevExpress.Utils
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Popup
Imports DevExpress.XtraTab
Imports DevExpress.XtraBars

Namespace DevExpress.XtraBars.Demos.RibbonSimplePad
	Public Class ColorPopup
		Private tabControl As XtraTabControl
		Private fResultColor As Color
		Private itemFontColor As BarItem
		Private container As PopupControlContainer
		Private main As frmMain
		Public Sub New(ByVal container As PopupControlContainer, ByVal item As BarItem, ByVal parent As frmMain)
			Me.main = parent
			Me.container = container
			Me.itemFontColor = item
			Me.fResultColor = Color.Empty
			Me.tabControl = CreateTabControl()
			Me.tabControl.TabStop = False
			Me.tabControl.TabPages.AddRange(New XtraTabPage() { New XtraTabPage(), New XtraTabPage(), New XtraTabPage()})
			Dim i As Integer = 0
			Do While i < tabControl.TabPages.Count
			SetTabPageProperties(i)
				i += 1
			Loop
			tabControl.Dock = DockStyle.Fill
			Me.container.Controls.AddRange(New System.Windows.Forms.Control() {tabControl})
			Me.container.Size = CalcFormSize()
		End Sub
		Private Function CreateTabControl() As XtraTabControl
			Return New XtraTabControl()
		End Function
		Private Function CreateColorListBox() As ColorListBox
			Return New ColorListBox()
		End Function
		Private Sub SetTabPageProperties(ByVal pageIndex As Integer)
			Dim tabPage As XtraTabPage = Me.tabControl.TabPages(pageIndex)
			Dim colorBox As ColorListBox = Nothing
			Dim control As BaseControl = Nothing
			Select Case pageIndex
				Case 0
					tabPage.Text = Localizer.Active.GetLocalizedString(StringId.ColorTabCustom)
					control = New ColorCellsControl(Nothing)
					Dim rItem As DevExpress.XtraEditors.Repository.RepositoryItemColorEdit = New DevExpress.XtraEditors.Repository.RepositoryItemColorEdit()
					rItem.ShowColorDialog = False
                    TryCast(control, ColorCellsControl).Properties = rItem
					AddHandler (TryCast(control, ColorCellsControl)).EnterColor, AddressOf OnEnterColor
					control.Size = ColorCellsControlViewInfo.BestSize
				Case 1
					tabPage.Text = Localizer.Active.GetLocalizedString(StringId.ColorTabWeb)
					colorBox = CreateColorListBox()
					colorBox.Items.AddRange(ColorListBoxViewInfo.WebColors)
					AddHandler colorBox.EnterColor, AddressOf OnEnterColor
					control = colorBox
				Case 2
					tabPage.Text = Localizer.Active.GetLocalizedString(StringId.ColorTabSystem)
					colorBox = CreateColorListBox()
					colorBox.Items.AddRange(ColorListBoxViewInfo.SystemColors)
					AddHandler colorBox.EnterColor, AddressOf OnEnterColor
					control = colorBox
			End Select
			control.Dock = DockStyle.Fill
			control.BorderStyle = BorderStyles.NoBorder
			control.LookAndFeel.ParentLookAndFeel = itemFontColor.Manager.GetController().LookAndFeel
			tabPage.Controls.Add(control)
		End Sub
		Private Sub OnEnterColor(ByVal sender As Object, ByVal e As EnterColorEventArgs)
			ResultColor = e.Color
			OnEnterColor(e.Color)
		End Sub
		Public Shared Sub SetImageColor(ByVal item As BarItem, ByVal clr As Color)
			Dim imIndex As Integer = item.ImageIndex
			Dim iml As ImageCollection = TryCast(item.Images, ImageCollection)
			Dim im As Bitmap = CType(iml.Images(imIndex), Bitmap)
			Dim g As Graphics = Graphics.FromImage(im)
			Dim r As Rectangle = New Rectangle(2, 12, 12, 3)
			g.FillRectangle(New SolidBrush(clr), r)
			If imIndex = iml.Images.Count - 1 Then
				iml.Images.RemoveAt(imIndex)
			End If
			g.Dispose()
			iml.Images.Add(im)
			item.ImageIndex = iml.Images.Count - 1
		End Sub
		Private Sub OnEnterColor(ByVal clr As Color)
			container.HidePopup()
			main.CurrentRichTextBox.SelectionColor = clr
		End Sub
		Private ReadOnly Property CellsControl() As ColorCellsControl
			Get
				Return (CType(tabControl.TabPages(0).Controls(0), ColorCellsControl))
			End Get
		End Property
		Private ReadOnly Property CustomColorsName() As String
			Get
				Return "CustomColors"
			End Get
		End Property
		Public Property ResultColor() As Color
			Get
				Return fResultColor
			End Get
			Set
				fResultColor = Value
				SetImageColor(itemFontColor, fResultColor)
			End Set
		End Property

		Public Function CalcFormSize() As Size
			Dim size As Size = ColorCellsControlViewInfo.BestSize
			size.Height = 113
			Return tabControl.CalcSizeByPageClient(size)
		End Function
	End Class
End Namespace