Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/VB/LayoutMainDemo/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/VB/LayoutMainDemo/Modules/BaseControl.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Namespace DevExpress.XtraLayout.Demos
    Partial Public Class BaseTutorialControl
        Inherits DevExpress.XtraLayout.Demos.TutorialControl
        Private layoutName As String = "Default.xml"
        Private fCustomization As Boolean = False

        Public Sub New()
            InitializeComponent()
            DisableLoadButton()
            Customization = False
            AddHandler cbFiles.EditValueChanged, AddressOf cbFiles_EditValueChanged
            AddHandler cbFiles.Properties.ButtonClick, AddressOf cbFiles_Properties_ButtonClick
        End Sub
        Public Overrides ReadOnly Property ExportControl() As LayoutControl
            Get
                Return BaseLayout
            End Get
        End Property
        Public Overridable ReadOnly Property BaseLayout() As LayoutControl
            Get
                Return Nothing
            End Get
        End Property
        Protected Overridable ReadOnly Property FileMask() As String
            Get
                Return "xtra"
            End Get
        End Property
        Private Sub cbFiles_Properties_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs)
            If e.Button.Index = 1 Then
                If BaseLayout Is Nothing Then
                    Return
                End If
                BaseLayout.RestoreLayoutFromXml(CurrentXMLFileName)
                layoutName = ""
            End If
        End Sub
        Private Sub cbFiles_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            DisableLoadButton()
        End Sub
        Private Sub DisableLoadButton()
            Dim btn As XtraEditors.Controls.EditorButton = cbFiles.Properties.Buttons.Item(1)
            btn.Enabled = Not String.IsNullOrEmpty(cbFiles.Text) And Not cbFiles.Text.Equals(layoutName)
        End Sub

        Protected Sub InitPanels()
            panelControl1.Visible = Not BaseLayout Is Nothing
            If Not BaseLayout Is Nothing Then
                Dim XmlFileNames As ArrayList = FindingXmlFiles(Application.StartupPath, "Data\FormLayouts\", FileMask)
                If XmlFileNames.Count = 0 Then
                    panelControl1.Visible = False
                End If
                cbFiles.Properties.Items.Clear()
                For Each obj As Object In XmlFileNames
                    cbFiles.Properties.Items.Add(obj)
                Next obj
                AddHandler BaseLayout.ShowCustomization, AddressOf ShowCustomization
                AddHandler BaseLayout.HideCustomization, AddressOf HideCustomization
            End If
        End Sub


        Public Property Customization() As Boolean
            Get
                Return fCustomization
            End Get
            Set(ByVal value As Boolean)
                fCustomization = value
                If (fCustomization) Then
                    sbCustomize.Text = "Hide Customization Form"
                Else
                    sbCustomize.Text = "Show Customization Form"
                End If
            End Set
        End Property
        Private Sub ShowCustomization(ByVal sender As Object, ByVal e As EventArgs)
            Customization = True
        End Sub
        Private Sub HideCustomization(ByVal sender As Object, ByVal e As EventArgs)
            Customization = False
        End Sub

        Private Sub BaseTutorialControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub

        Private ReadOnly Property CurrentXMLFileName() As String
            Get
                Dim file As XMLFileName = TryCast(cbFiles.SelectedItem, XMLFileName)
                If file Is Nothing Then
                    Return ""
                End If
                Return file.FullName
            End Get
        End Property
        Private Sub sbSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sbSave.Click
            If BaseLayout Is Nothing Then
                Return
            End If
            BaseLayout.SaveLayoutToXml("Temp.xml")
        End Sub
#Region "Finding Xml Files"
        Public Shared Function FindingXmlFiles(ByVal path As String, ByVal path1 As String, ByVal mask As String) As ArrayList
            Dim s As String = "\"
            Dim xmlFiles As ArrayList = New ArrayList()
            For i As Integer = 0 To 10
                If System.IO.Directory.Exists(path & s & path1) Then
                    Dim names As String() = System.IO.Directory.GetFiles(path & s & path1, mask & "*.xml")
                    For Each name As String In names
                        Dim fInfo As System.IO.FileInfo = New System.IO.FileInfo(name)
                        Dim fName As String = fInfo.Name
                        fName = fName.Replace(mask, "")
                        xmlFiles.Add(New XMLFileName(fName, fInfo.FullName))
                    Next name
                    Return xmlFiles
                Else
                    s &= "..\"
                End If
            Next i
            Return xmlFiles
        End Function

        Private Class XMLFileName
            Private fName, fFullName As String
            Public Sub New(ByVal name As String, ByVal fullName As String)
                Me.fName = name
                Me.fFullName = fullName
            End Sub
            Public ReadOnly Property Name() As String
                Get
                    Return fName
                End Get
            End Property
            Public ReadOnly Property FullName() As String
                Get
                    Return fFullName
                End Get
            End Property
            Public Overrides Function ToString() As String
                Return Name
            End Function
        End Class
#End Region

        Protected Overrides Sub DoHide()
            If Not BaseLayout Is Nothing Then
                BaseLayout.HideCustomizationForm()
            End If
            lcTitle.HideCustomizationForm()
        End Sub

        Private Sub sbCustomize_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sbCustomize.Click
            If BaseLayout Is Nothing Then
                Return
            End If
            If Customization Then
                BaseLayout.HideCustomizationForm()
            Else
                BaseLayout.ShowCustomizationForm()
            End If
        End Sub

        Private Sub checkEdit1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkEdit1.CheckedChanged
            If BaseLayout Is Nothing Then
                Return
            End If
            BaseLayout.OptionsView.AllowHotTrack = checkEdit1.Checked
        End Sub

        Private Sub checkEdit3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkEdit3.CheckedChanged
            If BaseLayout Is Nothing Then
                Return
            End If
            BaseLayout.OptionsView.AllowItemSkinning = checkEdit3.Checked
            checkEdit2.Enabled = checkEdit3.Checked
            checkEdit1.Enabled = checkEdit2.Enabled
        End Sub

        Private Sub checkEdit2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkEdit2.CheckedChanged
            If BaseLayout Is Nothing Then
                Return
            End If
            BaseLayout.OptionsView.HighlightFocusedItem = checkEdit2.Checked
        End Sub

        Private Sub checkEdit4_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkEdit4.CheckedChanged
            BaseLayout.OptionsView.DrawItemBorders = checkEdit4.Checked
        End Sub

    End Class
End Namespace