Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraBars.Docking
Imports DevExpress.XtraBars.Docking2010.Views
Imports DevExpress.XtraBars.Helpers
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraSplashScreen
Imports System.Reflection
Imports System.IO
Imports System.Collections.Generic
Imports System.Drawing
Namespace DevExpress.XtraBars.Demos.DockingDemo
Partial Public Class frmMain
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
CreateResourceStream()
SplashScreenManager.ShowImage(SplashScreenImage, True, False)
InitializeComponent()
WindowState = FormWindowState.Maximized
SolutionExplorer.InitTreeView(treeView1)
xtraPropertyGrid1.PropertyGrid.AutoGenerateRows = True
End Sub
Private splashScreenImageCore As Bitmap
Private ReadOnly Property SplashScreenImage() As Bitmap
Get
Return splashScreenImageCore
End Get
End Property
Private currentAssemblyCore As Assembly
Private ReadOnly Property CurrentAssembly() As Assembly
Get
If currentAssemblyCore Is Nothing Then
currentAssemblyCore = Assembly.GetExecutingAssembly()
End If
Return currentAssemblyCore
End Get
End Property
Private Sub CreateResourceStream()
splashScreenImageCore = New Bitmap(CurrentAssembly.GetManifestResourceStream("splashScreen.png"))
fileStreams.Add(CurrentAssembly.GetManifestResourceStream("ProgramText.rtf"))
fileStreams.Add(CurrentAssembly.GetManifestResourceStream("ProgramText2.rtf"))
fileStreams.Add(CurrentAssembly.GetManifestResourceStream("ProgramText3.rtf"))
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
SkinHelper.InitSkinPopupMenu(iPaintStyle)
BeginInvoke(New MethodInvoker(AddressOf InitDemo))
End Sub
Private fileStreams As New List(Of Stream)()
Private i As Integer = 0
Private projectIndex As Integer = 0
Private currentCursor As Cursor
Private Sub InitDemo()
AddControls(Me, comboBox1)
comboBox1.SelectedIndex = 0
comboBox2.SelectedIndex = 0
textBox2.ContextMenu = New ContextMenu()
textBox1.ContextMenu = textBox2.ContextMenu
AddNewForm("File.cs")
DevExpress.Demos.ClassViewer.AddClassInfo(treeView1, Me.GetType(), New Object() {Me, New SolutionExplorer()})
SplashScreenManager.HideImage()
End Sub
Private Sub AddNewForm(ByVal s As String)
Dim control As New RichEditControl()
control.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft
control.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder
control.LayoutUnit = DevExpress.XtraRichEdit.DocumentLayoutUnit.Pixel
control.Name = s
control.Text = s
control.Options.HorizontalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden
control.Options.VerticalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden
AddHandler control.SelectionChanged, AddressOf tb_SelectionChanged
tabbedView1.BeginUpdate()
Dim document As BaseDocument = tabbedView1.Controller.AddDocument(control)
document.Image = ImageList4.Images(10)
document.Form.Text = s
document.Form.Icon = CreateIcon(10)
document.Footer = Directory.GetCurrentDirectory()
control.LoadDocument(fileStreams(i), DocumentFormat.Rtf)
control.Document.Sections(0).Page.Width = 10000
tabbedView1.EndUpdate()
fileStreams(i).Seek(0, 0)
i += 1
If i = 3 Then
i = 0
End If
End Sub
Private Function CreateIcon(ByVal index As Integer) As System.Drawing.Icon
Return CreateIcon(ImageList4.Images(index))
End Function
Private Function CreateIcon(ByVal image As Image) As System.Drawing.Icon
If image Is Nothing Then
Return Nothing
End If
Using newIcon As New System.Drawing.Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newIcon)
g.DrawImageUnscaled(image, 0, 0, 16, 16)
Return System.Drawing.Icon.FromHandle(newIcon.GetHicon())
End Using
End Using
End Function
Private ReadOnly Property ActiveRTB() As RichEditControl
Get
If Me.ActiveMdiChild IsNot Nothing AndAlso Me.ActiveMdiChild.ContainsFocus Then
If Me.ActiveMdiChild.Controls.Count = 0 Then
Return Nothing
End If
Return TryCast(Me.ActiveMdiChild.Controls(0), RichEditControl)
End If
Return Nothing
End Get
End Property
Private Sub InitEdit()
Dim editControl As RichEditControl = ActiveRTB
If editControl IsNot Nothing Then
iCopy.Enabled = editControl.Document.Selection IsNot Nothing
iCut.Enabled = iCopy.Enabled
iPaste.Enabled = If(String.IsNullOrEmpty(Clipboard.GetText(TextDataFormat.Text)), False, True)
iUndo.Enabled = editControl.CanUndo
iRedo.Enabled = editControl.CanRedo
Else
iRedo.Enabled = False
iUndo.Enabled = iRedo.Enabled
iPaste.Enabled = iUndo.Enabled
iCopy.Enabled = iPaste.Enabled
iCut.Enabled = iCopy.Enabled
End If
End Sub
Private Sub tb_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
InitEdit()
End Sub
Private Sub AddControls(ByVal container As Control, ByVal cb As DevExpress.XtraEditors.ComboBoxEdit)
For Each obj As Object In container.Controls
cb.Properties.Items.Add(obj)
If TypeOf obj Is Control Then
AddControls(TryCast(obj, Control), cb)
End If
Next obj
End Sub
Private Sub repositoryItemComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles repositoryItemComboBox1.KeyDown
If e.KeyCode = Keys.Enter AndAlso eFind.EditValue IsNot Nothing Then
repositoryItemComboBox1.Items.Add(eFind.EditValue.ToString())
End If
End Sub
Private Sub comboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboBox2.SelectedIndexChanged
If comboBox2.SelectedIndex = 0 Then
textBox2.Text = " ------ Build started: Project: DockingDemo, Configuration: Debug .NET ------" & Constants.vbCrLf & Constants.vbCrLf & " Preparing resources..." & Constants.vbCrLf & " Updating references..." & Constants.vbCrLf & " Performing main compilation..." & Constants.vbCrLf & Constants.vbCrLf & " Build complete -- 0 errors, 0 warnings" & Constants.vbCrLf & " Building satellite assemblies..." & Constants.vbCrLf & Constants.vbCrLf & Constants.vbCrLf & " ---------------------- Done ----------------------" & Constants.vbCrLf & Constants.vbCrLf & " Build: 1 succeeded, 0 failed, 0 skipped"
Else
textBox2.Text = " 'DefaultDomain': Loaded 'd:\winnt\microsoft.net\framework\v1.0.3705\mscorlib.dll', No symbols loaded." & Constants.vbCrLf & " 'DockingDemo': Loaded 'C:\BarDemos\CS\DockingDemo\bin\Debug\DockingDemo.exe', Symbols loaded."
End If
End Sub
Private Sub textBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textBox2.KeyDown
e.Handled = True
End Sub
Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboBox1.SelectedIndexChanged
xtraPropertyGrid1.PropertyGrid.SelectedObject = comboBox1.SelectedItem
End Sub
Private Sub ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iProject.ItemClick, iFile.ItemClick, iBlankSolution.ItemClick, iNewProject.ItemClick, iNew.ItemClick
projectIndex += 1
AddNewForm(String.Format("File{0}.cs", projectIndex))
End Sub
Private Sub iAbout_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iAbout.ItemClick
DevExpress.Utils.About.AboutForm.Show(New DevExpress.Utils.About.ProductInfo(String.Empty, GetType(frmMain), DevExpress.Utils.About.ProductKind.DXperienceWin, DevExpress.Utils.About.ProductInfoStage.Registered))
End Sub
Private Sub frmMain_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
InitEdit()
End Sub
Private Sub iCut_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iCut.ItemClick
Dim rtb As RichEditControl = ActiveRTB
If rtb IsNot Nothing Then
rtb.Cut()
End If
End Sub
Private Sub iCopy_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iCopy.ItemClick
Dim rtb As RichEditControl = ActiveRTB
If rtb IsNot Nothing Then
rtb.Copy()
End If
End Sub
Private Sub iPaste_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iPaste.ItemClick
Dim rtb As RichEditControl = ActiveRTB
If rtb IsNot Nothing Then
rtb.Paste()
End If
End Sub
Private Sub iSelectAll_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iSelectAll.ItemClick
Dim rtb As RichEditControl = ActiveRTB
If rtb IsNot Nothing Then
rtb.SelectAll()
rtb.Focus()
End If
End Sub
Private Sub iUndo_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iUndo.ItemClick
Dim rtb As RichEditControl = ActiveRTB
If rtb IsNot Nothing Then
rtb.Undo()
End If
InitEdit()
End Sub
Private Sub iRedo_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iRedo.ItemClick
Dim rtb As RichEditControl = ActiveRTB
If rtb IsNot Nothing Then
rtb.Redo()
End If
InitEdit()
End Sub
'AB15908
Protected Function GetTopDockPanelCore(ByVal panel As DockPanel) As DockPanel
If panel.ParentPanel IsNot Nothing Then
Return GetTopDockPanel(panel.ParentPanel)
Else
Return panel
End If
End Function
Protected Function GetTopDockPanel(ByVal panel As DockPanel) As DockPanel
Dim floatPanelCandidate As DockPanel = GetTopDockPanelCore(panel)
If floatPanelCandidate.Dock = DockingStyle.Float Then
Return floatPanelCandidate
Else
Return panel
End If
End Function
'AB15908
Private Sub iSolutionExplorer_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iSolutionExplorer.ItemClick
dockPanel1.Show()
End Sub
Private Sub iProperties_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iProperties.ItemClick
dockPanel2.Show()
End Sub
Private Sub iTaskList_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iTaskList.ItemClick
dockPanel3.Show()
End Sub
Private Sub iFindResults_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iFindResults.ItemClick
dockPanel4.Show()
End Sub
Private Sub iOutput_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iOutput.ItemClick
dockPanel5.Show()
End Sub
Private Sub iToolbox_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iToolbox.ItemClick
dockPanel6.Show()
End Sub
Private Sub solutionExplorer1_PropertiesItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles solutionExplorer1.PropertiesItemClick
dockPanel2.Show()
End Sub
Private Sub treeViewItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles solutionExplorer1.TreeViewItemClick
Dim treeView As DevExpress.XtraTreeList.TreeList = TryCast(sender, DevExpress.XtraTreeList.TreeList)
Dim fileName As String = treeView.FocusedNode.GetDisplayText(0)
fileName = fileName.Replace(".cs", String.Empty)
Dim stream As Stream = CurrentAssembly.GetManifestResourceStream(String.Format("{0}.rtf", fileName))
For Each document As BaseDocument In tabbedView1.Documents
If document.Caption = (fileName & ".cs") Then
tabbedView1.Controller.Activate(document)
Return
End If
Next document
If stream IsNot Nothing Then
Dim control As New RichEditControl()
control.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft
control.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder
control.LayoutUnit = DevExpress.XtraRichEdit.DocumentLayoutUnit.Pixel
control.Text = fileName & ".cs"
control.Options.HorizontalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden
control.Options.VerticalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden
AddHandler control.SelectionChanged, AddressOf tb_SelectionChanged
tabbedView1.BeginUpdate()
Dim document As BaseDocument = tabbedView1.Controller.AddDocument(control)
document.Form.Text = fileName + ".cs"
document.Form.Icon = CreateIcon(treeView.FocusedNode.StateImageIndex)
document.Footer = Directory.GetCurrentDirectory()
document.Image = ImageList4.Images(treeView.FocusedNode.StateImageIndex())
control.LoadDocument(stream, DocumentFormat.Rtf)
control.Document.Sections(0).Page.Width = 10000
tabbedView1.EndUpdate()
End If
End Sub
Private Sub iSaveLayout_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iSaveLayout.ItemClick
Dim dlg As New SaveFileDialog()
dlg.Filter = "XML files (*.xml)|*.xml"
dlg.Title = "Save Layout"
If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Refresh(True)
barManager1.SaveToXml(dlg.FileName)
Refresh(False)
End If
End Sub
Private Sub iLoadLayout_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iLoadLayout.ItemClick
Dim dlg As New OpenFileDialog()
dlg.Filter = "XML files (*.xml)|*.xml|All files|*.*"
dlg.Title = "Restore Layout"
If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Refresh(True)
Try
barManager1.RestoreFromXml(dlg.FileName)
SkinHelper.InitSkinPopupMenu(iPaintStyle)
Catch
End Try
Refresh(False)
End If
End Sub
Private Overloads Sub Refresh(ByVal isWait As Boolean)
If isWait Then
currentCursor = Cursor.Current
Cursor.Current = Cursors.WaitCursor
Else
Cursor.Current = currentCursor
End If
Me.Refresh()
End Sub
Private Sub iExit_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iExit.ItemClick
Me.Close()
End Sub
Private Sub tabbedView1_DocumentAdded(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs) Handles tabbedView1.DocumentAdded
e.Document.Form.Text = e.Document.Caption
e.Document.Form.Icon = CreateIcon(e.Document.Image)
End Sub
Private Sub tabbedView1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabbedView1.LostFocus
InitEdit()
End Sub
End Class
End Namespace