Click here to Skip to main content
15,891,704 members
Articles / Programming Languages / Visual Basic

Open Door - Reporting, Charts, Enquiry Drill-Downs

Rate me:
Please Sign up or sign in to vote.
4.37/5 (11 votes)
2 Feb 2009CPOL6 min read 39.3K   2K   59  
A utility for generating user editable reports, charts, documents, enquiries
imports nbfSqlReporter
imports System.Windows.Forms
Imports System.IO
imports System.Drawing
imports system.Drawing.Printing
Public Class nbfEditReport 
    Inherits System.Windows.Forms.Form
    Public Rep As nbfBrowseCtrl
    Private SelectedControls As New Collection
    Friend pvDBC As nbfDB.HDBC
    Private BtnCount As Integer = 0
    Private _backBuffer As Bitmap
    Private x_offset As Integer = 0
    Private y_offset As Integer = 0
    Private y_overspill As Integer = 0
    Private x_overspill As Integer = 0
    Private inresize As Boolean = False
    Private SuspendDisplay As Boolean = False
    Public pvBrowseRep As nbfBrowseRep
    Private pvSI As nbfStyleInfo.AppStyle
    Private pvAppFrmSI As nbfStyleInfo.AppStyle
    Private InFormLoad As Boolean = False
    Public TopBorder As Integer = 6
    Public LeftBorder As Integer = 16
    Public RightBorder As Integer = 6
    Public BottomBorder As Integer = 6
    'Splitters
    Private spw As Integer = 2
    Private InSplitMove As Boolean
    Private SplitCeiling As Integer
    Private SplitMoving As Integer
    'LineEdit
    Private LineEditType As String = ""
    Private KeepVertical As Boolean = False
    'Edit Control Changes
    Private InCtrlEdit As Boolean = False
    Private InLineEdit As Boolean = False
    Private InBoxEdit As Boolean = False
    Private NewEditCtrl As nbfBrowseCtrl 'Control
    private CtrlChanges as boolean = false
    private EditCtrlHeight as integer = 0
    private EditCtrlWidth as integer = 0
    private EditCtrlLabHeight as integer = 0
    private EditCtrlLabWidth as integer = 0
    private EditXOffset as Integer = 0
    private CtrlEditType as string = ""
    private RevRectBackColor as color = color.BlueViolet
    private PrvRect as rectangle
    private PrvLabRect as rectangle
    private PrvPoint as Point
    private PrvStart as Point
    private PrvPlacePoint as Point
    Private lgSet as boolean
    'private lg as Graphics
    private LineDrawPen as Pen
    private LineErasePen as Pen
    private HighlightPen as Pen
    private PlacePen as Pen
    private ErasePlacePen as Pen
    private pvDefaultLineWidth as Integer = 1
    private pvDefaultButtonHeight = 20
    private pvDefaultButtonWidth = 80
    private LastSetTBWidth as integer
    private LastSetDTBWidth as integer
    private InitTabIndex as integer
    private pvNewPropDesc as String = ""
    private pvNewPropName as string = ""
    private pvAutoAddLabels as boolean = true
    private pvShowSubReps as boolean = false
    private pvBoxCtrlBlock as Boolean = false
    private pvCtrlBlock as nbfSqlColInfos
    private pvCtrlBlockHz as Boolean = false
    private pvCtrlBlockSqlSce as string = ""
    Private vl As Label
    Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
    Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar
    Friend WithEvents ts1 As System.Windows.Forms.ToolStripContainer
    Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
    Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SaveToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents CloseToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents EditToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ViewToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SuToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddDataSourceToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents RemoveDataSOurceToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents EditDataSourceToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents BrowseItemsToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddItemToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddTotalToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddAmalganatedTotalToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddSubItemToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents LayoutToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddLabelToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddLineToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddBoxToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddPictureToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents CaptionToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AlignmentToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents VerticalSpacingToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents HorizontalSpacingToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SectionsToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ShowDataToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ShowFieldInfoToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents VertHorizLineToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AngledLineToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AlignTopToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AlignBottomToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AlignLeftToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AlignRightToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SpaceAsFirstToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SpaceEvenlyToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents IncreaseSpacingToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents DecreaseSpacingToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SpaceAsFirstToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SpaceEvenlyToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents IncreaseSpacingToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents DecreaseSpacingToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents AddToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents RemoveToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents EditToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents LineMenuResize As System.Windows.Forms.MenuItem
    Friend WithEvents RepMenuEditList As System.Windows.Forms.MenuItem
    Friend WithEvents AddChartToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Private hl As Label

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        AddHandler AddItemToolStripMenuItem.Click, AddressOf AddBrowseCtrl
        AddHandler AddTotalToolStripMenuItem.Click, AddressOf AddBrowseTotal
        AddHandler AddAmalganatedTotalToolStripMenuItem.Click, AddressOf AddBrowseAmalgum
        AddHandler RemoveDataSOurceToolStripMenuItem.Click, AddressOf DelSqlSource
        AddHandler EditDataSourceToolStripMenuItem.Click, AddressOf EditSqlSource
        AddHandler AddSubItemToolStripMenuItem.Click, AddressOf AddBrowseSubCtrl
        AddHandler AddDataSourceToolStripMenuItem.Click, AddressOf AddSqlSource

        AddHandler AddLabelToolStripMenuItem.Click, AddressOf AddLabel
        AddHandler AngledLineToolStripMenuItem.Click, AddressOf AddLine
        AddHandler VertHorizLineToolStripMenuItem.Click, AddressOf AddVLine
        AddHandler AddBoxToolStripMenuItem.Click, AddressOf AddBox
        AddHandler AddPictureToolStripMenuItem.Click, AddressOf AddPicture
        AddHandler AddChartToolStripMenuItem.Click, AddressOf AddChart
        AddHandler CaptionToolStripMenuItem.Click, AddressOf ChangeCaption

        AddHandler AlignTopToolStripMenuItem.Click, AddressOf AlignTops
        AddHandler AlignBottomToolStripMenuItem.Click, AddressOf AlignBottoms
        AddHandler AlignLeftToolStripMenuItem.Click, AddressOf AlignLefts
        AddHandler AlignRightToolStripMenuItem.Click, AddressOf AlignRights

        AddHandler CtxtAlignTop.Click, AddressOf AlignTops
        AddHandler CtxtAlignBottom.Click, AddressOf AlignBottoms
        AddHandler CtxtAlignLeft.Click, AddressOf AlignLefts
        AddHandler CtxtAlignRight.Click, AddressOf AlignRights
        AddHandler ctxtAlignCentre.Click, AddressOf AlignCentres

        AddHandler SpaceAsFirstToolStripMenuItem.Click, AddressOf SpaceFirstV
        AddHandler SpaceEvenlyToolStripMenuItem.Click, AddressOf SpaceEvenV
        AddHandler IncreaseSpacingToolStripMenuItem.Click, AddressOf SpaceIncV
        AddHandler DecreaseSpacingToolStripMenuItem.Click, AddressOf SpaceDecV
        AddHandler SpaceAsFirstToolStripMenuItem1.Click, AddressOf SpaceFirstH
        AddHandler SpaceEvenlyToolStripMenuItem1.Click, AddressOf SpaceEvenH
        AddHandler IncreaseSpacingToolStripMenuItem1.Click, AddressOf SpaceIncH
        AddHandler DecreaseSpacingToolStripMenuItem1.Click, AddressOf SpaceDecH

        AddHandler CtxtVSpaceFirst.Click, AddressOf SpaceFirstV
        AddHandler CtxtVSpaceEven.Click, AddressOf SpaceEvenV
        AddHandler CtxtVSpaceInc.Click, AddressOf SpaceIncV
        AddHandler CtxtVSpaceDec.Click, AddressOf SpaceDecV

        AddHandler CtxtHSpaceFirst.Click, AddressOf SpaceFirstH
        AddHandler CtxtHSpaceEven.Click, AddressOf SpaceEvenH
        AddHandler CtxtHSpaceInc.Click, AddressOf SpaceIncH
        AddHandler CtxtHSpaceDec.Click, AddressOf SpaceDecH

        AddHandler CtxtMenuMove.Click, AddressOf MoveCtrl
        AddHandler CtxtMenuResize.Click, AddressOf ResizeCtrl
        AddHandler CtxtMenuDelete.Click, AddressOf DeleteCtrl
        AddHandler CtxtMenuEdit.Click, AddressOf ReqEditCtrl
        AddHandler MenuClearSelect.Click, AddressOf ClearSelect
        AddHandler MenuLClearSelect.Click, AddressOf ClearSelect
        AddHandler CtrlContextMenu.Popup, AddressOf CMPopup

        AddHandler RepMenuEdit.Click, AddressOf ReqEditRepChtCtrl
        AddHandler RepMenuDelete.Click, AddressOf DeleteCtrl
        AddHandler RepMenuResize.Click, AddressOf ResizeCtrl
        AddHandler RepMenuMove.Click, AddressOf MoveCtrl
        AddHandler RepMenuPropEdit.Click, AddressOf ReqEditProp
        AddHandler RepMenuEditList.Click, AddressOf ReqEditListProp

        AddHandler LineMenuDelLine.Click, AddressOf DeleteCtrl
        AddHandler LineMenuDelBox.Click, AddressOf DeleteCtrl
        AddHandler LineMenuResize.Click, AddressOf ResizeLine

        AddHandler SaveToolStripMenuItem.Click, AddressOf FileSave

        'AddHandler FileMenuOpen.Click, AddressOf FileOpen
        AddHandler CloseToolStripMenuItem.Click, AddressOf FileCloseClicked

        AddHandler ShowDataToolStripMenuItem.Click, AddressOf Display
        AddHandler ShowFieldInfoToolStripMenuItem.Click, AddressOf DisplayData


        AddHandler AddToolStripMenuItem.Click, AddressOf AddSection
        AddHandler RemoveToolStripMenuItem.Click, AddressOf DelSection
        AddHandler EditToolStripMenuItem1.Click, AddressOf EditSections

        PrvPlacePoint.X = -1
        PrvPoint.X = -1
        PrvRect.Height = -1
        vl = New Label
        vl.Visible = False
        vl.BackColor = System.Drawing.Color.Red
        vl.Width = 1
        vl.Top = 0
        vl.Height = Me.Height
        ts1.ContentPanel.Controls.Add(vl)
        hl = New Label
        hl.Visible = False
        hl.BackColor = System.Drawing.Color.Red
        hl.Height = 1
        hl.Left = 0
        hl.Width = Me.Width
        ts1.ContentPanel.Controls.Add(hl)
        AddHandler ts1.ContentPanel.Paint, AddressOf PaintForm
        AddHandler DropCtrl.MouseMove, AddressOf SubCtrlMM
        AddHandler DropCtrl.MouseDown, AddressOf SubCtrlMD
        AddHandler vl.MouseMove, AddressOf SubCtrlMM
        AddHandler vl.MouseDown, AddressOf SubCtrlMD
        AddHandler hl.MouseMove, AddressOf SubCtrlMM
        AddHandler hl.MouseDown, AddressOf SubCtrlMD
        AddHandler VScrollBar1.Scroll, AddressOf VScrolled
        AddHandler HScrollBar1.Scroll, AddressOf HScrolled
        AddHandler ts1.ContentPanel.MouseMove, AddressOf SubCtrlMM
        'AddHandler ts1.ContentPanel.MouseDown, AddressOf SubCtrlMD
        AddHandler ts1.ContentPanel.MouseDown, AddressOf MainPanelMouseDown
    End Sub
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents DropCtrl As System.Windows.Forms.Label
    Friend WithEvents CtrlContextMenu As System.Windows.Forms.ContextMenu
    Friend WithEvents CtxtMenuMove As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtMenuResize As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtMenuDelete As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtMenuEdit As System.Windows.Forms.MenuItem
    Friend WithEvents LineContextMenu As System.Windows.Forms.ContextMenu
    Friend WithEvents LineMenuDelLine As System.Windows.Forms.MenuItem
    Friend WithEvents LineMenuDelBox As System.Windows.Forms.MenuItem
    Friend WithEvents ReportMenu As System.Windows.Forms.ContextMenu
    Friend WithEvents RepMenuMove As System.Windows.Forms.MenuItem
    Friend WithEvents RepMenuResize As System.Windows.Forms.MenuItem
    Friend WithEvents RepMenuDelete As System.Windows.Forms.MenuItem
    Friend WithEvents RepMenuEdit As System.Windows.Forms.MenuItem
    Friend WithEvents RepMenuPropEdit As System.Windows.Forms.MenuItem
    Friend WithEvents HelpProvider1 As System.Windows.Forms.HelpProvider
    Friend WithEvents MenuClearSelect As System.Windows.Forms.MenuItem
    Friend WithEvents MenuLClearSelect As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtAlign As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtAlignTop As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtAlignBottom As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtAlignLeft As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtAlignRight As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtVSpaceFirst As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtVSpaceEven As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtVSpaceInc As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtVSpaceDec As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtHSpaceFirst As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtHSpaceEven As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtHSpaceInc As System.Windows.Forms.MenuItem
    Friend WithEvents CtxtHSpaceDec As System.Windows.Forms.MenuItem
    Friend WithEvents ctxtVSpace As System.Windows.Forms.MenuItem
    Friend WithEvents ctxtHSpace As System.Windows.Forms.MenuItem
    Friend WithEvents ctxtAlignCentre As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(nbfEditReport))
        Me.DropCtrl = New System.Windows.Forms.Label
        Me.CtrlContextMenu = New System.Windows.Forms.ContextMenu
        Me.CtxtMenuMove = New System.Windows.Forms.MenuItem
        Me.CtxtMenuResize = New System.Windows.Forms.MenuItem
        Me.CtxtMenuDelete = New System.Windows.Forms.MenuItem
        Me.CtxtMenuEdit = New System.Windows.Forms.MenuItem
        Me.MenuClearSelect = New System.Windows.Forms.MenuItem
        Me.CtxtAlign = New System.Windows.Forms.MenuItem
        Me.CtxtAlignTop = New System.Windows.Forms.MenuItem
        Me.CtxtAlignBottom = New System.Windows.Forms.MenuItem
        Me.CtxtAlignLeft = New System.Windows.Forms.MenuItem
        Me.CtxtAlignRight = New System.Windows.Forms.MenuItem
        Me.ctxtAlignCentre = New System.Windows.Forms.MenuItem
        Me.ctxtVSpace = New System.Windows.Forms.MenuItem
        Me.CtxtVSpaceFirst = New System.Windows.Forms.MenuItem
        Me.CtxtVSpaceEven = New System.Windows.Forms.MenuItem
        Me.CtxtVSpaceInc = New System.Windows.Forms.MenuItem
        Me.CtxtVSpaceDec = New System.Windows.Forms.MenuItem
        Me.ctxtHSpace = New System.Windows.Forms.MenuItem
        Me.CtxtHSpaceFirst = New System.Windows.Forms.MenuItem
        Me.CtxtHSpaceEven = New System.Windows.Forms.MenuItem
        Me.CtxtHSpaceInc = New System.Windows.Forms.MenuItem
        Me.CtxtHSpaceDec = New System.Windows.Forms.MenuItem
        Me.LineContextMenu = New System.Windows.Forms.ContextMenu
        Me.LineMenuDelLine = New System.Windows.Forms.MenuItem
        Me.LineMenuDelBox = New System.Windows.Forms.MenuItem
        Me.MenuLClearSelect = New System.Windows.Forms.MenuItem
        Me.LineMenuResize = New System.Windows.Forms.MenuItem
        Me.ReportMenu = New System.Windows.Forms.ContextMenu
        Me.RepMenuMove = New System.Windows.Forms.MenuItem
        Me.RepMenuResize = New System.Windows.Forms.MenuItem
        Me.RepMenuDelete = New System.Windows.Forms.MenuItem
        Me.RepMenuEdit = New System.Windows.Forms.MenuItem
        Me.RepMenuPropEdit = New System.Windows.Forms.MenuItem
        Me.RepMenuEditList = New System.Windows.Forms.MenuItem
        Me.HelpProvider1 = New System.Windows.Forms.HelpProvider
        Me.ts1 = New System.Windows.Forms.ToolStripContainer
        Me.HScrollBar1 = New System.Windows.Forms.HScrollBar
        Me.VScrollBar1 = New System.Windows.Forms.VScrollBar
        Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
        Me.FileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SaveToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.CloseToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.EditToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SuToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddDataSourceToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.RemoveDataSOurceToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.EditDataSourceToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.BrowseItemsToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddItemToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddTotalToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddAmalganatedTotalToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddSubItemToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.LayoutToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddLabelToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddLineToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.VertHorizLineToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AngledLineToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddBoxToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddPictureToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.CaptionToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AlignmentToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AlignTopToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AlignBottomToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AlignLeftToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AlignRightToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.VerticalSpacingToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SpaceAsFirstToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SpaceEvenlyToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.IncreaseSpacingToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.DecreaseSpacingToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.HorizontalSpacingToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SpaceAsFirstToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me.SpaceEvenlyToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me.IncreaseSpacingToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me.DecreaseSpacingToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me.SectionsToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.RemoveToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.EditToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me.ViewToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.ShowDataToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.ShowFieldInfoToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.AddChartToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.ts1.ContentPanel.SuspendLayout()
        Me.ts1.TopToolStripPanel.SuspendLayout()
        Me.ts1.SuspendLayout()
        Me.MenuStrip1.SuspendLayout()
        Me.SuspendLayout()
        '
        'DropCtrl
        '
        Me.DropCtrl.BackColor = System.Drawing.Color.Gainsboro
        Me.DropCtrl.Location = New System.Drawing.Point(-2, 58)
        Me.DropCtrl.Name = "DropCtrl"
        Me.DropCtrl.Size = New System.Drawing.Size(132, 20)
        Me.DropCtrl.TabIndex = 2
        Me.DropCtrl.Visible = False
        '
        'CtrlContextMenu
        '
        Me.CtrlContextMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.CtxtMenuMove, Me.CtxtMenuResize, Me.CtxtMenuDelete, Me.CtxtMenuEdit, Me.MenuClearSelect, Me.CtxtAlign, Me.ctxtVSpace, Me.ctxtHSpace})
        '
        'CtxtMenuMove
        '
        Me.CtxtMenuMove.Index = 0
        Me.CtxtMenuMove.Text = "&Move"
        '
        'CtxtMenuResize
        '
        Me.CtxtMenuResize.Index = 1
        Me.CtxtMenuResize.Text = "&Resize"
        '
        'CtxtMenuDelete
        '
        Me.CtxtMenuDelete.Index = 2
        Me.CtxtMenuDelete.Text = "&Delete"
        '
        'CtxtMenuEdit
        '
        Me.CtxtMenuEdit.Index = 3
        Me.CtxtMenuEdit.Text = "&Edit Properties"
        '
        'MenuClearSelect
        '
        Me.MenuClearSelect.Index = 4
        Me.MenuClearSelect.Text = "&Clear Selections"
        '
        'CtxtAlign
        '
        Me.CtxtAlign.Index = 5
        Me.CtxtAlign.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.CtxtAlignTop, Me.CtxtAlignBottom, Me.CtxtAlignLeft, Me.CtxtAlignRight, Me.ctxtAlignCentre})
        Me.CtxtAlign.Text = "&Alignment"
        '
        'CtxtAlignTop
        '
        Me.CtxtAlignTop.Index = 0
        Me.CtxtAlignTop.Text = "Align Top"
        '
        'CtxtAlignBottom
        '
        Me.CtxtAlignBottom.Index = 1
        Me.CtxtAlignBottom.Text = "Align Bottom"
        '
        'CtxtAlignLeft
        '
        Me.CtxtAlignLeft.Index = 2
        Me.CtxtAlignLeft.Text = "Align Left"
        '
        'CtxtAlignRight
        '
        Me.CtxtAlignRight.Index = 3
        Me.CtxtAlignRight.Text = "Align Right"
        '
        'ctxtAlignCentre
        '
        Me.ctxtAlignCentre.Index = 4
        Me.ctxtAlignCentre.Text = "Align Centre"
        '
        'ctxtVSpace
        '
        Me.ctxtVSpace.Index = 6
        Me.ctxtVSpace.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.CtxtVSpaceFirst, Me.CtxtVSpaceEven, Me.CtxtVSpaceInc, Me.CtxtVSpaceDec})
        Me.ctxtVSpace.Text = "&Vertical Spacing"
        '
        'CtxtVSpaceFirst
        '
        Me.CtxtVSpaceFirst.Index = 0
        Me.CtxtVSpaceFirst.Text = "Space as First"
        '
        'CtxtVSpaceEven
        '
        Me.CtxtVSpaceEven.Index = 1
        Me.CtxtVSpaceEven.Text = "Space Evenly"
        '
        'CtxtVSpaceInc
        '
        Me.CtxtVSpaceInc.Index = 2
        Me.CtxtVSpaceInc.Text = "Increase Spacing"
        '
        'CtxtVSpaceDec
        '
        Me.CtxtVSpaceDec.Index = 3
        Me.CtxtVSpaceDec.Text = "Decrease Spacing"
        '
        'ctxtHSpace
        '
        Me.ctxtHSpace.Index = 7
        Me.ctxtHSpace.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.CtxtHSpaceFirst, Me.CtxtHSpaceEven, Me.CtxtHSpaceInc, Me.CtxtHSpaceDec})
        Me.ctxtHSpace.Text = "&Horizontal Spacing"
        '
        'CtxtHSpaceFirst
        '
        Me.CtxtHSpaceFirst.Index = 0
        Me.CtxtHSpaceFirst.Text = "Space as First"
        '
        'CtxtHSpaceEven
        '
        Me.CtxtHSpaceEven.Index = 1
        Me.CtxtHSpaceEven.Text = "Space Evenly"
        '
        'CtxtHSpaceInc
        '
        Me.CtxtHSpaceInc.Index = 2
        Me.CtxtHSpaceInc.Text = "Increase Spacing"
        '
        'CtxtHSpaceDec
        '
        Me.CtxtHSpaceDec.Index = 3
        Me.CtxtHSpaceDec.Text = "Decrease Spacing"
        '
        'LineContextMenu
        '
        Me.LineContextMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.LineMenuDelLine, Me.LineMenuDelBox, Me.MenuLClearSelect, Me.LineMenuResize})
        '
        'LineMenuDelLine
        '
        Me.LineMenuDelLine.Index = 0
        Me.LineMenuDelLine.Text = "&Delete Line"
        '
        'LineMenuDelBox
        '
        Me.LineMenuDelBox.Index = 1
        Me.LineMenuDelBox.Text = "D&elete Box"
        '
        'MenuLClearSelect
        '
        Me.MenuLClearSelect.Index = 2
        Me.MenuLClearSelect.Text = "&Clear Selections"
        '
        'LineMenuResize
        '
        Me.LineMenuResize.Index = 3
        Me.LineMenuResize.Text = "&Resize"
        '
        'ReportMenu
        '
        Me.ReportMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.RepMenuMove, Me.RepMenuResize, Me.RepMenuDelete, Me.RepMenuEdit, Me.RepMenuPropEdit, Me.RepMenuEditList})
        '
        'RepMenuMove
        '
        Me.RepMenuMove.Index = 0
        Me.RepMenuMove.Text = "&Move"
        '
        'RepMenuResize
        '
        Me.RepMenuResize.Index = 1
        Me.RepMenuResize.Text = "&Resize"
        '
        'RepMenuDelete
        '
        Me.RepMenuDelete.Index = 2
        Me.RepMenuDelete.Text = "&Delete"
        '
        'RepMenuEdit
        '
        Me.RepMenuEdit.Index = 3
        Me.RepMenuEdit.Text = "&Edit Layout"
        '
        'RepMenuPropEdit
        '
        Me.RepMenuPropEdit.Index = 4
        Me.RepMenuPropEdit.Text = "Ed&it Properties"
        '
        'RepMenuEditList
        '
        Me.RepMenuEditList.Index = 5
        Me.RepMenuEditList.Text = "Edit List Properties"
        '
        'ts1
        '
        '
        'ts1.ContentPanel
        '
        Me.ts1.ContentPanel.BackColor = System.Drawing.Color.LightGray
        Me.ts1.ContentPanel.Controls.Add(Me.HScrollBar1)
        Me.ts1.ContentPanel.Controls.Add(Me.DropCtrl)
        Me.ts1.ContentPanel.Controls.Add(Me.VScrollBar1)
        Me.ts1.ContentPanel.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional
        Me.ts1.ContentPanel.Size = New System.Drawing.Size(292, 249)
        Me.ts1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ts1.Location = New System.Drawing.Point(0, 0)
        Me.ts1.Name = "ts1"
        Me.ts1.Size = New System.Drawing.Size(292, 273)
        Me.ts1.TabIndex = 7
        Me.ts1.Text = "ToolStripContainer1"
        '
        'ts1.TopToolStripPanel
        '
        Me.ts1.TopToolStripPanel.Controls.Add(Me.MenuStrip1)
        '
        'HScrollBar1
        '
        Me.HScrollBar1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.HScrollBar1.Location = New System.Drawing.Point(0, 233)
        Me.HScrollBar1.Name = "HScrollBar1"
        Me.HScrollBar1.Size = New System.Drawing.Size(276, 16)
        Me.HScrollBar1.TabIndex = 1
        '
        'VScrollBar1
        '
        Me.VScrollBar1.Dock = System.Windows.Forms.DockStyle.Right
        Me.VScrollBar1.Location = New System.Drawing.Point(276, 0)
        Me.VScrollBar1.Name = "VScrollBar1"
        Me.VScrollBar1.Size = New System.Drawing.Size(16, 249)
        Me.VScrollBar1.TabIndex = 0
        '
        'MenuStrip1
        '
        Me.MenuStrip1.Dock = System.Windows.Forms.DockStyle.None
        Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem, Me.EditToolStripMenuItem, Me.ViewToolStripMenuItem})
        Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
        Me.MenuStrip1.Name = "MenuStrip1"
        Me.MenuStrip1.Size = New System.Drawing.Size(292, 24)
        Me.MenuStrip1.TabIndex = 3
        Me.MenuStrip1.Text = "MenuStrip1"
        '
        'FileToolStripMenuItem
        '
        Me.FileToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.SaveToolStripMenuItem, Me.CloseToolStripMenuItem})
        Me.FileToolStripMenuItem.Name = "FileToolStripMenuItem"
        Me.FileToolStripMenuItem.Size = New System.Drawing.Size(37, 20)
        Me.FileToolStripMenuItem.Text = "&File"
        '
        'SaveToolStripMenuItem
        '
        Me.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"
        Me.SaveToolStripMenuItem.Size = New System.Drawing.Size(103, 22)
        Me.SaveToolStripMenuItem.Text = "&Save"
        '
        'CloseToolStripMenuItem
        '
        Me.CloseToolStripMenuItem.Name = "CloseToolStripMenuItem"
        Me.CloseToolStripMenuItem.Size = New System.Drawing.Size(103, 22)
        Me.CloseToolStripMenuItem.Text = "&Close"
        '
        'EditToolStripMenuItem
        '
        Me.EditToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.SuToolStripMenuItem, Me.BrowseItemsToolStripMenuItem, Me.LayoutToolStripMenuItem, Me.SectionsToolStripMenuItem})
        Me.EditToolStripMenuItem.Name = "EditToolStripMenuItem"
        Me.EditToolStripMenuItem.Size = New System.Drawing.Size(39, 20)
        Me.EditToolStripMenuItem.Text = "&Edit"
        '
        'SuToolStripMenuItem
        '
        Me.SuToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.AddDataSourceToolStripMenuItem, Me.RemoveDataSOurceToolStripMenuItem, Me.EditDataSourceToolStripMenuItem})
        Me.SuToolStripMenuItem.Name = "SuToolStripMenuItem"
        Me.SuToolStripMenuItem.Size = New System.Drawing.Size(167, 22)
        Me.SuToolStripMenuItem.Text = "Sub-Data Sources"
        '
        'AddDataSourceToolStripMenuItem
        '
        Me.AddDataSourceToolStripMenuItem.Name = "AddDataSourceToolStripMenuItem"
        Me.AddDataSourceToolStripMenuItem.Size = New System.Drawing.Size(183, 22)
        Me.AddDataSourceToolStripMenuItem.Text = "&Add Data Source"
        '
        'RemoveDataSOurceToolStripMenuItem
        '
        Me.RemoveDataSOurceToolStripMenuItem.Name = "RemoveDataSOurceToolStripMenuItem"
        Me.RemoveDataSOurceToolStripMenuItem.Size = New System.Drawing.Size(183, 22)
        Me.RemoveDataSOurceToolStripMenuItem.Text = "&Remove Data Source"
        '
        'EditDataSourceToolStripMenuItem
        '
        Me.EditDataSourceToolStripMenuItem.Name = "EditDataSourceToolStripMenuItem"
        Me.EditDataSourceToolStripMenuItem.Size = New System.Drawing.Size(183, 22)
        Me.EditDataSourceToolStripMenuItem.Text = "&Edit Data Source"
        '
        'BrowseItemsToolStripMenuItem
        '
        Me.BrowseItemsToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.AddItemToolStripMenuItem, Me.AddTotalToolStripMenuItem, Me.AddAmalganatedTotalToolStripMenuItem, Me.AddSubItemToolStripMenuItem})
        Me.BrowseItemsToolStripMenuItem.Name = "BrowseItemsToolStripMenuItem"
        Me.BrowseItemsToolStripMenuItem.Size = New System.Drawing.Size(167, 22)
        Me.BrowseItemsToolStripMenuItem.Text = "Browse Items"
        '
        'AddItemToolStripMenuItem
        '
        Me.AddItemToolStripMenuItem.Name = "AddItemToolStripMenuItem"
        Me.AddItemToolStripMenuItem.Size = New System.Drawing.Size(204, 22)
        Me.AddItemToolStripMenuItem.Text = "Add Item"
        '
        'AddTotalToolStripMenuItem
        '
        Me.AddTotalToolStripMenuItem.Name = "AddTotalToolStripMenuItem"
        Me.AddTotalToolStripMenuItem.Size = New System.Drawing.Size(204, 22)
        Me.AddTotalToolStripMenuItem.Text = "Add Total"
        '
        'AddAmalganatedTotalToolStripMenuItem
        '
        Me.AddAmalganatedTotalToolStripMenuItem.Name = "AddAmalganatedTotalToolStripMenuItem"
        Me.AddAmalganatedTotalToolStripMenuItem.Size = New System.Drawing.Size(204, 22)
        Me.AddAmalganatedTotalToolStripMenuItem.Text = "Add Amalgamated Total"
        '
        'AddSubItemToolStripMenuItem
        '
        Me.AddSubItemToolStripMenuItem.Name = "AddSubItemToolStripMenuItem"
        Me.AddSubItemToolStripMenuItem.Size = New System.Drawing.Size(204, 22)
        Me.AddSubItemToolStripMenuItem.Text = "Add Sub Item"
        '
        'LayoutToolStripMenuItem
        '
        Me.LayoutToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.AddLabelToolStripMenuItem, Me.AddLineToolStripMenuItem, Me.AddBoxToolStripMenuItem, Me.AddPictureToolStripMenuItem, Me.AddChartToolStripMenuItem, Me.CaptionToolStripMenuItem, Me.AlignmentToolStripMenuItem, Me.VerticalSpacingToolStripMenuItem, Me.HorizontalSpacingToolStripMenuItem})
        Me.LayoutToolStripMenuItem.Name = "LayoutToolStripMenuItem"
        Me.LayoutToolStripMenuItem.Size = New System.Drawing.Size(167, 22)
        Me.LayoutToolStripMenuItem.Text = "Layout"
        '
        'AddLabelToolStripMenuItem
        '
        Me.AddLabelToolStripMenuItem.Name = "AddLabelToolStripMenuItem"
        Me.AddLabelToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.AddLabelToolStripMenuItem.Text = "Add Label"
        '
        'AddLineToolStripMenuItem
        '
        Me.AddLineToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.VertHorizLineToolStripMenuItem, Me.AngledLineToolStripMenuItem})
        Me.AddLineToolStripMenuItem.Name = "AddLineToolStripMenuItem"
        Me.AddLineToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.AddLineToolStripMenuItem.Text = "Add Line"
        '
        'VertHorizLineToolStripMenuItem
        '
        Me.VertHorizLineToolStripMenuItem.Name = "VertHorizLineToolStripMenuItem"
        Me.VertHorizLineToolStripMenuItem.Size = New System.Drawing.Size(156, 22)
        Me.VertHorizLineToolStripMenuItem.Text = "Vert./Horiz Line"
        '
        'AngledLineToolStripMenuItem
        '
        Me.AngledLineToolStripMenuItem.Name = "AngledLineToolStripMenuItem"
        Me.AngledLineToolStripMenuItem.Size = New System.Drawing.Size(156, 22)
        Me.AngledLineToolStripMenuItem.Text = "Angled Line"
        '
        'AddBoxToolStripMenuItem
        '
        Me.AddBoxToolStripMenuItem.Name = "AddBoxToolStripMenuItem"
        Me.AddBoxToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.AddBoxToolStripMenuItem.Text = "Add Box"
        '
        'AddPictureToolStripMenuItem
        '
        Me.AddPictureToolStripMenuItem.Name = "AddPictureToolStripMenuItem"
        Me.AddPictureToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.AddPictureToolStripMenuItem.Text = "Add Picture"
        '
        'CaptionToolStripMenuItem
        '
        Me.CaptionToolStripMenuItem.Name = "CaptionToolStripMenuItem"
        Me.CaptionToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.CaptionToolStripMenuItem.Text = "Caption"
        '
        'AlignmentToolStripMenuItem
        '
        Me.AlignmentToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.AlignTopToolStripMenuItem, Me.AlignBottomToolStripMenuItem, Me.AlignLeftToolStripMenuItem, Me.AlignRightToolStripMenuItem})
        Me.AlignmentToolStripMenuItem.Name = "AlignmentToolStripMenuItem"
        Me.AlignmentToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.AlignmentToolStripMenuItem.Text = "Alignment"
        '
        'AlignTopToolStripMenuItem
        '
        Me.AlignTopToolStripMenuItem.Name = "AlignTopToolStripMenuItem"
        Me.AlignTopToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.AlignTopToolStripMenuItem.Text = "Align Top"
        '
        'AlignBottomToolStripMenuItem
        '
        Me.AlignBottomToolStripMenuItem.Name = "AlignBottomToolStripMenuItem"
        Me.AlignBottomToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.AlignBottomToolStripMenuItem.Text = "Align Bottom"
        '
        'AlignLeftToolStripMenuItem
        '
        Me.AlignLeftToolStripMenuItem.Name = "AlignLeftToolStripMenuItem"
        Me.AlignLeftToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.AlignLeftToolStripMenuItem.Text = "Align Left"
        '
        'AlignRightToolStripMenuItem
        '
        Me.AlignRightToolStripMenuItem.Name = "AlignRightToolStripMenuItem"
        Me.AlignRightToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.AlignRightToolStripMenuItem.Text = "Align Right"
        '
        'VerticalSpacingToolStripMenuItem
        '
        Me.VerticalSpacingToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.SpaceAsFirstToolStripMenuItem, Me.SpaceEvenlyToolStripMenuItem, Me.IncreaseSpacingToolStripMenuItem, Me.DecreaseSpacingToolStripMenuItem})
        Me.VerticalSpacingToolStripMenuItem.Name = "VerticalSpacingToolStripMenuItem"
        Me.VerticalSpacingToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.VerticalSpacingToolStripMenuItem.Text = "Vertical Spacing"
        '
        'SpaceAsFirstToolStripMenuItem
        '
        Me.SpaceAsFirstToolStripMenuItem.Name = "SpaceAsFirstToolStripMenuItem"
        Me.SpaceAsFirstToolStripMenuItem.Size = New System.Drawing.Size(166, 22)
        Me.SpaceAsFirstToolStripMenuItem.Text = "Space as First"
        '
        'SpaceEvenlyToolStripMenuItem
        '
        Me.SpaceEvenlyToolStripMenuItem.Name = "SpaceEvenlyToolStripMenuItem"
        Me.SpaceEvenlyToolStripMenuItem.Size = New System.Drawing.Size(166, 22)
        Me.SpaceEvenlyToolStripMenuItem.Text = "Space Evenly"
        '
        'IncreaseSpacingToolStripMenuItem
        '
        Me.IncreaseSpacingToolStripMenuItem.Name = "IncreaseSpacingToolStripMenuItem"
        Me.IncreaseSpacingToolStripMenuItem.Size = New System.Drawing.Size(166, 22)
        Me.IncreaseSpacingToolStripMenuItem.Text = "Increase Spacing"
        '
        'DecreaseSpacingToolStripMenuItem
        '
        Me.DecreaseSpacingToolStripMenuItem.Name = "DecreaseSpacingToolStripMenuItem"
        Me.DecreaseSpacingToolStripMenuItem.Size = New System.Drawing.Size(166, 22)
        Me.DecreaseSpacingToolStripMenuItem.Text = "Decrease Spacing"
        '
        'HorizontalSpacingToolStripMenuItem
        '
        Me.HorizontalSpacingToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.SpaceAsFirstToolStripMenuItem1, Me.SpaceEvenlyToolStripMenuItem1, Me.IncreaseSpacingToolStripMenuItem1, Me.DecreaseSpacingToolStripMenuItem1})
        Me.HorizontalSpacingToolStripMenuItem.Name = "HorizontalSpacingToolStripMenuItem"
        Me.HorizontalSpacingToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.HorizontalSpacingToolStripMenuItem.Text = "Horizontal Spacing"
        '
        'SpaceAsFirstToolStripMenuItem1
        '
        Me.SpaceAsFirstToolStripMenuItem1.Name = "SpaceAsFirstToolStripMenuItem1"
        Me.SpaceAsFirstToolStripMenuItem1.Size = New System.Drawing.Size(166, 22)
        Me.SpaceAsFirstToolStripMenuItem1.Text = "Space as First"
        '
        'SpaceEvenlyToolStripMenuItem1
        '
        Me.SpaceEvenlyToolStripMenuItem1.Name = "SpaceEvenlyToolStripMenuItem1"
        Me.SpaceEvenlyToolStripMenuItem1.Size = New System.Drawing.Size(166, 22)
        Me.SpaceEvenlyToolStripMenuItem1.Text = "Space Evenly"
        '
        'IncreaseSpacingToolStripMenuItem1
        '
        Me.IncreaseSpacingToolStripMenuItem1.Name = "IncreaseSpacingToolStripMenuItem1"
        Me.IncreaseSpacingToolStripMenuItem1.Size = New System.Drawing.Size(166, 22)
        Me.IncreaseSpacingToolStripMenuItem1.Text = "Increase Spacing"
        '
        'DecreaseSpacingToolStripMenuItem1
        '
        Me.DecreaseSpacingToolStripMenuItem1.Name = "DecreaseSpacingToolStripMenuItem1"
        Me.DecreaseSpacingToolStripMenuItem1.Size = New System.Drawing.Size(166, 22)
        Me.DecreaseSpacingToolStripMenuItem1.Text = "Decrease Spacing"
        '
        'SectionsToolStripMenuItem
        '
        Me.SectionsToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.AddToolStripMenuItem, Me.RemoveToolStripMenuItem, Me.EditToolStripMenuItem1})
        Me.SectionsToolStripMenuItem.Name = "SectionsToolStripMenuItem"
        Me.SectionsToolStripMenuItem.Size = New System.Drawing.Size(167, 22)
        Me.SectionsToolStripMenuItem.Text = "Sections"
        '
        'AddToolStripMenuItem
        '
        Me.AddToolStripMenuItem.Name = "AddToolStripMenuItem"
        Me.AddToolStripMenuItem.Size = New System.Drawing.Size(117, 22)
        Me.AddToolStripMenuItem.Text = "Add"
        '
        'RemoveToolStripMenuItem
        '
        Me.RemoveToolStripMenuItem.Name = "RemoveToolStripMenuItem"
        Me.RemoveToolStripMenuItem.Size = New System.Drawing.Size(117, 22)
        Me.RemoveToolStripMenuItem.Text = "Remove"
        '
        'EditToolStripMenuItem1
        '
        Me.EditToolStripMenuItem1.Name = "EditToolStripMenuItem1"
        Me.EditToolStripMenuItem1.Size = New System.Drawing.Size(117, 22)
        Me.EditToolStripMenuItem1.Text = "Edit"
        '
        'ViewToolStripMenuItem
        '
        Me.ViewToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ShowDataToolStripMenuItem, Me.ShowFieldInfoToolStripMenuItem})
        Me.ViewToolStripMenuItem.Name = "ViewToolStripMenuItem"
        Me.ViewToolStripMenuItem.Size = New System.Drawing.Size(44, 20)
        Me.ViewToolStripMenuItem.Text = "&View"
        '
        'ShowDataToolStripMenuItem
        '
        Me.ShowDataToolStripMenuItem.Name = "ShowDataToolStripMenuItem"
        Me.ShowDataToolStripMenuItem.Size = New System.Drawing.Size(155, 22)
        Me.ShowDataToolStripMenuItem.Text = "Show Data"
        '
        'ShowFieldInfoToolStripMenuItem
        '
        Me.ShowFieldInfoToolStripMenuItem.Name = "ShowFieldInfoToolStripMenuItem"
        Me.ShowFieldInfoToolStripMenuItem.Size = New System.Drawing.Size(155, 22)
        Me.ShowFieldInfoToolStripMenuItem.Text = "Show Field Info"
        '
        'AddChartToolStripMenuItem
        '
        Me.AddChartToolStripMenuItem.Name = "AddChartToolStripMenuItem"
        Me.AddChartToolStripMenuItem.Size = New System.Drawing.Size(174, 22)
        Me.AddChartToolStripMenuItem.Text = "Add Chart"
        '
        'nbfEditReport
        '
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.ts1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "nbfEditReport"
        Me.Text = "Edit Report"
        Me.ts1.ContentPanel.ResumeLayout(False)
        Me.ts1.TopToolStripPanel.ResumeLayout(False)
        Me.ts1.TopToolStripPanel.PerformLayout()
        Me.ts1.ResumeLayout(False)
        Me.ts1.PerformLayout()
        Me.MenuStrip1.ResumeLayout(False)
        Me.MenuStrip1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public Sub SetUpForm()
        Dim sz As New Size
        ts1.Dock = DockStyle.Fill
        'Me.BackColor = System.Drawing.Color.Gainsboro
        'Me.ForeColor = System.Drawing.Color.Black
        sz.Width = Rep.Size.Width + LeftBorder + RightBorder
        sz.Height = Rep.Size.Height + TopBorder + BottomBorder
        'Me.AutoScrollMinSize = sz
        Me.Text = pvBrowseRep.BFInfo.Caption
        OrderSections()
        Dim sbc As nbfBrowseCtrl
        Dim fx As Integer = 0
        For Each sbc In pvBrowseRep.BFInfo.SQLBrowseCtrls
            If sbc Is Rep Then
                Exit For
            End If
            If pvBrowseRep.fofst(Rep, sbc, fx) Then
                Exit For
            End If
        Next
        EditXOffset = Rep.Left + fx
        Setoverspill()
        RefreshDisplay()
        'ResetBuffer()
    End Sub
    Sub Setoverspill()
        Try
            If Not pvBrowseRep Is Nothing Then
                If pvBrowseRep.BFInfo.BrowseStyle = "B" Then
                    y_offset = 0
                    y_overspill = 0
                    VScrollBar1.Visible = False
                    x_offset = 0
                    x_overspill = 0
                    HScrollBar1.Visible = False
                    Exit Sub
                End If
                Dim dispHt As Integer = pvBrowseRep.BFInfo.FormSize.Height + CInt(TopBorder * pvBrowseRep.BFInfo.PageSize.Height / pvBrowseRep.BFInfo.FormSize.Height) + CInt(BottomBorder * pvBrowseRep.BFInfo.PageSize.Height / pvBrowseRep.BFInfo.FormSize.Height)
                Dim dispWd As Integer = pvBrowseRep.BFInfo.FormSize.Width + CInt(LeftBorder * pvBrowseRep.BFInfo.PageSize.Width / pvBrowseRep.BFInfo.FormSize.Width) + CInt(RightBorder * pvBrowseRep.BFInfo.PageSize.Width / pvBrowseRep.BFInfo.FormSize.Width)
                If dispHt > (ts1.ContentPanel.Height - HScrollBar1.Height) Then
                    y_overspill = dispHt - (ts1.ContentPanel.Height - HScrollBar1.Height)
                    VScrollBar1.Visible = True
                    VScrollBar1.Minimum = 0
                    VScrollBar1.Maximum = y_overspill + (y_overspill / 4)
                    If y_overspill > 10 Then
                        VScrollBar1.SmallChange = y_overspill / 10
                        VScrollBar1.LargeChange = y_overspill / 4
                    End If
                Else
                    y_overspill = 0
                    VScrollBar1.Visible = False
                End If
                If dispWd > (ts1.ContentPanel.Width - VScrollBar1.Width) Then
                    x_overspill = dispWd - (ts1.ContentPanel.Width - VScrollBar1.Width)
                    HScrollBar1.Minimum = 0
                    HScrollBar1.Maximum = x_overspill + (x_overspill / 4)
                    If x_overspill > 10 Then
                        HScrollBar1.SmallChange = x_overspill / 10
                        HScrollBar1.LargeChange = x_overspill / 4
                    End If
                    HScrollBar1.Visible = True
                Else
                    x_overspill = 0
                    HScrollBar1.Visible = False
                End If
                If x_offset > x_overspill Then
                    x_offset = 0
                End If
                If y_offset > y_overspill Then
                    y_offset = 0
                End If
            Else
                x_overspill = 0
                HScrollBar1.Visible = False
                y_overspill = 0
                VScrollBar1.Visible = False
            End If
        Catch ex As Exception
        End Try
    End Sub
    Sub ResetBuffer()
        Try
            If _backBuffer Is Nothing Then
                If Not pvBrowseRep Is Nothing Then
                    If pvBrowseRep.BFInfo.FormSize.Width > 0 And pvBrowseRep.BFInfo.FormSize.Height > 0 Then
                        Dim g As Graphics = ts1.ContentPanel.CreateGraphics()
                        _backBuffer = New Bitmap(pvBrowseRep.BFInfo.FormSize.Width * 2, pvBrowseRep.BFInfo.FormSize.Height * 2, g)
                        g.Dispose()
                    End If
                    'pvBrowseRep.ResetSqlSources()
                End If
            End If

            Exit Sub

            If Not (_backBuffer Is Nothing) Then
                _backBuffer.Dispose()
                _backBuffer = Nothing
            End If
            If Not pvBrowseRep Is Nothing Then
                If pvBrowseRep.BFInfo.FormSize.Width > 0 And pvBrowseRep.BFInfo.FormSize.Height > 0 Then
                    _backBuffer = New Bitmap(pvBrowseRep.BFInfo.FormSize.Width, pvBrowseRep.BFInfo.FormSize.Height)
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub ClearSelect(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Do While SelectedControls.Count > 0
            SelectedControls.Remove(1)
        Loop
        RefreshDisplay()
    End Sub
    Sub DrawPanel(ByVal rs As nbfSQLRepSection, ByVal g As Graphics, Optional ByVal DesignMode As Boolean = True)
        Try
            Dim rc As RectangleF
            Dim brc As Rectangle
            Dim fi As RepFontInfo
            Dim ft As Font
            Dim lc As New Point
            Dim pi As New RectangleF
            Dim sz As Size
            Dim fpt As New System.Drawing.Point
            Dim sqs As nbfSqlSource
            Dim brush = New SolidBrush(System.Drawing.Color.WhiteSmoke)
            Dim sbrush = New SolidBrush(System.Drawing.Color.Gainsboro)
            Dim lbrush = New SolidBrush(System.Drawing.Color.Black)
            Dim stit As String = ""
            Dim Dest As String = "D"
            If pvShowSubReps Then
                Dest = "P"
            End If
            Dim CheckPages As Boolean = False
            Dim r As RectangleF
            Dim sf As New StringFormat
            CheckGraphSet()
            fi = pvBrowseRep.GetDefRepFont(True, 8)
            ft = pvBrowseRep.GetRepFont(fi)
            sf.Trimming = StringTrimming.None
            'sf.FormatFlags = sf.FormatFlags or StringFormatFlags.NoWrap
            sf.Alignment = StringAlignment.Near
            sf.LineAlignment = StringAlignment.Center
            sqs = pvBrowseRep.GetSqSFromName(Rep.SQLSource)
            With rs
                lc.Y = .FormPos
                lc.X = 0  'LeftBorder
                'lc = SetAsLoc(lc)
                rc.X = lc.X
                rc.Y = lc.Y
                rc.Width = Rep.Width
                rc.Height = .SectionHeight
                sz.Width = Rep.Width
                sz.Height = .SectionHeight
                Select Case .SectionType
                    Case "H"
                        stit = "Rep"
                    Case "P"
                        stit = "Page"
                    Case "S"
                        stit = "S " & CStr(.SectionIndex)
                    Case "B"
                        stit = "Body"
                End Select
                If .SectionType <> "B" Then
                    Select Case .SectionHead
                        Case True
                            stit &= Chr(10) & Chr(13) & "Head"
                        Case False
                            stit &= Chr(10) & Chr(13) & "Foot"
                    End Select
                End If
                r = New RectangleF(rc.X, rc.Y, rc.Width, rc.Height)
                g.DrawString(stit, ft, lbrush, r, sf)
                lc.X += LeftBorder
                rc.X += LeftBorder
                pi = rc
                g.FillRectangle(brush, rc)
                g.DrawRectangle(LineDrawPen, rc.X, rc.Y, rc.Width, rc.Height)
                rc.Y = rc.Y + .SectionHeight
                rc.Height = spw
                g.FillRectangle(sbrush, rc)
                'pvBrowseRep.PrintSection(rs,sqs,pi,sz,Rep,True,CheckPages,"D")
                'if false then
                Dim bc As nbfBrowseCtrl
                Dim rci As New Rectangle
                Dim rcb As New Rectangle
                Dim rcii As New Rectangle
                For Each bc In .SectionCtrls
                    fpt.X = LeftBorder + bc.Location.X
                    fpt.Y = .FormPos + bc.Location.Y
                    bc.GrowthOffset = 0
                    bc.FormRepPos = fpt
                Next
                For Each bc In SelectedControls 'pvBrowseRep.BFInfo.SQLBrowseCtrls
                    rci.X = bc.FormRepPos.X '+ Me.AutoScrollPosition.X
                    rci.Y = bc.FormRepPos.Y '+ Me.AutoScrollPosition.Y
                    rci.Width = bc.Width
                    rci.Height = bc.Height
                    rcii.X = rci.X
                    rcii.Y = rci.Y
                    rcii.Width = rci.Width
                    rcii.Height = rci.Height
                    rci.Inflate(2, 2)
                    rcb.X = rci.X
                    rcb.Y = rci.Y
                    rcb.Width = rci.Width
                    rcb.Height = rci.Height
                    rcb.Inflate(1, 1)
                    'ControlPaint.DrawGrabHandle(g, rci, True, True)
                    ControlPaint.DrawSelectionFrame(g, True, rci, rcii, pvAppFrmSI.FormBackColour)
                Next
                If Not pvShowSubReps Then
                    For Each bc In .SectionCtrls
                        If Not (bc.OrderSet = False And bc.Top = 0 And bc.Left = 0) Then
                            Select Case bc.CtlType
                                Case "Line", "Box"
                                    If (bc.Top < .SectionHeight) And (bc.Left < Rep.Width) Then
                                        pvBrowseRep.PrintBrowseCtrl(bc, g, pi, sz, True, False, False, "", "D")
                                    End If
                                Case Else
                                    DrawCtlLabel(bc, lc, g)
                            End Select
                        End If
                    Next
                Else
                    For Each bc In .SectionCtrls
                        If Not (bc.OrderSet = False And bc.Top = 0 And bc.Left = 0) Then
                            Select Case bc.CtlType
                                Case "Grid", "Report"
                                    If Not pvShowSubReps Then
                                        brc.Y = lc.Y + bc.Top
                                        brc.X = lc.X + bc.Left
                                        brc.Width = bc.Width
                                        brc.Height = bc.Height
                                        g.DrawRectangle(LineDrawPen, brc)
                                    Else
                                        bc.NextRecordPos = 1
                                        bc.NextSectReq = "C1"
                                        bc.NextSectNo = 0
                                        'bc.DrivingSqlSource = sqs
                                        pvBrowseRep.PrintSubRep(bc, g, pi, sz, "D")
                                    End If
                            End Select
                        End If
                    Next
                    For Each bc In .SectionCtrls
                        If Not (bc.OrderSet = False And bc.Top = 0 And bc.Left = 0) Then
                            Select Case bc.CtlType
                                Case "Grid", "Report"
                                    'no action
                                Case Else
                                    If (bc.Top < .SectionHeight) And (bc.Left < Rep.Width) Then
                                        pvBrowseRep.PrintBrowseCtrl(bc, g, pi, sz, True, False, False, "", "D")
                                    End If
                            End Select
                        End If
                    Next
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub OrderSections()
        Dim rs As nbfSQLRepSection
        Dim rsCol As New nbfSQLRepSections
        Dim MaxSectIdx As Integer = 0
        For Each rs In Rep.RepSections
            rs.PanelSet = False
            If rs.SectionIndex > MaxSectIdx Then
                MaxSectIdx = rs.SectionIndex
            End If
        Next
        Dim rt As Integer = 0
        For Each rs In Rep.RepSections
            Select Case rs.SectionType
                Case "H"
                    With rs
                        If .SectionHead Then
                            .PanelSet = True
                            .SectionNumber = rt
                            rt += 1
                            rsCol.Add(rs)
                        End If
                    End With
            End Select
        Next
        For Each rs In Rep.RepSections
            Select Case rs.SectionType
                Case "P"
                    With rs
                        If .SectionHead Then
                            .PanelSet = True
                            .SectionNumber = rt
                            rt += 1
                            rsCol.Add(rs)
                        End If
                    End With
            End Select
        Next
        Dim scnt As Integer = 0
        Dim pfnd As Boolean
        Do
            pfnd = False
            scnt += 1
            For Each rs In Rep.RepSections
                Select Case rs.SectionType
                    Case "S"
                        If Not rs.PanelSet Then
                            If rs.SectionHead Then
                                pfnd = True
                                If rs.SectionIndex <= scnt Then
                                    With rs
                                        .PanelSet = True
                                        .SectionNumber = rt
                                        rt += 1
                                        rsCol.Add(rs)
                                    End With
                                End If
                            End If
                        End If
                End Select
            Next rs
        Loop While pfnd
        'if false then
        For Each rs In Rep.RepSections
            Select Case rs.SectionType
                Case "B"
                    With rs
                        .PanelSet = True
                        .SectionNumber = rt
                        rt += 1
                        rsCol.Add(rs)
                    End With
            End Select
        Next
        scnt = MaxSectIdx + 1
        Do
            pfnd = False
            scnt -= 1
            For Each rs In Rep.RepSections
                Select Case rs.SectionType
                    Case "S"
                        If Not rs.SectionHead Then
                            If Not rs.PanelSet Then
                                pfnd = True
                                If rs.SectionIndex >= scnt Then
                                    With rs
                                        .PanelSet = True
                                        .SectionNumber = rt
                                        rt += 1
                                        rsCol.Add(rs)
                                    End With
                                End If
                            End If
                        End If
                End Select
            Next rs
        Loop While pfnd
        For Each rs In Rep.RepSections
            Select Case rs.SectionType
                Case "H"
                    If Not rs.SectionHead Then
                        With rs
                            .PanelSet = True
                            .SectionNumber = rt
                            rt += 1
                            rsCol.Add(rs)
                        End With
                    End If
            End Select
        Next
        For Each rs In Rep.RepSections
            Select Case rs.SectionType
                Case "P"
                    If Not rs.SectionHead Then
                        With rs
                            .PanelSet = True
                            .SectionNumber = rt
                            rt += 1
                            rsCol.Add(rs)
                        End With
                    End If
            End Select
        Next
        Rep.RepSections.Clear()
        For Each rs In rsCol
            Debug.WriteLine(rs.SectionName & " " & CStr(rs.SectionNumber))
            Rep.RepSections.Add(rs)
        Next rs
        rsCol.Clear()
        OrderControls()
    End Sub
    Private Sub OrderControls()
        Dim y_pos As Double = 999999999
        Dim x_pos As Double = 999999999
        Dim rs As nbfSQLRepSection
        Dim bc As nbfBrowseCtrl
        Dim bcCol As New nbfBrowseCtrls
        Dim cfnd As Boolean
        For Each rs In Rep.RepSections
            If True Then 'rs.SectionType = "B" then
                For Each bc In rs.SectionCtrls
                    bc.OrderSet = False
                    With bc
                        If .Top < y_pos Then
                            y_pos = .Top

                        End If
                    End With
                Next
                Do
                    cfnd = False
                    y_pos = 999999999
                    For Each bc In rs.SectionCtrls
                        With bc
                            If Not .OrderSet Then
                                cfnd = True
                                If .Top < y_pos Then
                                    y_pos = .Top
                                End If
                            End If
                        End With
                    Next
                    If cfnd Then
                        x_pos = 999999999
                        For Each bc In rs.SectionCtrls
                            With bc
                                If Not .OrderSet And .Top = y_pos Then
                                    If .Left < x_pos Then
                                        x_pos = .Left
                                    End If
                                End If
                            End With
                        Next
                        For Each bc In rs.SectionCtrls
                            With bc
                                If Not .OrderSet Then
                                    If .Top = y_pos And .Left = x_pos Then
                                        bcCol.Add(bc)
                                        .OrderSet = True
                                    End If
                                End If
                            End With
                        Next
                    End If
                Loop While cfnd
                rs.SectionCtrls.Clear()
                For Each bc In bcCol
                    rs.SectionCtrls.Add(bc)
                Next
                bcCol.Clear()
            End If
        Next
    End Sub
    Sub AlignTops(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim bc As nbfBrowseCtrl
        Dim cp As Integer = 999999999
        Dim rs As New nbfSQLRepSection
        For Each rs In Rep.RepSections
            cp = 999999999
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    If bc.Top < cp Then
                        cp = bc.Top
                    End If
                End If
            Next
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    bc.Top = cp
                End If
            Next
        Next
        RefreshDisplay()
    End Sub
    Private Function inSect(ByVal bc As nbfBrowseCtrl, ByVal rs As nbfSQLRepSection) As Boolean
        Dim sbc As nbfBrowseCtrl
        For Each sbc In rs.SectionCtrls
            If sbc Is bc Then
                Return True
            End If
        Next
        Return False
    End Function
    Sub AlignBottoms(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim bc As nbfBrowseCtrl
        Dim cp As Integer = 0
        Dim rs As New nbfSQLRepSection
        For Each rs In Rep.RepSections
            cp = 0
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    If bc.Top + bc.Height > cp Then
                        cp = bc.Top + bc.Height
                    End If
                End If
            Next
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    bc.Top = cp - bc.Height
                End If
            Next
        Next
        RefreshDisplay()
    End Sub
    Sub AlignLefts(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim bc As nbfBrowseCtrl
        Dim cp As Integer = 999999999
        Dim rs As New nbfSQLRepSection
        For Each rs In Rep.RepSections
            cp = 999999999

            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    If bc.Left < cp Then
                        cp = bc.Left
                    End If
                End If
            Next
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    bc.Left = cp
                End If
            Next
        Next
        RefreshDisplay()
    End Sub
    Sub AlignRights(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim bc As nbfBrowseCtrl
        Dim cp As Integer = 0
        Dim rs As New nbfSQLRepSection
        For Each rs In Rep.RepSections
            cp = 0
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    If bc.Left + bc.Width > cp Then
                        cp = bc.Left + bc.Width
                    End If
                End If
            Next
            For Each bc In SelectedControls
                If inSect(bc, rs) Then
                    bc.Left = cp - bc.Width
                End If
            Next
        Next
        RefreshDisplay()
    End Sub
    Sub AlignCentres(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim bc As nbfBrowseCtrl
        Dim cp As Integer = 0
        Dim cpos As Integer = 0
        For Each bc In SelectedControls
            cp += 1
            If cp = 1 Then
                cpos = CInt(bc.Left + (bc.Width / 2))
            Else
                bc.Left = CInt(cpos - (bc.Width / 2))
            End If
        Next
        RefreshDisplay()
    End Sub
    Private Function GetSect(ByVal bc As nbfBrowseCtrl) As nbfSQLRepSection
        Dim rs As nbfSQLRepSection
        Dim sbc As nbfBrowseCtrl
        For Each rs In Rep.RepSections
            For Each sbc In rs.SectionCtrls
                If sbc Is bc Then
                    Return rs
                End If
            Next
        Next
        Return Nothing
    End Function
    Private Function CheckinSect() As Boolean
        Try
            Dim rs As nbfSQLRepSection
            Dim srs As nbfSQLRepSection
            Dim bc As nbfBrowseCtrl
            Dim cnt As Integer = 0
            For Each bc In SelectedControls
                cnt += 1
                If cnt = 1 Then
                    rs = GetSect(bc)
                    If rs Is Nothing Then
                        MsgBox("UnabLe to Retrieve section info")
                        Return False
                    End If
                Else
                    srs = GetSect(bc)
                    If rs Is Nothing Then
                        MsgBox("Unable to Retrieve section info")
                        Return False
                    End If
                    If Not srs Is rs Then
                        MsgBox("All selected controls must be in the same section before using spacing options")
                        Return False
                    End If
                End If
            Next
            Return True
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
    Sub SpaceFirstV(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedVert(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            For Each bc In oc
                cc += 1
                If cc = 1 Then
                    spos = bc.Top + bc.Height
                ElseIf cc = 2 Then
                    spac = bc.Top - spos
                    spos = bc.Top + bc.Height
                Else
                    bc.Top = spos + spac
                    spos = bc.Top + bc.Height
                End If
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceEvenV(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedVert(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            If MaxV <= MinV Or oc.Count <= 1 Then
                Exit Sub
            End If
            spac = CInt((MaxV - MinV) / (oc.Count - 1))
            For Each bc In oc
                cc += 1
                If cc = 1 Then
                    spos = bc.Top
                Else
                    bc.Top = spos + spac
                    spos = bc.Top
                End If
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceIncV(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedVert(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            If MaxV <= MinV Or oc.Count = 0 Then
                Exit Sub
            End If
            Dim spc As String = InputBox("Enter Increment Amount in Pixels", "Increase Spacing", "3")
            If IsNumeric(spc) Then
                spac = CInt(spc)
            Else
                MsgBox("Increment Abandoned")
            End If
            For Each bc In oc
                bc.Top = bc.Top + (cc * spac)
                cc += 1
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceDecV(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedVert(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            If MaxV <= MinV Or oc.Count = 0 Then
                Exit Sub
            End If
            Dim spc As String = InputBox("Enter Decrement Amount in Pixels", "Decrease Spacing", "3")
            If IsNumeric(spc) Then
                spac = CInt(spc)
            Else
                MsgBox("Decrement Abandoned")
            End If
            For Each bc In oc
                bc.Top = bc.Top - (cc * spac)
                cc += 1
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceFirstH(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedHorz(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            For Each bc In oc
                cc += 1
                If cc = 1 Then
                    spos = bc.Left + bc.Width
                ElseIf cc = 2 Then
                    spac = bc.Left - spos
                    spos = bc.Left + bc.Width
                Else
                    bc.Left = spos + spac
                    spos = bc.Left + bc.Width
                End If
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceEvenH(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedHorz(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            If MaxV <= MinV Or oc.Count <= 1 Then
                Exit Sub
            End If
            spac = CInt((MaxV - MinV) / (oc.Count - 1))
            For Each bc In oc
                cc += 1
                If cc = 1 Then
                    spos = bc.Left
                Else
                    bc.Left = spos + spac
                    spos = bc.Left
                End If
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceIncH(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedHorz(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            If MaxV <= MinV Or oc.Count = 0 Then
                Exit Sub
            End If
            Dim spc As String = InputBox("Enter Increment Amount in Pixels", "Increase Spacing", "3")
            If IsNumeric(spc) Then
                spac = CInt(spc)
            Else
                MsgBox("Increment Abandoned")
            End If
            For Each bc In oc
                bc.Left = bc.Left + (cc * spac)
                cc += 1
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SpaceDecH(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim MaxV As Integer
            Dim MinV As Integer
            Dim oc As Collection
            Dim bc As nbfBrowseCtrl
            If Not CheckinSect() Then
                Exit Sub
            End If
            oc = OrderSelectedHorz(MinV, MaxV)
            Dim cc As Integer = 0
            Dim spos = cc
            Dim spac As Integer
            If MaxV <= MinV Or oc.Count = 0 Then
                Exit Sub
            End If
            Dim spc As String = InputBox("Enter Decrement Amount in Pixels", "Decrease Spacing", "3")
            If IsNumeric(spc) Then
                spac = CInt(spc)
            Else
                MsgBox("Decrement Abandoned")
            End If
            For Each bc In oc
                bc.Left = bc.Left - (cc * spac)
                cc += 1
            Next
            Do While oc.Count > 0
                oc.Remove(1)
            Loop
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Function OrderSelectedVert(ByRef MinVal As Integer, ByRef MaxVal As Integer) As Collection
        Dim y_pos As Double = 999999999
        Dim y_posm As Double = 0
        Dim osc As New Collection
        Dim bc As nbfBrowseCtrl
        Dim bcCol As New nbfBrowseCtrls
        Dim cfnd As Boolean
        For Each bc In SelectedControls
            bc.OrderSet = False
            If bc.Top < y_pos Then
                y_pos = bc.Top
            End If
            If bc.Top > y_posm Then
                y_posm = bc.Top
            End If
        Next
        MinVal = y_pos
        MaxVal = y_posm
        Do
            cfnd = False
            y_pos = 999999999
            For Each bc In SelectedControls
                With bc
                    If Not .OrderSet Then
                        cfnd = True
                        If .Top < y_pos Then
                            y_pos = .Top
                        End If
                    End If
                End With
            Next
            If cfnd Then
                For Each bc In SelectedControls
                    With bc
                        If Not .OrderSet Then
                            If .Top = y_pos Then
                                osc.Add(bc)
                                .OrderSet = True
                            End If
                        End If
                    End With
                Next
            End If
        Loop While cfnd
        Return osc
    End Function
    Private Function OrderSelectedHorz(ByRef MinVal As Integer, ByRef MaxVal As Integer) As Collection
        Dim y_pos As Double = 999999999
        Dim y_posm As Double = 0
        Dim osc As New Collection
        Dim bc As nbfBrowseCtrl
        Dim bcCol As New nbfBrowseCtrls
        Dim cfnd As Boolean
        For Each bc In SelectedControls
            bc.OrderSet = False
            If bc.Left < y_pos Then
                y_pos = bc.Left
            End If
            If bc.Left > y_posm Then
                y_posm = bc.Left
            End If
        Next
        MinVal = y_pos
        MaxVal = y_posm
        Do
            cfnd = False
            y_pos = 999999999
            For Each bc In SelectedControls
                With bc
                    If Not .OrderSet Then
                        cfnd = True
                        If .Left < y_pos Then
                            y_pos = .Left
                        End If
                    End If
                End With
            Next
            If cfnd Then
                For Each bc In SelectedControls
                    With bc
                        If Not .OrderSet Then
                            If .Left = y_pos Then
                                osc.Add(bc)
                                .OrderSet = True
                            End If
                        End If
                    End With
                Next
            End If
        Loop While cfnd
        Return osc
    End Function
    Private Sub Form1_ResizeBegin(ByVal sender As Object, ByVal e As EventArgs) Handles Me.ResizeBegin
        inresize = True
    End Sub
    Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As EventArgs) Handles Me.ResizeEnd
        inresize = False
        Me.Refresh()
    End Sub
    Sub PaintForm(ByVal sender As Object, ByVal pevent As PaintEventArgs)
        Try
            If inresize Then Exit Sub
            If False Then 'Not pvShowSubReps Then
                MyBase.OnPaintBackground(pevent)
                Exit Sub
            End If
            'Copy the back buffer to the screen
            If Not _backBuffer Is Nothing Then
                ' Create rectangle for source image.
                'pevent.Graphics.FillRectangle(Brushes.WhiteSmoke, 0, 0, Me.Width, Me.Height)

                If x_offset > 0 Or y_offset > 0 Then

                    Dim srcRect As New Rectangle(x_offset, y_offset, _backBuffer.Width - x_offset, _backBuffer.Height - y_offset)
                    Dim units As GraphicsUnit = GraphicsUnit.Pixel

                    pevent.Graphics.DrawImage(_backBuffer, 0, 0, srcRect, units)

                    Exit Sub
                    'Dim fr_bm As New Bitmap(picImage.Image)
                    Dim to_bm As New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
                    Dim gr As Graphics = Graphics.FromImage(to_bm)

                    ' Get source and destination rectangles.
                    Dim to_rect As New Rectangle(0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height)

                    ' Draw from the source to the destination.
                    gr.DrawImage(_backBuffer, to_rect, srcRect, GraphicsUnit.Pixel)
                    gr.DrawRectangle(Pens.Red, to_rect)
                    'pevent.Graphics.DrawImageUnscaled(to_bm, 0, 0) ', srcRect, units)
                Else
                    pevent.Graphics.DrawImageUnscaled(_backBuffer, 0, 0) ', srcRect, units)
                End If
            End If
            If pvBrowseRep.BFInfo.BrowseStyle = "B" Then
                'DrawBrowserControls(pevent.Graphics)
            End If
        Catch ex As Exception
            'no Action
        End Try
    End Sub
    Sub RefreshDisplay()
        ResetBuffer()
        DrawBuffer()
        ts1.ContentPanel.Invalidate()
        'ts1.ContentPanel.BackgroundImage = _backBuffer
    End Sub
    Private Sub Redraw(ByVal g As Graphics)
        'Dim bbrush As New SolidBrush(System.Drawing.SystemColors.ControlLight)
        Dim bbrush As New SolidBrush(System.Drawing.Color.LightGray)
        g.FillRectangle(bbrush, g.ClipBounds)
        Dim rs As New nbfSQLRepSection
        Dim rt As Integer = TopBorder + 1
        For Each rs In Rep.RepSections
            With rs
                .FormPos = rt
                DrawPanel(rs, g)
                rt += spw + .SectionHeight
            End With
        Next
        'pvShowSubReps = False
        DispBorder(g)
    End Sub
    Protected Overrides Sub OnLayout(ByVal e As LayoutEventArgs)
        MyBase.OnLayout(e)
        Setoverspill()
        If Not vl Is Nothing Then
            vl.Height = Me.Height
        End If
        If Not hl Is Nothing Then
            hl.Width = Me.Width
        End If
        'Select Case Me.WindowState
        'Case FormWindowState.Normal
        'Try
        '        If Not pvBrowseRep Is Nothing Then
        'pvBrowseRep.BFInfo.Size = Me.Size
        'pvBrowseRep.BFInfo.Location = Me.Location
        'End If
        'Catch
        'End Try
        'End Select
    End Sub
    Private Sub DrawBuffer()
        Dim g As Graphics = Nothing
        Dim brush As SolidBrush = Nothing
        Try
            If _backBuffer Is Nothing Then
                Exit Sub
            End If
            g = Graphics.FromImage(_backBuffer)
            Dim bbrush As New SolidBrush(System.Drawing.Color.LightGray)
            g.FillRectangle(bbrush, g.ClipBounds)
            Dim rs As New nbfSQLRepSection
            Dim rt As Integer = TopBorder + 1
            For Each rs In Rep.RepSections
                With rs
                    .FormPos = rt
                    DrawPanel(rs, g)
                    rt += spw + .SectionHeight
                End With
            Next
            'pvShowSubReps = False
            DispBorder(g)
        Catch
        Finally
            If Not brush Is Nothing Then
                brush.Dispose()
            End If
            If Not g Is Nothing Then
                g.Dispose()
            End If
        End Try
    End Sub
    Sub CheckGraphSet()
        'If lg Is Nothing Then
        ' lg = Me.CreateGraphics()
        'End If
        If LineDrawPen Is Nothing Then
            LineDrawPen = New Pen(SI.FormForeColour, pvDefaultLineWidth)
            LineErasePen = New Pen(SI.FormBackColour, pvDefaultLineWidth)
            HighlightPen = New Pen(System.Drawing.SystemColors.Highlight, pvDefaultLineWidth)
            PlacePen = New Pen(System.Drawing.Color.Red, 1)
            ErasePlacePen = New Pen(SI.FormBackColour, 1)
        End If
    End Sub
    Private Sub FileCloseClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub
    Sub AddBrowseCtrl(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            'if Rep.SubItem then
            '    if Rep.ParentCtrl.SqlSources.Count = 0 then
            '        msgbox("No SQL Sources available on this form")
            '        exit Sub
            '    end if
            'else
            '    if pvBrowseRep.BFInfo.SqlSources.Count = 0 then
            '        msgbox("No SQL Sources available on this form")
            '        exit Sub
            '    end if
            'end if
            Dim sc As New nbfSqlSources
            Dim ssc As New nbfSqlSource
            Dim pCtrl As nbfBrowseCtrl
            For Each ssc In pvBrowseRep.BFInfo.SQLSources
                sc.Add(ssc)
            Next
            For Each ssc In Rep.SQLSources
                sc.Add(ssc)
            Next
            pCtrl = Rep.ParentCtrl
            Do While Not pCtrl Is Nothing
                For Each ssc In pCtrl.SQLSources
                    sc.Add(ssc)
                Next
                pCtrl = pCtrl.ParentCtrl
            Loop
            If sc.count = 0 Then
                MsgBox("No SQL Sources available on this form")
                Exit Sub
            End If
            sc.SetAllowNew(False)
            Dim mn As String = sc.GetType.Name 'pvBrowseRep.BFInfo.SqlSources.GetType.Name
            Dim ss As New nbfSelectSQLSource
            nbfBrowseHost.SetStyles(ss, pvAppFrmSI)

            ss.NbfGrid1.GridCaptionVisible = False
            ss.NbfGrid1.ColHeadersVisible = True
            ss.NbfGrid1.RowHeadersVisible = False
            ss.NbfGrid1.AllowEdit = False
            ss.NbfGrid1.AllowAdd = False

            Dim ncd As odGridControls.nbfGridColumn
            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "BrowseTableName"
            ncd.ColHeader = "Source"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "RepTitle"
            ncd.ColHeader = "Description"
            ncd.Width = 600
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)
            ss.NbfGrid1.AutoScaleColumnWidths = True
            ss.NbfGrid1.HorizontalScrollBar = False
            'ss.RadioButton1.enabled = false
            ss.RadioButton2.Checked = True

            ss.NbfGrid1.SourceObject = sc

            ss.ShowDialog()
            'if Rep.SubItem then
            '    Rep.ParentCtrl.SqlSources.SetAllowNew(true)
            'else
            '    pvBrowseRep.BFInfo.SQLSources.SetAllowNew(true)
            'end if
            If ss.Abandoned Then
                ss.NbfGrid1.ReleaseBinding()
                MsgBox("Selection Abandoned")
                Exit Sub
            End If
            Dim SqlSce As nbfSqlSource
            'if Rep.SubItem then
            SqlSce = sc.Item(ss.NbfGrid1.SelectedIndex)
            'else
            '    SqlSce = pvBrowseRep.BFInfo.SqlSources.Item(ss.DataGrid1.CurrentRowIndex)
            'end if
            If ss.RadioButton1.Checked Then
                'Single Column
                Dim cis As nbfSqlColInfos
                Dim ci As nbfSqlColInfo
                Dim hz As Boolean = False
                cis = GetSqlColumns(pvAppFrmSI, SqlSce, hz)
                If Not cis Is Nothing Then
                    If cis.count > 1 Then
                        AddCtrlBlock(cis, SqlSce.BrowseTableName, hz)
                    ElseIf cis.count = 1 Then
                        ci = cis.Item(0)
                        Dim bc As New nbfBrowseCtrl   'me)
                        bc.CtlType = "Field"
                        bc.SQLSource = SqlSce.BrowseTableName
                        bc.SQLColNumber = ci.ColPosition
                        bc.SQLColName = ci.ColName
                        bc.BackColor = SI.LabelBackColor
                        bc.BorderStyle = SI.LabelBorderStyle
                        bc.ForeColor = SI.LabelForeColor
                        bc.ParentCtrl = Rep
                        'bc.TextAlign = ci.ColJust
                        Select Case ci.ColJust
                            Case "R"
                                bc.TextAlign = Drawing.ContentAlignment.TopRight
                            Case "C"
                                bc.TextAlign = Drawing.ContentAlignment.TopCenter
                            Case Else
                                bc.TextAlign = Drawing.ContentAlignment.TopLeft
                        End Select
                        'bc.Parent = me
                        bc.Height = SI.StdTextBoxHeight
                        bc.Width = 50
                        bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                        bc.FontInfo.FontName = pvAppFrmSI.CtrlFont.Name
                        bc.FontInfo.FontSize = pvAppFrmSI.CtrlFont.Size
                        'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                        NewEditCtrl = bc
                        EditCtrlHeight = bc.Height
                        EditCtrlWidth = bc.Width
                        If True Then
                            DropCtrl.BackColor = System.Drawing.Color.Yellow
                            DropCtrl.Height = EditCtrlHeight
                            DropCtrl.Width = EditCtrlWidth
                            Select Case NewEditCtrl.TextAlign
                                Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                    DropCtrl.TextAlign = ContentAlignment.TopLeft
                                Case Else
                                    DropCtrl.TextAlign = ContentAlignment.TopRight
                            End Select
                            DropCtrl.Text = ""
                            DropCtrl.Visible = True
                            DropCtrl.BringToFront()
                            vl.Height = Me.Height
                            hl.Width = Me.Width
                            vl.Visible = True
                            vl.BringToFront()
                            hl.Visible = True
                            hl.BringToFront()
                        End If
                        InCtrlEdit = True
                        InLineEdit = False
                        InBoxEdit = False
                        CtrlEditType = "N"
                    End If
                End If
                'nbfBrowseCtrl
                'NewCtrl = new nbfSQLReportBrowserCtrls.SQLBrowseField
            Else
                'Grid or Report Selected
                Dim bc As nbfBrowseCtrl
                Dim subit As Boolean = True
                For Each ssc In pvBrowseRep.BFInfo.SQLSources
                    If ssc Is SqlSce Then
                        subit = False
                    End If
                Next
                If ss.RadioButton3.Checked Then
                    Dim rs As nbfSQLRepSection
                    For Each rs In Rep.RepSections
                        If rs.SectionType = "B" Then
                            bc = rs.AddRep(pvBrowseRep.BFInfo, Rep)
                            Exit For
                        End If
                    Next
                Else
                    bc = New nbfBrowseCtrl
                    bc.CtlType = "Grid"
                    bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                    'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                End If
                If subit Then
                    bc.SubItem = True
                End If
                bc.CanGrow = True
                bc.SQLSource = SqlSce.BrowseTableName
                bc.Height = 5 * SI.StdTextBoxHeight
                bc.Width = 150
                NewEditCtrl = bc
                EditCtrlHeight = bc.Height
                EditCtrlWidth = bc.Width
                If True Then
                    DropCtrl.BackColor = System.Drawing.Color.Yellow
                    DropCtrl.Height = EditCtrlHeight
                    DropCtrl.Width = EditCtrlWidth
                    DropCtrl.Text = ""
                    Select Case NewEditCtrl.TextAlign
                        Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                            DropCtrl.TextAlign = ContentAlignment.TopLeft
                        Case Else
                            DropCtrl.TextAlign = ContentAlignment.TopRight
                    End Select
                    DropCtrl.Visible = True
                    DropCtrl.BringToFront()
                    vl.Height = Me.Height
                    hl.Width = Me.Width
                    vl.Visible = True
                    vl.BringToFront()
                    hl.Visible = True
                    hl.BringToFront()
                End If
                InCtrlEdit = True
                InLineEdit = False
                InBoxEdit = False
                CtrlEditType = "N"
            End If
            ss.NbfGrid1.ReleaseBinding()
            ss = Nothing
            Do While sc.count > 0
                sc.RemoveAt(0)
            Loop
            pvBrowseRep.WriteLog("End AddBrrowseCtrl")
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Sub AddCtrlBlock(ByVal cis As nbfSqlColInfos, ByVal ssn As String, ByVal Horiz As Boolean)
        pvBoxCtrlBlock = True
        pvCtrlBlock = cis
        pvCtrlBlockSqlSce = ssn
        pvCtrlBlockHz = Horiz
        InBoxEdit = True
    End Sub
    Private Sub AddBlock(ByVal X As Integer, ByVal Y As Integer, ByVal Wd As Integer, ByVal Ht As Integer)
        Try
            Dim fi As New RepFontInfo
            fi.FontName = pvAppFrmSI.CtrlFont.Name
            fi.FontName = pvAppFrmSI.CtrlFont.SizeInPoints
            Dim nfnt As Font
            Dim cwd As Single
            Dim cnt As Integer
            If Not pvCtrlBlock.count > 0 Then
                Exit Sub
            End If
            nfnt = pvBrowseRep.GetRepFont(fi)
            Dim cht As Single = nfnt.GetHeight
            If Wd < 0 Then
                X = X - Wd
                Wd = Wd * -1
            End If
            If Ht < 0 Then
                Y = Y - Ht
                Ht = Ht * -1
            End If
            Dim rs As nbfSQLRepSection = GetSectionFromPoint(Y)
            If (Y + Ht) > (rs.FormPos + rs.SectionHeight) Then
                Ht = (rs.FormPos + rs.SectionHeight) - Y
            End If
            If pvCtrlBlockHz Then
                cwd = CInt(Wd / pvCtrlBlock.count)
                For cnt = 1 To pvCtrlBlock.count
                    Dim bc As New nbfBrowseCtrl   'me)
                    With pvCtrlBlock.Item(cnt - 1)
                        bc.Top = Y
                        bc.Left = X + CInt((cnt - 1) * cwd)
                        bc.Width = CInt(cwd * 0.95)
                        bc.Height = cht
                        bc.CtlType = "Field"
                        bc.SQLSource = pvCtrlBlockSqlSce
                        bc.SQLColNumber = .ColPosition
                        bc.SQLColName = .ColName
                        bc.BackColor = SI.LabelBackColor
                        bc.BorderStyle = SI.LabelBorderStyle
                        bc.ForeColor = SI.LabelForeColor
                        bc.FontInfo.FontName = pvAppFrmSI.CtrlFont.Name
                        bc.FontInfo.FontSize = pvAppFrmSI.CtrlFont.Size
                        'bc.TextAlign = ci.ColJust
                        Select Case .ColJust
                            Case "R"
                                bc.TextAlign = Drawing.ContentAlignment.TopRight
                            Case "C"
                                bc.TextAlign = Drawing.ContentAlignment.TopCenter
                            Case Else
                                bc.TextAlign = Drawing.ContentAlignment.TopLeft
                        End Select
                        'bc.Parent = me
                        bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                        'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                        AddFormCtrl(rs, bc)
                    End With
                Next
            Else
                cwd = CInt(Wd)
                Dim div As Integer
                If cht < Ht Then
                    Ht = Ht - cht
                    If pvCtrlBlock.count > 1 Then
                        div = pvCtrlBlock.count - 1
                    End If
                Else
                    div = pvCtrlBlock.count
                End If
                For cnt = 1 To pvCtrlBlock.count
                    Dim bc As New nbfBrowseCtrl   'me)
                    With pvCtrlBlock.Item(cnt - 1)
                        bc.Top = Y + CInt((cnt - 1) * (Ht / div))
                        bc.Left = X
                        bc.Width = cwd
                        bc.Height = cht
                        bc.CtlType = "Field"
                        bc.SQLSource = pvCtrlBlockSqlSce
                        bc.SQLColNumber = .ColPosition
                        bc.SQLColName = .ColName
                        bc.BackColor = SI.LabelBackColor
                        bc.BorderStyle = SI.LabelBorderStyle
                        bc.ForeColor = SI.LabelForeColor
                        bc.FontInfo.FontName = pvAppFrmSI.CtrlFont.Name
                        bc.FontInfo.FontSize = pvAppFrmSI.CtrlFont.Size
                        'bc.TextAlign = ci.ColJust
                        Select Case .ColJust
                            Case "R"
                                bc.TextAlign = Drawing.ContentAlignment.TopRight
                            Case "C"
                                bc.TextAlign = Drawing.ContentAlignment.TopCenter
                            Case Else
                                bc.TextAlign = Drawing.ContentAlignment.TopLeft
                        End Select
                        'bc.Parent = me
                        bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                        'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                        AddFormCtrl(rs, bc)
                    End With
                Next
            End If
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub AddBrowseSubCtrl(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            If Rep.SQLSources.count = 0 Then
                MsgBox("No SQL Sources available on this form")
                Exit Sub
            End If
            Dim mn As String = Rep.SQLSources.GetType.Name
            Dim ss As New nbfSelectSQLSource
            nbfBrowseHost.SetStyles(ss, pvAppFrmSI)

            ss.NbfGrid1.GridCaptionVisible = False
            ss.NbfGrid1.ColHeadersVisible = True
            ss.NbfGrid1.RowHeadersVisible = False
            ss.NbfGrid1.AllowEdit = False
            ss.NbfGrid1.AllowAdd = False

            Dim ncd As odGridControls.nbfGridColumn
            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "BrowseTableName"
            ncd.ColHeader = "Source"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "RepTitle"
            ncd.ColHeader = "Description"
            ncd.Width = 600
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)
            ss.NbfGrid1.AutoScaleColumnWidths = True
            ss.NbfGrid1.HorizontalScrollBar = False
            'ss.RadioButton1.enabled = false
            ss.RadioButton2.Checked = True

            ss.NbfGrid1.SourceObject = Rep.SQLSources
            ss.ShowDialog()

            If ss.Abandoned Then
                ss.NbfGrid1.ReleaseBinding()
                MsgBox("Selection Abandoned")
                Exit Sub
            End If
            Dim SqlSce As nbfSqlSource
            SqlSce = Rep.SQLSources.Item(ss.NbfGrid1.SelectedIndex)
            If ss.RadioButton1.Checked Then
                'Single Column
                Dim ci As nbfSqlColInfo
                ci = GetSqlColumn(pvAppFrmSI, SqlSce)
                If Not ci Is Nothing Then
                    Dim bc As New nbfBrowseCtrl   'me)
                    bc.CtlType = "Field"
                    bc.SQLSource = SqlSce.BrowseTableName
                    bc.SQLColNumber = ci.ColPosition
                    bc.SQLColName = ci.ColName
                    bc.BackColor = SI.LabelBackColor
                    bc.BorderStyle = SI.LabelBorderStyle
                    bc.ForeColor = SI.LabelForeColor
                    'bc.TextAlign = ci.ColJust
                    Select Case ci.ColJust
                        Case "R"
                            bc.TextAlign = Drawing.ContentAlignment.TopRight
                        Case "C"
                            bc.TextAlign = Drawing.ContentAlignment.TopCenter
                        Case Else
                            bc.TextAlign = Drawing.ContentAlignment.TopLeft
                    End Select
                    'bc.Parent = me
                    bc.Height = SI.StdTextBoxHeight
                    bc.Width = 200
                    bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                    bc.SubItem = True
                    bc.ParentCtrl = Rep
                    'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                    NewEditCtrl = bc
                    EditCtrlHeight = bc.Height
                    EditCtrlWidth = bc.Width
                    If True Then
                        DropCtrl.BackColor = System.Drawing.Color.Yellow
                        DropCtrl.Height = EditCtrlHeight
                        DropCtrl.Width = EditCtrlWidth
                        DropCtrl.Text = ""
                        Select Case NewEditCtrl.TextAlign
                            Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                DropCtrl.TextAlign = ContentAlignment.TopLeft
                            Case Else
                                DropCtrl.TextAlign = ContentAlignment.TopRight
                        End Select
                        DropCtrl.Visible = True
                        DropCtrl.BringToFront()
                        vl.Height = Me.Height
                        hl.Width = Me.Width
                        vl.Visible = True
                        vl.BringToFront()
                        hl.Visible = True
                        hl.BringToFront()
                    End If
                    InCtrlEdit = True
                    InLineEdit = False
                    InBoxEdit = False
                    CtrlEditType = "N"
                End If
                'nbfBrowseCtrl
                'NewCtrl = new nbfSQLReportBrowserCtrls.SQLBrowseField
            Else
                'Grid or Report Selected
                Dim bc As nbfBrowseCtrl
                If ss.RadioButton3.Checked Then
                    Dim rs As nbfSQLRepSection
                    For Each rs In Rep.RepSections
                        If rs.SectionType = "B" Then
                            bc = rs.AddRep(pvBrowseRep.BFInfo, Rep)
                            Exit For
                        End If
                    Next
                Else
                    bc = New nbfBrowseCtrl
                    bc.CtlType = "Grid"
                    bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                    'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                End If
                bc.SubItem = True
                bc.CanGrow = True
                bc.ParentCtrl = Rep
                bc.SQLSource = SqlSce.BrowseTableName
                bc.Height = 5 * SI.StdTextBoxHeight
                bc.Width = 200
                NewEditCtrl = bc
                EditCtrlHeight = bc.Height
                EditCtrlWidth = bc.Width
                If True Then
                    DropCtrl.BackColor = System.Drawing.Color.Yellow
                    DropCtrl.Height = EditCtrlHeight
                    DropCtrl.Width = EditCtrlWidth
                    DropCtrl.Text = ""
                    Select Case NewEditCtrl.TextAlign
                        Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                            DropCtrl.TextAlign = ContentAlignment.TopLeft
                        Case Else
                            DropCtrl.TextAlign = ContentAlignment.TopRight
                    End Select
                    DropCtrl.Visible = True
                    DropCtrl.BringToFront()
                    vl.Height = Me.Height
                    hl.Width = Me.Width
                    vl.Visible = True
                    vl.BringToFront()
                    hl.Visible = True
                    hl.BringToFront()
                End If
                InCtrlEdit = True
                InLineEdit = False
                InBoxEdit = False
                CtrlEditType = "N"
            End If
            ss.NbfGrid1.ReleaseBinding()
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Sub AddBrowseTotal(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim sc As New nbfSqlSources
            Dim ssc As New nbfSqlSource
            Dim pCtrl As nbfBrowseCtrl
            For Each ssc In pvBrowseRep.BFInfo.SQLSources
                sc.Add(ssc)
            Next
            For Each ssc In Rep.SQLSources
                sc.Add(ssc)
            Next
            pCtrl = Rep.ParentCtrl
            Do While Not pCtrl Is Nothing
                For Each ssc In pCtrl.SQLSources
                    sc.Add(ssc)
                Next
                pCtrl = pCtrl.ParentCtrl
            Loop
            If sc.count = 0 Then
                MsgBox("No SQL Sources available on this form")
                Exit Sub
            End If
            Dim mn As String = sc.GetType.Name
            Dim ss As New nbfSelectSQLSource
            nbfBrowseHost.SetStyles(ss, pvAppFrmSI)
            ss.RadioButton1.Checked = True
            ss.GroupBox1.Enabled = False

            ss.NbfGrid1.GridCaptionVisible = False
            ss.NbfGrid1.ColHeadersVisible = True
            ss.NbfGrid1.RowHeadersVisible = False
            ss.NbfGrid1.AllowEdit = False
            ss.NbfGrid1.AllowAdd = False

            Dim ncd As odGridControls.nbfGridColumn
            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "BrowseTableName"
            ncd.ColHeader = "Source"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "RepTitle"
            ncd.ColHeader = "Description"
            ncd.Width = 600
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)
            ss.NbfGrid1.AutoScaleColumnWidths = True
            ss.NbfGrid1.HorizontalScrollBar = False
            'ss.RadioButton1.enabled = false
            ss.RadioButton2.Checked = True

            ss.NbfGrid1.SourceObject = sc

            ss.ShowDialog()
            If ss.Abandoned Then
                ss.NbfGrid1.ReleaseBinding()
                MsgBox("Selection Abandoned")
                Exit Sub
            End If
            Dim SqlSce As nbfSqlSource
            SqlSce = sc.Item(ss.NbfGrid1.SelectedIndex)
            'Single Column
            Dim ci As nbfSqlColInfo
            ci = GetSqlColumn(pvAppFrmSI, SqlSce)
            If Not ci Is Nothing Then
                Dim bc As New nbfBrowseCtrl   'me)
                bc.CtlType = "Total"
                bc.SQLSource = SqlSce.BrowseTableName
                bc.SQLColNumber = ci.ColPosition
                bc.SQLColName = ci.ColName
                bc.BackColor = SI.LabelBackColor
                bc.BorderStyle = SI.LabelBorderStyle
                bc.ForeColor = SI.LabelForeColor
                bc.ParentCtrl = Rep
                'bc.TextAlign = ci.ColJust
                Select Case ci.ColJust
                    Case "R"
                        bc.TextAlign = Drawing.ContentAlignment.TopRight
                    Case "C"
                        bc.TextAlign = Drawing.ContentAlignment.TopCenter
                    Case Else
                        bc.TextAlign = Drawing.ContentAlignment.TopLeft
                End Select
                'bc.Parent = me
                bc.Height = SI.StdTextBoxHeight
                bc.Width = 150
                bc.FontInfo.FontName = pvAppFrmSI.CtrlFont.Name
                bc.FontInfo.FontSize = pvAppFrmSI.CtrlFont.Size
                bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
                NewEditCtrl = bc
                EditCtrlHeight = bc.Height
                EditCtrlWidth = bc.Width
                DropCtrl.BackColor = System.Drawing.Color.Yellow
                DropCtrl.Height = EditCtrlHeight
                DropCtrl.Width = EditCtrlWidth
                DropCtrl.Text = ""
                Select Case NewEditCtrl.TextAlign
                    Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                        DropCtrl.TextAlign = ContentAlignment.TopLeft
                    Case Else
                        DropCtrl.TextAlign = ContentAlignment.TopRight
                End Select
                DropCtrl.Visible = True
                DropCtrl.BringToFront()
                vl.Height = Me.Height
                hl.Width = Me.Width
                vl.Visible = True
                vl.BringToFront()
                hl.Visible = True
                hl.BringToFront()
                InCtrlEdit = True
                InLineEdit = False
                InBoxEdit = False
                CtrlEditType = "N"
            End If
            ss.NbfGrid1.ReleaseBinding()
            Do While sc.count > 0
                sc.RemoveAt(0)
            Loop
            'nbfBrowseCtrl
            'NewCtrl = new nbfSQLReportBrowserCtrls.SQLBrowseField
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Sub AddBrowseAmalgum(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim bcs As New BrowseTotalCtls
            Dim bc As nbfBrowseCtrl
            Dim rs As nbfSQLRepSection
            For Each rs In Rep.RepSections
                For Each bc In rs.SectionCtrls
                    If bc.CtlType = "Total" Then
                        bcs.Add(bc)
                    End If
                Next
            Next
            If bcs.count <= 0 Then
                MsgBox("No total controls on this report")
                Exit Sub
            End If
            Dim aa As New nbfAddAmalgum
            nbfBrowseHost.SetStyles(aa, pvAppFrmSI)
            aa.SI = pvAppFrmSI
            aa.bcs = bcs

            aa.NbfGrid1.GridCaptionVisible = False
            aa.NbfGrid1.ColHeadersVisible = True
            aa.NbfGrid1.RowHeadersVisible = False
            aa.NbfGrid1.AllowEdit = False
            aa.NbfGrid1.AllowAdd = False

            Dim ncd As odGridControls.nbfGridColumn
            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "SQLSource"
            ncd.ColHeader = "SQL Source"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            aa.NbfGrid1.Columns.Add(ncd)

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "SQLColNumber"
            ncd.ColHeader = "Column"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            aa.NbfGrid1.Columns.Add(ncd)

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "ReverseSign"
            ncd.ColHeader = "Rev (+/-)"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            aa.NbfGrid1.Columns.Add(ncd)

            aa.NbfGrid1.AutoScaleColumnWidths = True
            aa.NbfGrid1.HorizontalScrollBar = False
            aa.NbfGrid1.SourceObject = aa.bc.SubTotList

            aa.ShowDialog()
            If aa.abandoned Then
                Exit Sub
            End If
            bc = aa.bc
            bc.CtlType = "Amalgum"
            bc.BackColor = SI.LabelBackColor
            bc.BorderStyle = SI.LabelBorderStyle
            bc.ForeColor = SI.LabelForeColor
            bc.TextAlign = Drawing.ContentAlignment.TopRight
            bc.FontInfo.FontName = pvAppFrmSI.CtrlFont.Name
            bc.FontInfo.FontSize = pvAppFrmSI.CtrlFont.Size
            bc.Height = SI.StdTextBoxHeight
            bc.ParentCtrl = Rep
            bc.Width = 150
            bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
            Dim bc2 As nbfBrowseCtrl
            For Each bc2 In pvBrowseRep.BFInfo.SQLBrowseCtrls
                'debug.WriteLine(bc2.Name)
            Next
            'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
            NewEditCtrl = bc
            EditCtrlHeight = bc.Height
            EditCtrlWidth = bc.Width
            DropCtrl.BackColor = System.Drawing.Color.Yellow
            DropCtrl.Height = EditCtrlHeight
            DropCtrl.Width = EditCtrlWidth
            DropCtrl.Text = ""
            Select Case NewEditCtrl.TextAlign
                Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                    DropCtrl.TextAlign = ContentAlignment.TopLeft
                Case Else
                    DropCtrl.TextAlign = ContentAlignment.TopRight
            End Select
            DropCtrl.Visible = True
            DropCtrl.BringToFront()
            vl.Height = Me.Height
            hl.Width = Me.Width
            vl.Visible = True
            vl.BringToFront()
            hl.Visible = True
            hl.BringToFront()
            InCtrlEdit = True
            InLineEdit = False
            InBoxEdit = False
            CtrlEditType = "N"
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Sub AddLabel(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim cpt As String
            cpt = InputBox("Enter Caption for Label", "")
            If cpt = "" Then
                Exit Sub
            End If
            Dim bc As New nbfBrowseCtrl
            bc.CtlType = "Label"
            bc.Text = cpt
            bc.PriorPageText = cpt
            bc.FirstPageText = cpt
            bc.BackColor = SI.LabelBackColor
            bc.BorderStyle = SI.LabelBorderStyle
            bc.ForeColor = SI.LabelForeColor
            bc.ParentCtrl = Rep
            'bc.TextAlign = ci.ColJust
            Select Case "L"
                Case "R"
                    bc.TextAlign = Drawing.ContentAlignment.TopRight
                Case "C"
                    bc.TextAlign = Drawing.ContentAlignment.TopCenter
                Case Else
                    bc.TextAlign = Drawing.ContentAlignment.TopLeft
            End Select
            'bc.Parent = me
            bc.Height = SI.StdTextBoxHeight
            bc.Width = 50
            bc.FontInfo.FontName = pvAppFrmSI.LabelFont.Name
            bc.FontInfo.FontSize = pvAppFrmSI.LabelFont.Size
            bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
            'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
            NewEditCtrl = bc
            EditCtrlHeight = bc.Height
            EditCtrlWidth = bc.Width
            DropCtrl.BackColor = System.Drawing.Color.Yellow
            DropCtrl.Height = EditCtrlHeight
            DropCtrl.Width = EditCtrlWidth
            DropCtrl.Text = ""
            Select Case NewEditCtrl.TextAlign
                Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                    DropCtrl.TextAlign = ContentAlignment.TopLeft
                Case Else
                    DropCtrl.TextAlign = ContentAlignment.TopRight
            End Select
            DropCtrl.Visible = True
            DropCtrl.BringToFront()
            vl.Height = Me.Height
            hl.Width = Me.Width
            vl.Visible = True
            vl.BringToFront()
            hl.Visible = True
            hl.BringToFront()
            InCtrlEdit = True
            InLineEdit = False
            InBoxEdit = False
            CtrlEditType = "N"
            'nbfBrowseCtrl
            'NewCtrl = new nbfSQLReportBrowserCtrls.SQLBrowseField
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Sub AddLine(ByVal sender As Object, ByVal e As System.EventArgs)
        InLineEdit = True
        InBoxEdit = False
        KeepVertical = False
    End Sub
    Sub AddVLine(ByVal sender As Object, ByVal e As System.EventArgs)
        InLineEdit = True
        InBoxEdit = False
        KeepVertical = True
    End Sub
    Sub AddBox(ByVal sender As Object, ByVal e As System.EventArgs)
        InBoxEdit = True
    End Sub
    Sub AddPicture(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim ap As New nbfAddPict
            nbfBrowseHost.SetStyles(ap, pvAppFrmSI)
            nbfAddPict.AppDir = pvBrowseRep.AppPath
            ap.ShowDialog()
            If ap.Abandoned Then
                MsgBox("Operation Cancelled")
                Exit Sub
            End If
            Dim PicFileName As String = ""
            Dim SqlSceName As String = ""
            Dim SqlColNum As Integer = 0
            Dim SqlColName As String = ""
            If ap.RadioButton1.Checked Or ap.RadioButton2.Checked Then
                Dim sc As New nbfSqlSources
                Dim ssc As New nbfSqlSource
                Dim pCtrl As nbfBrowseCtrl
                For Each ssc In pvBrowseRep.BFInfo.SQLSources
                    sc.Add(ssc)
                Next
                For Each ssc In Rep.SQLSources
                    sc.Add(ssc)
                Next
                pCtrl = Rep.ParentCtrl
                Do While Not pCtrl Is Nothing
                    For Each ssc In pCtrl.SQLSources
                        sc.Add(ssc)
                    Next
                    pCtrl = pCtrl.ParentCtrl
                Loop
                If sc.count = 0 Then
                    MsgBox("No SQL Sources available on this form")
                    Exit Sub
                End If
                Dim ss As New nbfSelectSQLSource
                nbfBrowseHost.SetStyles(ss, pvAppFrmSI)
                ss.NbfGrid1.GridCaptionVisible = False
                ss.NbfGrid1.ColHeadersVisible = True
                ss.NbfGrid1.RowHeadersVisible = False
                ss.NbfGrid1.AllowEdit = False
                ss.NbfGrid1.AllowAdd = False
                ss.RadioButton2.Enabled = False
                ss.RadioButton3.Enabled = False

                Dim ncd As odGridControls.nbfGridColumn
                ncd = New odGridControls.nbfGridColumn
                ncd.PropertyName = "BrowseTableName"
                ncd.ColHeader = "Source"
                ncd.Width = 200
                ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
                ss.NbfGrid1.Columns.Add(ncd)

                ncd = New odGridControls.nbfGridColumn
                ncd.PropertyName = "RepTitle"
                ncd.ColHeader = "Description"
                ncd.Width = 600
                ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
                ss.NbfGrid1.Columns.Add(ncd)
                ss.NbfGrid1.AutoScaleColumnWidths = True
                ss.NbfGrid1.HorizontalScrollBar = False
                ss.RadioButton1.Checked = True
                ss.RadioButton2.Enabled = False
                ss.RadioButton3.Enabled = False

                ss.NbfGrid1.SourceObject = sc

                ss.ShowDialog()
                If ss.Abandoned Then
                    ss.NbfGrid1.ReleaseBinding()
                    MsgBox("Selection Abandoned")
                    Exit Sub
                End If
                Dim SqlSce As nbfSqlSource
                SqlSce = sc.Item(ss.NbfGrid1.SelectedIndex)
                'Single Column
                Dim ci As nbfSqlColInfo
                ci = GetSqlColumn(pvAppFrmSI, SqlSce)
                If Not ci Is Nothing Then
                    SqlSceName = SqlSce.BrowseTableName
                    SqlColNum = ci.ColPosition
                    SqlColName = ci.ColName
                Else
                    MsgBox("No Data Source Selected")
                    Exit Sub
                End If
                ss.NbfGrid1.ReleaseBinding()
                Do While sc.count > 0
                    sc.RemoveAt(0)
                Loop
            Else
                PicFileName = ap.TextBox1.Text
            End If
            Dim bc As New nbfBrowseCtrl
            bc.CtlType = "Image"
            If ap.CheckBox1.Checked Then
                bc.ImageType = "V"
            Else
                bc.ImageType = "B"
            End If
            'bc.ImageSetting = mid(cstr(ap.ComboBox1.SelectedItem),1,1)
            If ap.RadioButton1.Checked Then
                bc.SourceType = "N"
            ElseIf ap.RadioButton2.Checked Then
                bc.SourceType = "D"
            ElseIf ap.RadioButton3.Checked Then
                'bc.SourceType = "F"
                Try
                    Dim Img As Image
                    Img = Image.FromFile(PicFileName)
                    If Not Img Is Nothing Then
                        bc.SourceType = "E"
                        bc.ImageData = Img
                    Else
                        MsgBox("Error loading Image")
                        Exit Sub
                    End If
                    Img = Nothing
                Catch ex As Exception
                    MsgBox(ex.Message & " Error loading Image")
                    Exit Sub
                End Try
            End If
            If ap.CheckBox1.Checked Then
                bc.MaintainAspectRatio = True
            Else
                bc.MaintainAspectRatio = True
            End If
            If ap.CheckBox2.Checked Then
                bc.StretchDimension = "H"
            Else
                bc.StretchDimension = ""
            End If
            bc.SourceFile = PicFileName
            bc.SQLSource = SqlSceName
            bc.SQLColName = SqlColName
            bc.SQLColNumber = SqlColNum
            bc.Height = 5 * SI.StdTextBoxHeight
            bc.Width = 200
            bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
            'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
            NewEditCtrl = bc
            EditCtrlHeight = bc.Height
            EditCtrlWidth = bc.Width
            DropCtrl.BackColor = System.Drawing.Color.Yellow
            DropCtrl.Height = EditCtrlHeight
            DropCtrl.Width = EditCtrlWidth
            DropCtrl.Text = ""
            Select Case NewEditCtrl.TextAlign
                Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                    DropCtrl.TextAlign = ContentAlignment.TopLeft
                Case Else
                    DropCtrl.TextAlign = ContentAlignment.TopRight
            End Select
            DropCtrl.Visible = True
            DropCtrl.BringToFront()
            vl.Height = Me.Height
            hl.Width = Me.Width
            vl.Visible = True
            vl.BringToFront()
            hl.Visible = True
            hl.BringToFront()
            InCtrlEdit = True
            InLineEdit = False
            InBoxEdit = False
            CtrlEditType = "N"
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Private Sub SetHistOptions(ByVal Chart As nbfChart.nbfGraph)
        Chart.TopMargin = 40
        Chart.BottomMargin = 40
        Chart.LeftMargin = 40
        Chart.RightMargin = 40
        Chart.ShowLegend = False
        Chart.ShowTitle = False
        Chart.ShowXTitle = False
        Chart.ShowYTitle = False
        Chart.TitleOffset = 2
        Chart.YTitleOffset = 2
        Chart.XTitleOffset = 2
        Chart.LegendOffsetY = 40
        Chart.LegendOffsetX = 5
        Chart.LegendWidth = 80
    End Sub
    Private Sub SetPieOptions(ByVal Chart As nbfChart.nbfGraph)
        Chart.TopMargin = 20
        Chart.BottomMargin = 20
        Chart.LeftMargin = 40
        Chart.RightMargin = 40
        Chart.TitleOffset = 2
        Chart.LegendOffsetY = 40
        Chart.LegendOffsetX = 5
        Chart.LegendWidth = 80
    End Sub
    Sub AddChart(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim sc As New nbfSqlSources
            Dim ssc As New nbfSqlSource
            Dim pCtrl As nbfBrowseCtrl
            Dim SqlSceName As String = ""
            Dim SqlColNum As Integer = 0
            Dim SqlColName As String = ""
            For Each ssc In pvBrowseRep.BFInfo.SQLSources
                sc.Add(ssc)
            Next
            For Each ssc In Rep.SQLSources
                sc.Add(ssc)
            Next
            pCtrl = Rep.ParentCtrl
            Do While Not pCtrl Is Nothing
                For Each ssc In pCtrl.SQLSources
                    sc.Add(ssc)
                Next
                pCtrl = pCtrl.ParentCtrl
            Loop
            If sc.count = 0 Then
                MsgBox("No SQL Sources available on this form")
                Exit Sub
            End If
            Dim mn As String = pvBrowseRep.BFInfo.SQLSources.GetType.Name
            Dim ss As New nbfSelectChartSource
            nbfBrowseHost.SetStyles(ss, pvAppFrmSI)
            '#nbfBrowseHost.SetStyles(ss,pvAppFrmSI)        
            ss.NbfGrid1.GridCaptionVisible = False
            ss.NbfGrid1.ColHeadersVisible = True
            ss.NbfGrid1.RowHeadersVisible = False
            ss.NbfGrid1.AllowEdit = False
            ss.NbfGrid1.AllowAdd = False
            Dim ncd As odGridControls.nbfGridColumn
            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "BrowseTableName"
            ncd.ColHeader = "Source"
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)
            ncd = Nothing

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "RepTitle"
            ncd.ColHeader = "Description"
            ncd.Width = 600
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            ss.NbfGrid1.Columns.Add(ncd)
            ncd = Nothing
            ss.NbfGrid1.AutoScaleColumnWidths = True
            ss.NbfGrid1.HorizontalScrollBar = False
            ss.NbfGrid1.SourceObject = sc
            ss.ShowDialog()
            If ss.Abandoned Then
                ss.NbfGrid1.ReleaseBinding()
                Do While sc.count > 0
                    sc.RemoveAt(0)
                Loop
                ss.Close()
                ss.Dispose()
                ss = Nothing
                MsgBox("Selection Abandoned")
                Exit Sub
            End If
            Dim SqlSce As nbfSqlSource
            SqlSce = sc.Item(ss.NbfGrid1.SelectedIndex)
            ss.NbfGrid1.ReleaseBinding()
            Do While sc.count > 0
                sc.RemoveAt(0)
            Loop
            ss.Close()
            ss.Dispose()
            ss = Nothing

            Dim sch As New nbfSelectChartType
            sch.btnHistogram.Checked = True
            sch.ShowDialog()
            If sch.Abandoned Then
                sch.Close()
                sch.Dispose()
                sch = Nothing
                MsgBox("Chart Abandoned")
                Exit Sub
            End If
            Dim ct As nbfChart.GraphType
            If sch.btnHistogram.Checked Then
                ct = nbfChart.GraphType.Histogram
            ElseIf sch.btnLineGraph.Checked Then
                ct = nbfChart.GraphType.LineGraph
            Else
                ct = nbfChart.GraphType.PieChart
            End If
            sch.Close()
            sch.Dispose()
            sch = Nothing
            Dim bc As New nbfBrowseCtrl()
            SqlSceName = SqlSce.BrowseTableName
            bc.CtlType = "Chart"
            bc.SQLSource = SqlSceName
            bc.Height = 5 * SI.StdTextBoxHeight
            bc.Width = 200
            bc.Chart = New nbfChart.nbfGraph
            Select Case ct
                Case nbfChart.GraphType.Histogram
                    bc.Chart.GraphType = nbfChart.GraphType.Histogram
                    SetHistOptions(bc.Chart)
                Case nbfChart.GraphType.LineGraph
                    bc.Chart.GraphType = nbfChart.GraphType.LineGraph
                    SetHistOptions(bc.Chart)
                Case nbfChart.GraphType.PieChart
                    bc.Chart.GraphType = nbfChart.GraphType.PieChart
                    SetPieOptions(bc.Chart)
            End Select
            Dim ccnt As Integer = 0
            Dim scnt As Integer = 0
            For Each ci As nbfSqlColInfo In SqlSce.SqlColInfos
                If ccnt > 0 Then
                    Select Case ci.ColType
                        Case "I", "Z", "X", "M", "N"
                            scnt += 1
                    End Select
                End If
                ccnt += 1
            Next
            For gsicnt As Integer = 1 To scnt
                Dim sinfo As nbfChart.GraphSeriesInfo = New nbfChart.GraphSeriesInfo()
                sinfo.Colour = DefColour(gsicnt)
                sinfo.Description = "Series " + gsicnt.ToString()
                bc.Chart.GraphSeries.Add(sinfo)
                sinfo = Nothing
            Next
            Dim scopt As New nbfSelectChartOptions
            scopt.SetChartSizeLimits(pvBrowseRep.BFInfo.FormSize.Width, pvBrowseRep.BFInfo.FormSize.Height)
            scopt.BindObject = bc.Chart
            scopt.grdSeriesSettings.GridCaptionVisible = False
            scopt.grdSeriesSettings.ColHeadersVisible = True
            scopt.grdSeriesSettings.RowHeadersVisible = False
            scopt.grdSeriesSettings.AllowEdit = True
            scopt.grdSeriesSettings.AllowAdd = False

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "Description"
            ncd.ColHeader = "Description"
            ncd.Width = 600
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            scopt.grdSeriesSettings.Columns.Add(ncd)
            ncd = Nothing

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "ColourIdx"
            ncd.ColHeader = "Colour Ref"
            ncd.ShowSelectButton = True
            ncd.ReadOnlyColumn = True
            ncd.ShowAsColour = True
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            scopt.grdSeriesSettings.Columns.Add(ncd)
            ncd = Nothing

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "HistogramType"
            ncd.ColHeader = "HistogramType"
            ncd.Width = 400
            ncd.DropParameters.DropTypeCollection = True
            ncd.DropBox = True
            Dim lv As New odGridControls.LookUpValue
            lv.Code = "Stack"
            lv.Description = "Stacked Histogram"
            ncd.DropParameters.nbfCollection.Add(lv)
            lv = Nothing
            lv = New odGridControls.LookUpValue
            lv.Code = "Clustered"
            lv.Description = "Clustered Histogram"
            ncd.DropParameters.nbfCollection.Add(lv)
            lv = Nothing
            lv = New odGridControls.LookUpValue
            lv.Code = "Overlaid"
            lv.Description = "Overlaid Profile"
            ncd.DropParameters.nbfCollection.Add(lv)
            lv = Nothing
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            scopt.grdSeriesSettings.Columns.Add(ncd)
            ncd = Nothing

            scopt.grdSeriesSettings.AutoScaleColumnWidths = True
            scopt.grdSeriesSettings.HorizontalScrollBar = False
            scopt.grdSeriesSettings.SourceObject = bc.Chart.GraphSeries

            scopt.ShowDialog()
            If scopt.Abandoned Then
                bc = Nothing
                scopt.Close()
                scopt.Dispose()
                scopt = Nothing
                MsgBox("Chart Abandoned")
                Exit Sub
            End If
            bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
            'pvBrowseRep.BFInfo.SQLBrowseCtrls.Add(bc)
            NewEditCtrl = bc
            EditCtrlHeight = bc.Height
            EditCtrlWidth = bc.Width
            DropCtrl.BackColor = System.Drawing.Color.Azure
            DropCtrl.Height = EditCtrlHeight
            DropCtrl.Width = EditCtrlWidth
            DropCtrl.Text = ""
            Select Case NewEditCtrl.TextAlign
                Case ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
                    DropCtrl.TextAlign = ContentAlignment.TopLeft
                Case Else
                    DropCtrl.TextAlign = ContentAlignment.TopRight
            End Select
            DropCtrl.Visible = True
            DropCtrl.BringToFront()
            vl.Height = Me.Height
            hl.Width = Me.Width
            vl.Visible = True
            vl.BringToFront()
            hl.Visible = True
            hl.BringToFront()
            InCtrlEdit = True
            InLineEdit = False
            InBoxEdit = False
            CtrlEditType = "N"
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Sub EditChart(ByVal bc As nbfBrowseCtrl)
        Try
            Dim scopt As New nbfSelectChartOptions
            scopt.SetChartSizeLimits(pvBrowseRep.BFInfo.FormSize.Width, pvBrowseRep.BFInfo.FormSize.Height)
            scopt.BindObject = bc.Chart
            scopt.grdSeriesSettings.GridCaptionVisible = False
            scopt.grdSeriesSettings.ColHeadersVisible = True
            scopt.grdSeriesSettings.RowHeadersVisible = False
            scopt.grdSeriesSettings.AllowEdit = True
            scopt.grdSeriesSettings.AllowAdd = False

            Dim ncd As New odGridControls.nbfGridColumn
            ncd.PropertyName = "Description"
            ncd.ColHeader = "Description"
            ncd.Width = 600
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            scopt.grdSeriesSettings.Columns.Add(ncd)
            ncd = Nothing

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "ColourIdx"
            ncd.ColHeader = "Colour Ref"
            ncd.ShowSelectButton = True
            ncd.ReadOnlyColumn = True
            ncd.ShowAsColour = True
            ncd.Width = 200
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            scopt.grdSeriesSettings.Columns.Add(ncd)
            ncd = Nothing

            ncd = New odGridControls.nbfGridColumn
            ncd.PropertyName = "HistogramType"
            ncd.ColHeader = "HistogramType"
            ncd.Width = 400

            ncd.DropParameters.DropTypeCollection = True
            ncd.DropBox = True
            Dim lv As New odGridControls.LookUpValue
            lv.Code = "0"
            lv.Description = "Standard"
            ncd.DropParameters.nbfCollection.Add(lv)
            lv = Nothing
            lv = New odGridControls.LookUpValue
            lv.Code = "1"
            lv.Description = "Overlaid Line"
            ncd.DropParameters.nbfCollection.Add(lv)
            lv = Nothing
            lv = New odGridControls.LookUpValue
            lv.Code = "2"
            lv.Description = "Profile"
            ncd.DropParameters.nbfCollection.Add(lv)
            lv = Nothing
            ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
            scopt.grdSeriesSettings.Columns.Add(ncd)
            ncd = Nothing

            scopt.grdSeriesSettings.AutoScaleColumnWidths = True
            scopt.grdSeriesSettings.HorizontalScrollBar = False
            scopt.grdSeriesSettings.SourceObject = bc.Chart.GraphSeries

            scopt.ShowDialog()
            If scopt.Abandoned Then
                bc = Nothing
                scopt.Close()
                scopt.Dispose()
                scopt = Nothing
                MsgBox("Chart Abandoned")
                Exit Sub
            End If
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    End Sub
    Private Sub ShowCtrlMenu(ByVal bc As nbfBrowseCtrl, ByVal SelPoint As Point)
        If bc Is Nothing Then
            Exit Sub
        End If
        Select Case bc.CtlType
            Case "Report", "Chart"
                NewEditCtrl = bc
                RepMenuEdit.Visible = True
                RepMenuEditList.Visible = False
                ReportMenu.Show(Me, SetAsLoc(SelPoint))
            Case "Grid"
                NewEditCtrl = bc
                RepMenuEditList.Visible = True
                RepMenuEdit.Visible = False
                ReportMenu.Show(Me, SetAsLoc(SelPoint))
            Case "Line", "Box"
                'already catered for
            Case Else
                NewEditCtrl = bc
                CtrlContextMenu.Show(Me, SetAsLoc(SelPoint))
        End Select
    End Sub
    Private Sub EditCtrl(ByVal bc As nbfBrowseCtrl)
        Dim SelPoint As Point
        Dim rs As nbfSQLRepSection
        Dim bc2 As nbfBrowseCtrl
        Dim sbc As nbfBrowseCtrl
        Dim pt As Point
        Dim cfnd As Boolean = False
        Dim selFnd As Boolean = False
        If bc Is Nothing Then
            Exit Sub
        End If
        Select Case bc.CtlType
            Case "Report"
                EditRep()
            Case "xxGrid"
                Dim sqs As nbfSqlSource
                sqs = pvBrowseRep.GetSqSFromName(bc.SQLSource)
                If sqs Is Nothing Then
                    MsgBox("Sql Source Not Found")
                Else
                    Dim egd As New nbfEditRepGrid
                    nbfBrowseHost.SetStyles(egd, pvAppFrmSI)
                    egd.SI = pvAppFrmSI
                    egd.g = sqs
                    egd.bc = bc
                    egd.SetBinding()
                    egd.ShowDialog()
                End If
            Case "Field", "Total", "Amalgum", "Label", "Image", "Grid", "Chart"
                If SelectedControls.Count > 1 Then
                    For Each sbc In SelectedControls
                        If bc Is sbc Then
                            selFnd = True
                        End If
                    Next
                End If
                Dim ec As New nbfEdtCtrlProps
                ec.SI = pvAppFrmSI
                nbfBrowseHost.SetStyles(ec, pvAppFrmSI)
                'dim sbc as nbfBrowseCtrl
                'dim fx as Integer = 0
                'For Each sbc in pvBrowseRep.BFInfo.SQLBrowseCtrls
                '    if sbc is bc then
                '        exit for
                '    End If
                '    if pvBrowseRep.fofst(bc,sbc,fx) then
                '        exit for
                '    End If
                'Next        
                ec.lblPosPanel.Text = CStr(bc.Left) & "," & CStr(bc.Top)
                ec.lblPosForm.Text = CStr(bc.Left + EditXOffset)
                ec.lblPosRep.Text = Format(((bc.Left + EditXOffset) * pvBrowseRep.BFInfo.PageSize.Width / pvBrowseRep.BFInfo.FormSize.Width), "#.00")
                ec.txtWidth.Text = CStr(bc.Width)
                ec.txtHeight.Text = CStr(bc.Height)
                ec.lblType.Text = bc.CtlType
                ec.lblSource.Text = bc.SQLSource
                If selFnd Then
                    ec.lblFormat.Visible = True
                    ec.lblFormatDes.Visible = True
                    ec.lblDateFormat.Visible = True
                    ec.lblDateFormatDes.Visible = True
                    ec.lblFormat.Text = bc.ImageType
                    ec.lblDateFormat.Text = bc.DateFormat
                Else
                    Select Case bc.CtlType
                        Case "Field"
                            ec.lblFormat.Visible = True
                            ec.lblFormatDes.Visible = True
                            ec.lblDateFormat.Visible = True
                            ec.lblDateFormatDes.Visible = True
                            ec.lblFormat.Text = bc.ImageType
                            ec.lblDateFormat.Text = bc.DateFormat
                        Case "Total", "Amalgum"
                            ec.lblFormat.Visible = True
                            ec.lblFormatDes.Visible = True
                            ec.lblFormat.Text = bc.ImageType
                    End Select
                End If
                ec.lblFont.Font = pvBrowseRep.GetRepFont(bc.FontInfo)
                If bc.SQLColNumber > 0 Then
                    ec.lblSourceCol.Text = bc.SQLColName & " (" & CStr(bc.SQLColNumber) & ")"
                End If
                ec.bc = bc
                ec.ssl = pvBrowseRep.BFInfo.SQLSources
                ec.ComboBox1.Items.Add("Left Justified")
                ec.ComboBox1.Items.Add("Right Justified")
                ec.ComboBox1.Items.Add("Centre Justified")
                Select Case bc.TextAlign
                    Case ContentAlignment.BottomLeft, ContentAlignment.MiddleLeft, ContentAlignment.TopLeft
                        ec.ComboBox1.SelectedIndex = 0
                    Case ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
                        ec.ComboBox1.SelectedIndex = 1
                    Case ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter, ContentAlignment.TopCenter
                        ec.ComboBox1.SelectedIndex = 2
                End Select
                If selFnd Then
                    ec.ComboBox2.Visible = False
                    ec.NumericUpDown1.Visible = False
                    ec.chkAlignDS.Visible = False
                    ec.Button3.Visible = False
                Else
                    If bc.CtlType = "Field" Or bc.CtlType = "Total" Then
                        If bc.SQLSource = "" Then
                            MsgBox("This Field/Total has no associated SQL Source")
                            Exit Sub
                        End If
                        ec.ComboBox2.Items.Add(bc.SQLSource)
                        ec.ComboBox2.SelectedIndex = 0
                        ec.ComboBox2.Enabled = False
                    Else
                        Dim sqs As nbfSqlSource
                        Dim cidx As Integer = 0
                        Dim svidx As Integer = 0
                        For Each sqs In pvBrowseRep.BFInfo.SQLSources
                            ec.ComboBox2.Items.Add(sqs.BrowseTableName)
                            If Trim(UCase(sqs.BrowseTableName)) = Trim(UCase(bc.SQLSource)) Then
                                svidx = cidx
                            End If
                            cidx += 1
                        Next
                        ec.ComboBox2.SelectedIndex = svidx
                    End If
                    If bc.AlignWithCol > 0 Then
                        ec.NumericUpDown1.Value = bc.AlignWithCol
                        ec.chkAlignDS.Checked = True
                        ec.ComboBox2.Enabled = True
                        ec.NumericUpDown1.Enabled = True
                        ec.Button3.Enabled = True
                    Else
                        ec.chkAlignDS.Checked = False
                        ec.ComboBox2.Enabled = False
                        ec.NumericUpDown1.Enabled = False
                        ec.Button3.Enabled = False
                    End If
                End If
                ec.ComboBox3.Items.Add("All")
                ec.ComboBox3.Items.Add("Last Page Only")
                ec.ComboBox3.Items.Add("First Page Only")
                ec.ComboBox3.Items.Add("Intermediate Only")
                Select Case bc.ShowOnPages
                    Case "L"
                        ec.ComboBox3.SelectedIndex = 1
                    Case "F"
                        ec.ComboBox3.SelectedIndex = 2
                    Case "I"
                        ec.ComboBox3.SelectedIndex = 3
                    Case Else
                        ec.ComboBox3.SelectedIndex = 0
                End Select
                If selFnd Then
                    ec.CheckBox6.Visible = False
                    ec.CheckBox7.Visible = False
                    ec.txtDefault.Visible = False
                    ec.txtFirst.Visible = False
                    ec.txtPrior.Visible = False
                Else
                    If bc.CtlType = "Image" Then
                        ec.CheckBox6.Visible = True
                        ec.CheckBox7.Visible = True
                        ec.Label5.Visible = False
                        ec.Label6.Visible = False
                        ec.Label7.Visible = False
                        ec.txtDefault.Visible = False
                        ec.txtFirst.Visible = False
                        ec.txtPrior.Visible = False
                        If bc.MaintainAspectRatio Then
                            ec.CheckBox7.Checked = True
                        End If
                        If bc.StretchDimension = "W" Then
                            ec.CheckBox6.Checked = True
                        End If
                    Else
                        ec.CheckBox6.Visible = False
                        ec.CheckBox7.Visible = False
                        ec.txtDefault.Text = bc.Text
                        ec.txtFirst.Text = bc.FirstPageText
                        ec.txtPrior.Text = bc.PriorPageText
                    End If
                End If
                If bc.RepTopBorder Then
                    ec.CheckBox1.Checked = True
                End If
                If bc.RepBottomBorder Then
                    ec.CheckBox2.Checked = True
                End If
                If bc.RepRightBorder Then
                    ec.CheckBox3.Checked = True
                End If
                If bc.RepLeftBorder Then
                    ec.CheckBox4.Checked = True
                End If
                If bc.RepDoubleUnderline Then
                    ec.CheckBox5.Checked = True
                End If
                ec.CheckBox8.Checked = bc.MultiLine
                ec.CheckBox9.Checked = bc.CliptoBorders
                If selFnd Then
                    ec.SelCtrls = SelectedControls
                    ec.MultiEdit = True
                    ec.Label2.Visible = False
                    ec.Label3.Visible = False
                    ec.Label5.Visible = False
                    ec.Label6.Visible = False
                    ec.Label7.Visible = False
                    ec.chkSetAlign.Visible = True
                    ec.chkSetFont.Visible = True
                    ec.chkSetFont.Checked = True
                    ec.chkSetFormat.Visible = True
                    ec.chkSetHeight.Visible = True
                    ec.chkSetWidth.Visible = True
                    ec.chkSetShow.Visible = True
                    ec.chkSetBorders.Visible = True
                    ec.chkSetMulti.Visible = True
                    ec.ComboBox1.Enabled = False
                    ec.CheckBox1.Enabled = False
                    ec.CheckBox2.Enabled = False
                    ec.CheckBox3.Enabled = False
                    ec.CheckBox4.Enabled = False
                    ec.CheckBox5.Enabled = False
                    ec.CheckBox8.Enabled = False
                    ec.CheckBox9.Enabled = False
                    ec.txtWidth.Enabled = False
                    ec.txtHeight.Enabled = False
                    ec.ComboBox3.Enabled = False
                    ec.lblFormat.Enabled = False
                    ec.lblDateFormat.Enabled = False
                Else
                    ec.chkSetAlign.Visible = False
                    ec.chkSetFont.Visible = False
                    ec.chkSetFormat.Visible = False
                    ec.chkSetHeight.Visible = False
                    ec.chkSetWidth.Visible = False
                    ec.chkSetShow.Visible = False
                    ec.chkSetBorders.Visible = False
                    ec.chkSetMulti.Visible = False
                    ec.MultiEdit = False
                End If
                ec.ShowDialog()
        End Select
        RefreshDisplay()
    End Sub
    Private Sub EditRepProp(ByVal bc As nbfBrowseCtrl)
        Dim SelPoint As Point
        Dim rs As nbfSQLRepSection
        Dim bc2 As nbfBrowseCtrl
        Dim pt As Point
        Dim cfnd As Boolean = False
        If bc Is Nothing Then
            Exit Sub
        End If
        Dim ec As New nbfEdtCtrlProps
        ec.SI = pvAppFrmSI
        nbfBrowseHost.SetStyles(ec, pvAppFrmSI)
        ec.bc = bc
        ec.lblType.Text = bc.CtlType
        ec.lblSource.Text = bc.SQLSource
        If bc.SQLColNumber > 0 Then
            ec.lblSourceCol.Text = bc.SQLColName & " (" & CStr(bc.SQLColNumber) & ")"
        End If
        'dim sbc as nbfBrowseCtrl
        'dim fx as Integer = 0
        'For Each sbc in pvBrowseRep.BFInfo.SQLBrowseCtrls
        '    if sbc is bc then
        '        exit for
        '   End If
        '   if pvBrowseRep.fofst(bc,sbc,fx) then
        '        exit for
        '    End If
        'Next        
        ec.lblPosPanel.Text = CStr(bc.Left) & "," & CStr(bc.Top)
        ec.lblPosForm.Text = CStr(bc.Left + EditXOffset)
        ec.lblPosRep.Text = Format(((bc.Left + EditXOffset) * pvBrowseRep.BFInfo.PageSize.Width / pvBrowseRep.BFInfo.FormSize.Width), "#.00")
        ec.txtWidth.Text = CStr(bc.Width)
        ec.txtHeight.Text = CStr(bc.Height)
        ec.ComboBox1.Enabled = False
        ec.btnFont.Enabled = False
        ec.ComboBox2.Enabled = False
        ec.chkAlignDS.Enabled = False
        ec.NumericUpDown1.Enabled = False
        ec.Button3.Enabled = False
        ec.ComboBox3.Items.Add("All")
        ec.ComboBox3.Items.Add("Last Page Only")
        ec.ComboBox3.Items.Add("First Page Only")
        ec.ComboBox3.Items.Add("Intermediate Only")
        Select Case bc.ShowOnPages
            Case "L"
                ec.ComboBox3.SelectedIndex = 1
            Case "F"
                ec.ComboBox3.SelectedIndex = 2
            Case "I"
                ec.ComboBox3.SelectedIndex = 3
            Case Else
                ec.ComboBox3.SelectedIndex = 0
        End Select
        ec.CheckBox6.Visible = False
        ec.CheckBox7.Visible = False
        ec.txtDefault.Enabled = False
        ec.txtFirst.Enabled = False
        ec.txtPrior.Enabled = False
        If bc.RepTopBorder Then
            ec.CheckBox1.Checked = True
        End If
        If bc.RepBottomBorder Then
            ec.CheckBox2.Checked = True
        End If
        If bc.RepRightBorder Then
            ec.CheckBox3.Checked = True
        End If
        If bc.RepLeftBorder Then
            ec.CheckBox4.Checked = True
        End If
        If bc.RepDoubleUnderline Then
            ec.CheckBox5.Checked = True
        End If
        ec.CheckBox8.Enabled = False
        ec.CheckBox9.Enabled = False
        ec.CheckBox10.Enabled = True
        ec.CheckBox10.Checked = bc.CanGrow
        ec.CheckBox11.Checked = bc.ResetOnEachPage
        ec.ShowDialog()
        RefreshDisplay()
    End Sub
    Private Sub DeleteCtrl(ByVal sender As System.Object, ByVal e As System.EventArgs)
        DelCtrl()
        RefreshDisplay()
    End Sub
    Sub DelCtrl()
        If Not NewEditCtrl Is Nothing Then
            Dim bc As nbfBrowseCtrl
            Dim rs As nbfSQLRepSection
            Dim cf As Boolean = False
            Dim ci As Integer = 0
            Dim sbc As nbfBrowseCtrl
            For Each sbc In SelectedControls
                ci += 1
                If sbc Is NewEditCtrl Then
                    SelectedControls.Remove(ci)
                End If
            Next
            For Each rs In Rep.RepSections
                For Each bc In rs.SectionCtrls
                    If bc Is NewEditCtrl Then
                        rs.SectionCtrls.Remove(bc)
                        cf = True
                        Exit For
                    End If
                Next

                If cf Then Exit For
            Next
        End If
    End Sub
    Private Sub ResizeLine(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            Dim pvResizingOffset As Point
            pvResizingOffset.X = LeftBorder
            pvResizingOffset.Y = 0
            For Each rs As nbfSQLRepSection In Rep.RepSections
                For Each bc As nbfBrowseCtrl In rs.SectionCtrls
                    If bc Is NewEditCtrl Then
                        pvResizingOffset.Y = rs.FormPos
                    End If
                Next
            Next
            'start as if adding fresh line / box
            Dim newloc As Point
            newloc.X = NewEditCtrl.Location.X + pvResizingOffset.X
            newloc.Y = NewEditCtrl.Location.Y + pvResizingOffset.Y
            NewEditCtrl.Location = newloc
            DelCtrl()
            If NewEditCtrl.CtlType = "Line" Then
                If NewEditCtrl.Width = 0 Or NewEditCtrl.Height = 0 Then
                    KeepVertical = True
                End If
                CtrlEditType = "L"
            Else
                CtrlEditType = "B"
                'InLineEdit = True
            End If
            InCtrlEdit = True
        End If
    End Sub
    Private Sub MoveCtrl(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            Dim bc As nbfBrowseCtrl
            Dim rs As nbfSQLRepSection
            Dim cf As Boolean = False
            If NewEditCtrl.CtlType <> "Report" Then
                For Each rs In Rep.RepSections
                    For Each bc In rs.SectionCtrls
                        If bc Is NewEditCtrl Then
                            rs.SectionCtrls.Remove(bc)
                            cf = True
                            Exit For
                        End If
                    Next
                    If cf Then Exit For
                Next
                If bc Is Nothing Then
                    MsgBox("No control selected")
                    Exit Sub
                End If
                EditCtrlHeight = bc.Height
                EditCtrlWidth = bc.Width
            Else
                EditCtrlHeight = NewEditCtrl.Height
                EditCtrlWidth = NewEditCtrl.Width
            End If
            RefreshDisplay()
            If True Then
                DropCtrl.BackColor = System.Drawing.Color.Yellow
                DropCtrl.Height = EditCtrlHeight
                DropCtrl.Width = EditCtrlWidth
                DropCtrl.Text = ""
                Select Case NewEditCtrl.TextAlign
                    Case ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                        DropCtrl.TextAlign = ContentAlignment.TopLeft
                    Case Else
                        DropCtrl.TextAlign = ContentAlignment.TopRight
                End Select
                DropCtrl.Visible = True
                DropCtrl.BringToFront()
                vl.Height = Me.Height
                hl.Width = Me.Width
                vl.Visible = True
                vl.BringToFront()
                hl.Visible = True
                hl.BringToFront()
            End If
            InCtrlEdit = True
            InLineEdit = False
            InBoxEdit = False
            CtrlEditType = "M"
        End If
    End Sub
    Private Sub ResizeCtrl(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            CtrlEditType = "R"
            InLineEdit = False
            InCtrlEdit = True
        End If
    End Sub
    Private Sub ReqEditRepChtCtrl(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            If NewEditCtrl.CtlType = "Chart" Then
                EditChart(NewEditCtrl)
            Else
                EditCtrl(NewEditCtrl)
            End If
        End If
    End Sub
    Private Sub ReqEditCtrl(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            EditCtrl(NewEditCtrl)
        End If
    End Sub
    Private Sub ReqEditProp(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            If NewEditCtrl.CtlType = "Chart" Then
                EditCtrl(NewEditCtrl)
            Else
                EditRepProp(NewEditCtrl)
            End If
        End If
    End Sub
    Private Sub ReqEditListProp(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not NewEditCtrl Is Nothing Then
            If NewEditCtrl.CtlType = "Grid" Then
                Dim sqs As nbfSqlSource
                sqs = pvBrowseRep.GetSqSFromName(NewEditCtrl.SQLSource)
                If sqs Is Nothing Then
                    MsgBox("Sql Source Not Found")
                Else
                    Dim egd As New nbfEditRepGrid
                    nbfBrowseHost.SetStyles(egd, pvAppFrmSI)
                    egd.SI = pvAppFrmSI
                    egd.g = sqs
                    egd.bc = NewEditCtrl
                    egd.SetBinding()
                    egd.ShowDialog()
                End If
            End If
        End If
    End Sub
    Public Property SI() As nbfStyleInfo.AppStyle
        Get
            Return pvSI
        End Get
        Set(ByVal Value As nbfStyleInfo.AppStyle)
            pvSI = Value
        End Set
    End Property
    Public Property AppFrmSI() As nbfStyleInfo.AppStyle
        Get
            Return pvAppFrmSI
        End Get
        Set(ByVal Value As nbfStyleInfo.AppStyle)
            pvAppFrmSI = Value
        End Set
    End Property
    Sub GetScrFont(ByRef bc As nbfBrowseCtrl, ByVal c As Control)
        Dim ft As Font
        ft = pvBrowseRep.GetRepFont(bc.FontInfo, "D")
        c.Font = ft
    End Sub
    Public Sub SetDisplayStyle(ByVal DisStyle As String, Optional ByVal redraw As Boolean = False)
        Select Case DisStyle
            Case "D", "P"
                pvSI = New nbfStyleInfo.AppStyle
                'design
                'Do Form Font
                Dim bc As New nbfBrowseCtrl
                bc.FontInfo = pvBrowseRep.GetDefRepFont(False, 8)
                GetScrFont(bc, Me)
                pvSI.FormBackColour = System.Drawing.Color.Gainsboro
                pvSI.FormForeColour = System.Drawing.Color.Black
                pvSI.FormFont = Me.Font

                If DisStyle = "D" Then
                    pvSI.LabelBackColor = System.Drawing.Color.Gainsboro
                Else
                    pvSI.LabelBackColor = System.Drawing.Color.WhiteSmoke
                End If
                pvSI.LabelForeColor = pvSI.FormForeColour
                pvSI.LabelFont = pvSI.FormFont
                pvSI.LabelBorderStyle = BorderStyle.None

                pvSI.InfoLabelBackColor = pvSI.FormBackColour
                pvSI.InfoLabelForeColor = System.Drawing.Color.Black
                pvSI.InfoLabelFont = pvSI.FormFont
                pvSI.InfoLabelBorderStyle = BorderStyle.None

                If DisStyle = "D" Then
                    pvSI.CtrlBackColour = System.Drawing.Color.Gainsboro
                    pvSI.CtrlForeColour = System.Drawing.Color.Black
                    pvSI.CtrlFont = pvSI.FormFont
                    pvSI.CtrlBorderStyle = BorderStyle.None
                Else
                    pvSI.CtrlBackColour = System.Drawing.Color.WhiteSmoke
                    pvSI.CtrlForeColour = System.Drawing.Color.Black
                    pvSI.CtrlFont = pvSI.FormFont
                    pvSI.CtrlBorderStyle = BorderStyle.None
                End If

                pvSI.ButtonBackColor = System.Drawing.SystemColors.Control 'pvSi.CtrlBackColour
                pvSI.ButtonForeColor = System.Drawing.SystemColors.ControlText 'pvSi.CtrlForeColour
                pvSI.HeadButtonBackColor = pvSI.CtrlBackColour

                pvSI.GridAlternatingBackColor = System.Drawing.Color.WhiteSmoke
                pvSI.GridBackColor = System.Drawing.Color.WhiteSmoke
                pvSI.GridBackgroundColor = System.Drawing.Color.WhiteSmoke

                pvSI.GridCaptionBackColor = System.Drawing.Color.WhiteSmoke
                pvSI.GridCaptionFont = New System.Drawing.Font("Tahoma", 8, Drawing.FontStyle.Bold)
                pvSI.GridCaptionForecolor = System.Drawing.Color.Black

                pvSI.GridFont = pvSI.FormFont
                pvSI.GridForecolor = System.Drawing.Color.Black
                pvSI.GridLinecolor = System.Drawing.Color.Black
                pvSI.GridLineStyle = DataGridLineStyle.None

                pvSI.GridHeaderBackColor = System.Drawing.Color.WhiteSmoke
                pvSI.GridHeaderFont = pvSI.FormFont
                pvSI.GridHeaderForecolor = System.Drawing.Color.Black

                pvSI.GridSelectionBackColor = System.Drawing.Color.CadetBlue
                pvSI.GridSelectionForecolor = System.Drawing.Color.WhiteSmoke

                pvSI.GridLinkcolor = System.Drawing.Color.Teal

                pvSI.GridParentRowsBackColor = System.Drawing.Color.WhiteSmoke
                pvSI.GridParentRowsForecolor = System.Drawing.Color.Black

                pvSI.GridPreferredColumnWidth = 75
                pvSI.GridPreferredRowHeight = 16

                pvSI.StdTextBoxHeight = 18

                pvSI.GridFlatMode = True

                pvSI.GridBorderStyle = BorderStyle.FixedSingle

            Case "B"
                'browse
                pvSI = pvAppFrmSI
        End Select
        If redraw Then
            nbfBrowseHost.SetStyles(Me, pvSI)
        End If
    End Sub
    Sub SubCtrlMM(ByVal Sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim cp As Point
        cp.X = e.X
        cp.Y = e.Y
        'if DropCtrl.Visible = True then
        '    if cp.Y + DropCtrl.Height > sender.Height then
        '        cp.Y = sender.Height - DropCtrl.Height
        '        exit sub
        '    End If
        'End If
        cp = Sender.PointToScreen(cp)
        CtrlMM(cp)
    End Sub
    Sub SubCtrlMD(ByVal Sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim cp As Point
        cp.X = e.X + Sender.left
        cp.Y = e.Y + Sender.top
        CtrlMD(Sender, cp)
    End Sub
    Sub CtrlMM(ByVal MousePoint As Point)
        Dim lg As Graphics = Nothing
        Try
            If InSplitMove Then
                SplitMM(MousePoint)
                Exit Sub
            ElseIf InCtrlEdit Then
                Dim LineStart As Point
                Dim LineEnd As Point
                Dim ptCurrent As Point
                Dim FormMousePoint As Point
                Dim rc As Rectangle
                Dim lrc As Rectangle
                Dim ptp, pbt, plf, prt As Integer
                pvBrowseRep.WriteLog("In MM")
                FormMousePoint = ts1.ContentPanel.PointToClient(MousePoint)
                'FormMousePoint = PointToClient(MousePoint)
                Dim x_point As Single = FormMousePoint.X
                Dim y_point As Single = FormMousePoint.Y
                CheckGraphSet()
                lg = ts1.ContentPanel.CreateGraphics()
                If CtrlEditType = "L" Or CtrlEditType = "B" Then
                    ptCurrent.X = FormMousePoint.X
                    ptCurrent.Y = FormMousePoint.Y
                    'ptCurrent = me.PointToScreen(ptCurrent) 'NewEditCtrl.Parent.PointToScreen(ptCurrent)
                    'rc.X = ptCurrent.X
                    'rc.Y = ptCurrent.Y
                ElseIf CtrlEditType = "R" Then
                    If NewEditCtrl.TextAlign = ContentAlignment.BottomRight Or _
                     NewEditCtrl.TextAlign = ContentAlignment.MiddleRight Or _
                     NewEditCtrl.TextAlign = ContentAlignment.TopRight Then
                        ptCurrent.X = NewEditCtrl.FormRepPos.X + NewEditCtrl.Width - x_offset '+ Me.AutoScrollPosition.X
                        ptCurrent.Y = NewEditCtrl.FormRepPos.Y - y_offset '+ Me.AutoScrollPosition.Y
                    Else
                        ptCurrent.X = NewEditCtrl.FormRepPos.X - x_offset '+ Me.AutoScrollPosition.X
                        ptCurrent.Y = NewEditCtrl.FormRepPos.Y - y_offset '+ Me.AutoScrollPosition.Y
                    End If
                    If ptCurrent.X < 0 Then
                        ptCurrent.X = 0
                    End If
                    If ptCurrent.Y < 0 Then
                        ptCurrent.Y = 0
                    End If
                    ptCurrent = ts1.ContentPanel.PointToScreen(ptCurrent)
                    Dim cwid As Integer
                    If ptCurrent.X < MousePoint.X Then
                        cwid = MousePoint.X - ptCurrent.X
                    Else
                        cwid = ptCurrent.X - MousePoint.X
                    End If
                    If cwid < 3 Then cwid = 3
                    Dim cht As Integer
                    Select Case NewEditCtrl.CtlType
                        Case "Grid", "Image", "Drill", "Report", "Chart"
                            cht = MousePoint.Y - ptCurrent.Y
                            If cht < 10 Then cht = 10
                        Case Else
                            If NewEditCtrl.MultiLine Then
                                cht = MousePoint.Y - ptCurrent.Y
                                If cht < 10 Then cht = 10
                            Else
                                cht = NewEditCtrl.Size.Height
                            End If
                    End Select
                    If ptCurrent.X < MousePoint.X Then
                        rc.X = ptCurrent.X
                    Else
                        rc.X = MousePoint.X
                    End If
                    rc.Y = ptCurrent.Y
                    rc.Height = cht
                    rc.Width = cwid
                    'if PrvRect.Height <> -1 then
                    '    DrawResRect(PrvRect)
                    'End If
                    'DrawResRect(rc)                
                Else
                    If CtrlEditType = "N" And pvAutoAddLabels And pvNewPropDesc <> "" Then
                        If EditCtrlLabHeight = 0 Then
                            Dim snl As New nbfBrowseCtrl   'me) 'nbfLabel
                            snl.CtlType = "Label"
                            EditCtrlLabHeight = SI.StdTextBoxHeight 'snl.height
                            EditCtrlLabWidth = 100
                        End If
                        lrc.X = MousePoint.X
                        lrc.Y = MousePoint.Y
                        lrc.Height = EditCtrlLabHeight
                        If lrc.Width > EditCtrlWidth Then
                            lrc.Width = EditCtrlWidth
                        Else
                            lrc.Width = EditCtrlLabWidth
                        End If
                        rc.X = MousePoint.X
                        rc.Y = MousePoint.Y + lrc.Height
                        rc.Height = EditCtrlHeight
                        rc.Width = EditCtrlWidth
                    Else
                        rc.X = MousePoint.X
                        rc.Y = MousePoint.Y
                        rc.Height = EditCtrlHeight
                        rc.Width = EditCtrlWidth
                    End If
                End If
                If CtrlEditType = "L" Or CtrlEditType = "B" Then
                    Dim cwid As Integer
                    Dim cht As Integer
                    CheckGraphSet()
                    LineStart = SetAsLoc(NewEditCtrl.Location)
                    If PrvPoint.X <> -1 Then
                        If CtrlEditType = "L" Then
                            lg.DrawLine(LineErasePen, PrvStart, PrvPoint)
                        Else
                            cwid = PrvPoint.X - PrvStart.X
                            cht = PrvPoint.Y - PrvStart.Y
                            lg.DrawRectangle(LineErasePen, PrvStart.X, PrvStart.Y, cwid, cht)
                        End If
                    End If
                    If CtrlEditType = "L" Then
                        lg.DrawLine(LineDrawPen, LineStart, ptCurrent)
                    Else
                        cwid = ptCurrent.X - LineStart.X
                        cht = ptCurrent.Y - LineStart.Y
                        lg.DrawRectangle(LineDrawPen, LineStart.X, LineStart.Y, cwid, cht)
                    End If
                    PrvPoint.X = ptCurrent.X
                    PrvPoint.Y = ptCurrent.Y
                    PrvStart.X = LineStart.X
                    PrvStart.Y = LineStart.Y
                Else
                    If CtrlEditType = "R" Then 'or CtrlEditType = "M" then 'or CtrlEditType = "N" then
                        'me.Invalidate()
                        If PrvRect.Height <> -1 Then
                            ControlPaint.FillReversibleRectangle(PrvRect, RevRectBackColor)
                            If CtrlEditType = "N" And pvAutoAddLabels And pvNewPropDesc <> "" Then
                                ControlPaint.FillReversibleRectangle(PrvLabRect, RevRectBackColor)
                            End If
                        End If
                        ControlPaint.FillReversibleRectangle(rc, RevRectBackColor)
                        If CtrlEditType = "N" And pvAutoAddLabels And pvNewPropDesc <> "" Then
                            ControlPaint.FillReversibleRectangle(lrc, RevRectBackColor)
                        End If
                        PrvRect = rc
                        PrvLabRect = lrc
                    Else
                        DropCtrl.Height = EditCtrlHeight
                        'FormMousePoint = PointToClient(MousePoint)
                        Select Case NewEditCtrl.TextAlign
                            Case Drawing.ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                DropCtrl.Left = FormMousePoint.X - EditCtrlWidth
                            Case Else
                                DropCtrl.Left = FormMousePoint.X
                        End Select
                        DropCtrl.Top = FormMousePoint.Y
                        Dim rs As nbfSQLRepSection = GetSectionFromPoint(FormMousePoint.Y - Me.AutoScrollPosition.Y)
                        Dim y_text As String = ""
                        If rs Is Nothing Then
                            y_text = CStr(FormMousePoint.Y + y_offset)
                        Else
                            y_text = CStr(FormMousePoint.Y + y_offset - rs.FormPos)
                        End If
                        DropCtrl.Text = CStr(EditXOffset + DropCtrl.Left + x_offset - LeftBorder) & "," & y_text
                        vl.Left = FormMousePoint.X
                        hl.Top = FormMousePoint.Y
                        'debug.WriteLine("Top " & CStr(DropCtrl.Top))
                    End If
                End If
            End If
        Catch ex As Exception
            'MsgBox("MM Error " & ex.Message)
        Finally
            If Not lg Is Nothing Then
                lg.Dispose()
                lg = Nothing
            End If
        End Try
    End Sub
    Sub CtrlMD(ByVal pr As Object, ByVal cp As Point)
        Dim lg As Graphics = Nothing
        Try
            lg = ts1.ContentPanel.CreateGraphics()
            If PrvPlacePoint.X <> -1 Then
                Dim ptp, pbt, plf, prt As Integer
                CheckGraphSet()
                ptp = ((pvBrowseRep.BFInfo.MarginTop * pvBrowseRep.BFInfo.FormSize.Height) / pvBrowseRep.BFInfo.PageSize.Height) - y_offset
                pbt = (((pvBrowseRep.BFInfo.PageSize.Height - pvBrowseRep.BFInfo.MarginBottom) * pvBrowseRep.BFInfo.FormSize.Height) / pvBrowseRep.BFInfo.PageSize.Height) - y_offset
                plf = ((pvBrowseRep.BFInfo.MarginLeft * pvBrowseRep.BFInfo.FormSize.Width) / pvBrowseRep.BFInfo.PageSize.Width) - x_offset
                prt = (((pvBrowseRep.BFInfo.PageSize.Width - pvBrowseRep.BFInfo.MarginRight) * pvBrowseRep.BFInfo.FormSize.Width) / pvBrowseRep.BFInfo.PageSize.Width) - x_offset
                If PrvPlacePoint.X < plf Then
                    PrvPlacePoint.X = plf
                End If
                If PrvPlacePoint.X > prt Then
                    PrvPlacePoint.X = prt
                End If
                If PrvPlacePoint.Y < ptp Then
                    PrvPlacePoint.Y = ptp
                End If
                If PrvPlacePoint.Y > pbt Then
                    PrvPlacePoint.Y = pbt
                End If
                lg.DrawLine(ErasePlacePen, PrvPlacePoint.X, ptp, PrvPlacePoint.X, pbt)
                lg.DrawLine(ErasePlacePen, PrvPlacePoint.Y, plf, PrvPlacePoint.Y, prt)
                PrvPlacePoint.X = -1
            End If
            If InCtrlEdit Then
                InCtrlEdit = False
                InLineEdit = False
                InBoxEdit = False
                CtrlChanges = True
                CheckGraphSet()
                Dim x_point As Integer
                Dim y_point As Integer
                Dim npt As New Point
                Dim px_point As Integer
                Dim py_point As Integer
                y_point = cp.Y + y_offset
                x_point = cp.X + x_offset
                If CtrlEditType = "L" Or CtrlEditType = "B" Then
                    If pvBoxCtrlBlock Then
                        pvBoxCtrlBlock = False
                        NewEditCtrl.Height = y_point - NewEditCtrl.Location.Y
                        NewEditCtrl.Width = x_point - NewEditCtrl.Location.X
                        If NewEditCtrl.Height < 5 Or NewEditCtrl.Width < 5 Then
                            InCtrlEdit = True
                            InBoxEdit = True
                            pvBoxCtrlBlock = True
                            Exit Sub
                        End If
                        AddBlock(NewEditCtrl.Left, NewEditCtrl.Top, NewEditCtrl.Width, NewEditCtrl.Height)
                        NewEditCtrl = Nothing
                        Exit Sub
                    End If
                    Dim cwid As Integer
                    Dim cht As Integer
                    Dim LineStart As Point
                    LineStart = SetAsLoc(NewEditCtrl.Location)
                    If PrvPoint.X <> -1 Then
                        If CtrlEditType = "L" Then
                            lg.DrawLine(LineErasePen, PrvStart, PrvPoint)
                        Else
                            cwid = PrvPoint.X - PrvStart.X
                            cht = PrvPoint.Y - PrvStart.Y
                            lg.DrawRectangle(LineErasePen, PrvStart.X, PrvStart.Y, cwid, cht)
                        End If
                    End If
                    'if CtrlEditType = "L" then
                    '    lg.DrawLine(LineDrawPen,NewEditCtrl.Location.X,NewEditCtrl.Location.Y,e.X,e.Y)
                    'else
                    '    cwid = e.X - NewEditCtrl.Location.X
                    '    cht = e.Y - NewEditCtrl.Location.Y
                    '    lg.DrawRectangle(LineDrawPen,NewEditCtrl.Location.X,NewEditCtrl.Location.Y,cwid,cht)
                    'end if
                    NewEditCtrl.Height = y_point - NewEditCtrl.Location.Y
                    NewEditCtrl.Width = x_point - NewEditCtrl.Location.X
                    If CtrlEditType = "L" Then
                        If KeepVertical Then
                            If NewEditCtrl.Height > NewEditCtrl.Width Then
                                NewEditCtrl.Width = 0
                            Else
                                NewEditCtrl.Height = 0
                            End If
                        End If
                    End If
                    NewEditCtrl.LineWidth = pvDefaultLineWidth
                    NewEditCtrl.ForeColor = Me.ForeColor
                    NewEditCtrl.ParentCtrl = Rep
                    Dim rs As nbfSQLRepSection = GetSectionFromPoint(NewEditCtrl.Location.Y)
                    AddFormCtrl(rs, NewEditCtrl)
                    OrderControls()
                    PrvPoint.X = -1
                    RefreshDisplay()
                Else
                    If CtrlEditType = "R" Then
                        If pr Is NewEditCtrl Then
                            y_point = y_point + NewEditCtrl.Location.Y
                            x_point = x_point + NewEditCtrl.Location.X
                            pr = Me 'NewEditCtrl.Parent
                        ElseIf pr.GetType.Name = "TabPage" Then
                            If pr.parent Is NewEditCtrl Then
                                y_point = y_point + NewEditCtrl.Location.Y + pr.top
                                x_point = x_point + NewEditCtrl.Location.X + pr.left
                                pr = Me 'NewEditCtrl.Parent
                            End If
                        End If
                    End If
                    If (PrvRect.Height <> -1) Then
                        ControlPaint.FillReversibleRectangle(PrvRect, RevRectBackColor)
                        If CtrlEditType = "N" And pvAutoAddLabels And pvNewPropDesc <> "" Then
                            ControlPaint.FillReversibleRectangle(PrvLabRect, RevRectBackColor)
                        End If
                    Else
                        DropCtrl.Visible = False
                        vl.Visible = False
                        hl.Visible = False
                    End If
                    ' Set flags to know that there is no "previous" line to reverse.
                    PrvRect.Height = -1
                    Dim c As Control
                    If Not NewEditCtrl Is Nothing Then
                        Me.SuspendLayout()
                        'NewEditCtrl.BackColor = si.CtrlBackColour
                        'NewEditCtrl.ForeColor = si.CtrlBColour
                        If CtrlEditType = "R" Then
                            Dim x_of As Integer = NewEditCtrl.FormRepPos.X - NewEditCtrl.Location.X
                            Dim y_of As Integer = NewEditCtrl.FormRepPos.Y - NewEditCtrl.Location.Y
                            If NewEditCtrl.TextAlign = ContentAlignment.BottomRight Or _
                            NewEditCtrl.TextAlign = ContentAlignment.MiddleRight Or _
                            NewEditCtrl.TextAlign = ContentAlignment.TopRight Then
                                'reverse sides
                                px_point = x_point
                                x_point = NewEditCtrl.FormRepPos.X + NewEditCtrl.Width
                                npt.X = px_point
                                npt.Y = NewEditCtrl.FormRepPos.Y
                                NewEditCtrl.FormRepPos = npt
                            End If
                            If x_point < NewEditCtrl.FormRepPos.X Then
                                px_point = NewEditCtrl.FormRepPos.X
                                npt.X = x_point
                                npt.Y = NewEditCtrl.FormRepPos.Y
                                NewEditCtrl.FormRepPos = npt
                                x_point = px_point
                            End If
                            If y_point < NewEditCtrl.FormRepPos.Y Then
                                py_point = NewEditCtrl.FormRepPos.Y
                                npt.Y = y_point
                                npt.X = NewEditCtrl.FormRepPos.X
                                NewEditCtrl.FormRepPos = npt
                                y_point = py_point
                            End If
                            Dim cwid As Integer = x_point - NewEditCtrl.FormRepPos.X
                            If cwid < 3 Then
                                cwid = 3
                            ElseIf pvBrowseRep.BFInfo.SnapToNear Then
                                For Each c In pr.Controls
                                    If Not c Is NewEditCtrl Then
                                        If c.Left = NewEditCtrl.FormRepPos.X Then
                                            If c.Width > (cwid - pvBrowseRep.BFInfo.SnapRange) And c.Width < (cwid + pvBrowseRep.BFInfo.SnapRange) Then
                                                cwid = c.Width
                                                Exit For
                                            End If
                                        End If
                                    End If
                                Next
                            End If
                            NewEditCtrl.Width = cwid
                            Select Case NewEditCtrl.CtlType '.GetType.Name
                                Case "Grid", "Image", "Report", "Drill", "Chart"
                                    Dim cht As Integer = y_point - NewEditCtrl.FormRepPos.Y
                                    If cht < 5 Then cht = 5
                                    NewEditCtrl.Height = cht
                                Case Else
                                    If NewEditCtrl.MultiLine Then
                                        Dim cht As Integer = y_point - NewEditCtrl.FormRepPos.Y
                                        If cht < 5 Then cht = 5
                                        NewEditCtrl.Height = cht
                                    End If
                                    If cwid > 5 Then
                                        LastSetTBWidth = cwid
                                    End If
                            End Select
                            Dim newloc As Point
                            newloc.X = NewEditCtrl.FormRepPos.X - x_of
                            newloc.Y = NewEditCtrl.FormRepPos.Y - y_of
                            NewEditCtrl.Location = newloc
                            RefreshDisplay()
                            Exit Sub
                        Else
                            If CtrlEditType = "N" Then
                                'if InitTabIndex > 0 then
                                '    NewEditCtrl.TabIndex = InitTabIndex
                                '    InitTabIndex = InitTabIndex + 1
                                'End If
                                Console.WriteLine("New ctrl height " & CStr(NewEditCtrl.Height))
                                'pr.Controls.Add(NewEditCtrl)
                                Select Case NewEditCtrl.CtlType
                                    Case "Grid"
                                        'AddHandler NewEditCtrl.MouseMove, addressof SubCMouseMove
                                        'AddHandler NewEditCtrl.MouseDown, addressof CtrlMD
                                End Select
                                If pvAutoAddLabels And pvNewPropDesc <> "" Then
                                    Dim nl As New nbfBrowseCtrl   'me)
                                    nl.Name = "lblAA-" & pvNewPropName
                                    'nl.UserAdded = True
                                    'setctrlstyle(nl)
                                    nl.Text = pvNewPropDesc
                                    y_point = y_point + nl.Height
                                    If pvBrowseRep.BFInfo.SnapToNear Then
                                        For Each c In pr.Controls
                                            If Not c Is NewEditCtrl Then
                                                If y_point > (c.Top - pvBrowseRep.BFInfo.SnapRange) And y_point < (c.Top + pvBrowseRep.BFInfo.SnapRange) Then
                                                    y_point = c.Top
                                                    Exit For
                                                End If
                                            End If
                                        Next
                                    End If
                                    NewEditCtrl.Top = y_point
                                    Select Case NewEditCtrl.TextAlign
                                        Case Drawing.ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                            NewEditCtrl.Left = x_point - NewEditCtrl.Width
                                        Case Else
                                            NewEditCtrl.Left = x_point
                                    End Select
                                    y_point = y_point - nl.Height
                                    nl.Top = y_point
                                    Select Case NewEditCtrl.TextAlign
                                        Case Drawing.ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                            nl.Left = x_point - NewEditCtrl.Width
                                        Case Else
                                            nl.Left = x_point
                                    End Select
                                    pr.Controls.Add(nl)
                                Else
                                    NewEditCtrl.Top = y_point
                                    Select Case NewEditCtrl.TextAlign
                                        Case Drawing.ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                            NewEditCtrl.Left = x_point - NewEditCtrl.Width
                                        Case Else
                                            NewEditCtrl.Left = x_point
                                    End Select
                                End If
                            ElseIf CtrlEditType = "M" Then
                                NewEditCtrl.Top = y_point
                                Select Case NewEditCtrl.TextAlign
                                    Case Drawing.ContentAlignment.TopRight, ContentAlignment.BottomRight, ContentAlignment.MiddleRight
                                        NewEditCtrl.Left = x_point - NewEditCtrl.Width
                                    Case Else
                                        NewEditCtrl.Left = x_point
                                End Select
                                'if not NewEditCtrl.Parent is pr then
                                '    NewEditCtrl.Parent.Controls.Remove(NewEditCtrl)
                                '    pr.Controls.Add(NewEditCtrl)
                                'End If
                            End If
                        End If
                        pvAutoAddLabels = False
                        'NewEditCtrl.visible = true
                        Dim rs As nbfSQLRepSection = GetSectionFromPoint(y_point)
                        If NewEditCtrl.SubItem Then
                            If rs.SectionType <> "B" Then
                                rs = GetBodySection()
                                NewEditCtrl.Top = 0
                                NewEditCtrl.Left = 0
                            End If
                        End If
                        AddFormCtrl(rs, NewEditCtrl)
                        OrderControls()
                        Me.ResumeLayout()
                        NewEditCtrl = Nothing
                        'SetBindings
                        'me.BackColor = system.Drawing.Color.White
                        RefreshDisplay()
                        'dim nc as Control
                        'for each nc in me.Controls
                        '    nc.ForeColor = system.Drawing.Color.Black
                        '    'nc.Text = "TEST"
                        '    nc.BackColor = system.Drawing.Color.Yellow
                        '    msgbox("Ctrl " & nc.Name & " left " & cstr(nc.Left) & " top " & cstr(nc.Top) & " width " & nc.Width & " height " & (nc.Height))
                        '    nc.Refresh
                        'Next
                    End If
                End If
            ElseIf InLineEdit Then
                InLineEdit = False
                Dim bc As New nbfBrowseCtrl   'me)
                bc.CtlType = "Line"
                bc.ForeColor = SI.FormForeColour
                'bc.Location = 
                Dim pt As Point
                PrvPoint.X = -1
                pt.X = cp.X
                pt.Y = cp.Y
                pt = SelectLinePoint(pt)
                bc.Location = RevAsLoc(pt)
                bc.LineWidth = pvDefaultLineWidth
                bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                NewEditCtrl = bc
                InCtrlEdit = True
                CtrlEditType = "L"
                Exit Sub
            ElseIf InBoxEdit Then
                InBoxEdit = False
                Dim bc As New nbfBrowseCtrl   'me)
                bc.CtlType = "Box"
                bc.ForeColor = SI.FormForeColour
                'bc.Location = 
                Dim pt As Point
                PrvPoint.X = -1
                pt.X = cp.X
                pt.Y = cp.Y
                pt = SelectLinePoint(pt)
                bc.Location = RevAsLoc(pt)
                bc.LineWidth = pvDefaultLineWidth
                bc.Name = pvBrowseRep.BFInfo.GetCtrlName()
                NewEditCtrl = bc
                InCtrlEdit = True
                CtrlEditType = "B"
                Exit Sub
            End If
        Catch ex As Exception
            'MsgBox("MM Error " & ex.Message)
        Finally
            If Not lg Is Nothing Then
                lg.Dispose()
                lg = Nothing
            End If
        End Try
    End Sub
    Sub SplitMM(ByVal MousePoint As Point)
        Try
            Dim ScreenMousePoint As Point
            Dim FormMousePoint As Point
            Dim lw As Integer
            Dim rc As Rectangle
            Dim cpt As Point
            cpt.X = 0
            cpt.Y = SplitCeiling
            FormMousePoint = ts1.ContentPanel.PointToClient(MousePoint)
            'cpt = SetAsLoc(cpt)
            FormMousePoint.X = LeftBorder - x_offset
            If FormMousePoint.Y < cpt.Y Then
                FormMousePoint.Y = cpt.Y
            End If
            lw = Rep.Width
            If lw > Me.ClientSize.Width - FormMousePoint.X Then
                lw = Me.ClientSize.Width - FormMousePoint.X
            End If
            'FormMousePoint = ts1.ContentPanel.PointToClient(MousePoint)
            ScreenMousePoint = ts1.ContentPanel.PointToScreen(FormMousePoint)
            rc.X = ScreenMousePoint.X
            rc.Y = ScreenMousePoint.Y
            rc.Width = lw
            rc.Height = spw
            If PrvRect.Height <> -1 Then
                ControlPaint.FillReversibleRectangle(PrvRect, RevRectBackColor)
            End If
            ControlPaint.FillReversibleRectangle(rc, RevRectBackColor)
            PrvRect = rc
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub AddFormCtrl(ByRef rs As nbfSQLRepSection, ByRef bc As nbfBrowseCtrl)
        Try
            If rs Is Nothing Then
                Exit Sub
            End If
            bc.FlowThrough = False
            bc.Top = bc.Top - rs.FormPos
            bc.Left = bc.Left - LeftBorder
            If bc.Top < 0 Then
                bc.Top = 0
            End If
            If bc.Left < 0 Then
                bc.Left = 0
            End If
            If pvBrowseRep.BFInfo.SnapToNear Then
                Dim bc2 As nbfBrowseCtrl
                Dim rs2 As nbfSQLRepSection
                Dim LeftAligned As Boolean = False
                For Each bc2 In rs.SectionCtrls
                    If bc.Top > (bc2.Top - pvBrowseRep.BFInfo.SnapRange) And bc.Top < (bc2.Top + pvBrowseRep.BFInfo.SnapRange) Then
                        bc.Top = bc2.Top
                        Exit For
                    End If
                Next
                Select Case bc.TextAlign
                    Case ContentAlignment.BottomLeft, ContentAlignment.MiddleLeft, ContentAlignment.TopLeft
                        For Each rs2 In Rep.RepSections
                            For Each bc2 In rs2.SectionCtrls
                                Select Case bc2.TextAlign
                                    Case ContentAlignment.BottomLeft, ContentAlignment.MiddleLeft, ContentAlignment.TopLeft
                                        If bc.Left > (bc2.Left - pvBrowseRep.BFInfo.SnapRange) And bc.Left < (bc2.Left + pvBrowseRep.BFInfo.SnapRange) Then
                                            bc.Left = bc2.Left
                                            LeftAligned = True
                                            Exit For
                                        End If
                                End Select
                            Next
                            If LeftAligned Then Exit For
                        Next
                    Case ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
                        For Each rs2 In Rep.RepSections
                            For Each bc2 In rs2.SectionCtrls
                                Select Case bc2.TextAlign
                                    Case ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
                                        If (bc.Left + bc.Width) > ((bc2.Left + bc2.Width) - pvBrowseRep.BFInfo.SnapRange) And (bc.Left + bc.Width) < ((bc2.Left + bc2.Width) + pvBrowseRep.BFInfo.SnapRange) Then
                                            bc.Left = (bc2.Left + bc2.Width) - bc.Width
                                            LeftAligned = True
                                            Exit For
                                        End If
                                End Select
                            Next
                            If LeftAligned Then Exit For
                        Next
                End Select
            End If
            If bc.CtlType <> "Report" Then
                rs.SectionCtrls.Add(bc)
            Else
                If Not bc.SubItem Then
                    Dim rs2 As New nbfSQLRepSection
                    Dim bc2 As nbfBrowseCtrl
                    For Each rs2 In Rep.RepSections
                        For Each bc2 In rs2.SectionCtrls
                            If bc2 Is bc Then
                                Exit For
                            End If
                        Next
                        If bc2 Is bc Then
                            Exit For
                        End If
                    Next
                    If Not rs2 Is rs Then
                        rs2.SectionCtrls.Remove(bc)
                        rs.SectionCtrls.Add(bc)
                    End If
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub DispBorder(ByVal g As Graphics)
        Try
            If pvBrowseRep.BFInfo.PageSize.Height > 0 And pvBrowseRep.BFInfo.PageSize.Width > 0 Then
                If pvBrowseRep.BFInfo.FormSize.Height > 0 And pvBrowseRep.BFInfo.FormSize.Width > 0 Then
                    Dim bbrush As New SolidBrush(System.Drawing.Color.AntiqueWhite)
                    Dim fbrush As New SolidBrush(System.Drawing.Color.Black)
                    Dim TopMarg As New RectangleF
                    Dim x1, x2, x3, y1, y2, y3, rx1, rx2, rx3, ry1, ry2, ry3 As Single
                    Dim p As New Pen(System.Drawing.Color.Black, 1)
                    Dim rs As nbfSQLRepSection
                    Dim CtlHt As Integer = 0
                    For Each rs In Rep.RepSections
                        CtlHt += (rs.SectionHeight + spw)
                    Next
                    Dim tf As Font
                    Dim sft As Font
                    Dim TmHt As Single = CSng((TopBorder * pvBrowseRep.BFInfo.FormSize.Height) / pvBrowseRep.BFInfo.PageSize.Height)
                    Dim BmHt As Single = CSng((BottomBorder * pvBrowseRep.BFInfo.FormSize.Height) / pvBrowseRep.BFInfo.PageSize.Height)
                    Dim LmHt As Single = CSng((RightBorder * pvBrowseRep.BFInfo.FormSize.Width) / pvBrowseRep.BFInfo.PageSize.Width)
                    Dim RmHt As Single = CSng((RightBorder * pvBrowseRep.BFInfo.FormSize.Width) / pvBrowseRep.BFInfo.PageSize.Width)
                    TopMarg.X = LeftBorder + Me.AutoScrollPosition.X
                    TopMarg.Y = 0 + Me.AutoScrollPosition.Y
                    TopMarg.Width = Rep.Width
                    TopMarg.Height = TopBorder
                    g.FillRectangle(bbrush, TopMarg)
                    TopMarg.X = LeftBorder - RightBorder + Me.AutoScrollPosition.X
                    TopMarg.Y = TopBorder + Me.AutoScrollPosition.Y
                    TopMarg.Width = RightBorder
                    TopMarg.Height = CtlHt '- TmHt - BmHt
                    g.FillRectangle(bbrush, TopMarg)
                    TopMarg.X = LeftBorder + Me.AutoScrollPosition.X
                    TopMarg.Y = CtlHt + TopBorder + Me.AutoScrollPosition.Y
                    TopMarg.Width = Rep.Width
                    TopMarg.Height = BottomBorder
                    g.FillRectangle(bbrush, TopMarg)
                    TopMarg.X = Rep.Width + LeftBorder + Me.AutoScrollPosition.X
                    TopMarg.Y = TopBorder + Me.AutoScrollPosition.Y
                    TopMarg.Width = RightBorder
                    TopMarg.Height = CtlHt '- TmHt - BmHt
                    g.FillRectangle(bbrush, TopMarg)
                    Dim DefFontFamily As System.Drawing.FontFamily
                    Dim FontSizeInPixels As Integer = CInt(TopBorder / 3)
                    Dim gu As System.Drawing.GraphicsUnit = GraphicsUnit.Pixel
                    tf = New System.Drawing.Font(DefFontFamily.GenericSansSerif, 8)
                    sft = New Font(tf.FontFamily, FontSizeInPixels, gu)
                    y1 = 0 + Me.AutoScrollPosition.Y
                    y2 = TopBorder / 4 + Me.AutoScrollPosition.Y
                    ry1 = TopBorder + CtlHt + BottomBorder + Me.AutoScrollPosition.Y
                    ry2 = TopBorder + CtlHt + BottomBorder - (BottomBorder / 4) + Me.AutoScrollPosition.Y
                    Dim mmWid As Integer = CInt(Rep.Width * pvBrowseRep.BFInfo.PageSize.Width / pvBrowseRep.BFInfo.FormSize.Width)
                    Dim Cnt As Integer
                    If mmWid > 0 Then
                        For Cnt = 1 To mmWid 'Cint(pvBrowseRep.BFInfo.PageSize.Width)
                            If Cnt = mmWid Then
                                Dim xxp As Integer = 0
                            End If
                            x1 = LeftBorder + CSng((Cnt * pvBrowseRep.BFInfo.FormSize.Width) / pvBrowseRep.BFInfo.PageSize.Width) + Me.AutoScrollPosition.X
                            x2 = x1 'csng((cnt * pvBrowseRep.BFInfo.FormSize.Width)/pvBrowseRep.BFInfo.PageSize.Width) + me.AutoScrollPosition.X
                            rx1 = x1
                            rx2 = x2
                            If (Cnt + 1) Mod 10 = 0 And Cnt < CInt(pvBrowseRep.BFInfo.PageSize.Width) Then
                                x3 = x2 + (pvBrowseRep.BFInfo.FormSize.Width / pvBrowseRep.BFInfo.PageSize.Width)
                                rx3 = x3
                                y3 = ((TopBorder / 4) * 0.75) + Me.AutoScrollPosition.Y
                                ry3 = TopBorder + CtlHt + BottomBorder - ((BottomBorder / 4) * 3) + Me.AutoScrollPosition.Y
                                Dim r As New RectangleF(0, y3, x3, TopBorder)
                                Dim sf As New StringFormat
                                sf.Trimming = StringTrimming.None
                                sf.FormatFlags = sf.FormatFlags Or StringFormatFlags.NoWrap
                                sf.Alignment = StringAlignment.Far
                                sf.LineAlignment = StringAlignment.Near
                                g.DrawString(CStr(Cnt + 1), sft, fbrush, r, sf)

                                r = New RectangleF(0, ry3, rx3, BmHt)
                                sf = New StringFormat
                                sf.Trimming = StringTrimming.None
                                sf.FormatFlags = sf.FormatFlags Or StringFormatFlags.NoWrap
                                sf.Alignment = StringAlignment.Far
                                sf.LineAlignment = StringAlignment.Near
                                g.DrawString(CStr(Cnt + 1), sft, fbrush, r, sf)

                            End If
                            If Cnt Mod 10 = 0 Then
                                y3 = ((TopBorder / 4) * 3) + Me.AutoScrollPosition.Y
                                ry3 = TopBorder + CtlHt + BottomBorder - ((BottomBorder / 4) * 3) + Me.AutoScrollPosition.Y
                                g.DrawLine(p, x1, y1, x2, y3)
                                g.DrawLine(p, rx1, ry1, rx2, ry3)
                            ElseIf Cnt Mod 5 = 0 Then
                                y3 = ((TopBorder / 4) * 1.5) + Me.AutoScrollPosition.Y
                                ry3 = TopBorder + CtlHt + BottomBorder - ((BottomBorder / 4) * 1.5) + Me.AutoScrollPosition.Y
                                g.DrawLine(p, x1, y1, x2, y3)
                                g.DrawLine(p, rx1, ry1, rx2, ry3)
                            Else
                                g.DrawLine(p, x1, y1, x2, y2)
                                g.DrawLine(p, rx1, ry1, rx2, ry2)
                            End If
                        Next
                    End If
                    For Each rs In Rep.RepSections
                        Dim MaxCnt As Integer = CInt(rs.SectionHeight * pvBrowseRep.BFInfo.PageSize.Height / pvBrowseRep.BFInfo.FormSize.Height)
                        If MaxCnt > 0 Then
                            x1 = LeftBorder + Me.AutoScrollPosition.X
                            x2 = LeftBorder - (RightBorder / 4) + Me.AutoScrollPosition.X
                            rx1 = LeftBorder + Rep.Width + Me.AutoScrollPosition.X
                            rx2 = LeftBorder + Rep.Width + RightBorder / 4 + Me.AutoScrollPosition.X
                            For Cnt = 1 To MaxCnt
                                y1 = rs.FormPos + CSng((Cnt * pvBrowseRep.BFInfo.FormSize.Height) / pvBrowseRep.BFInfo.PageSize.Height) + Me.AutoScrollPosition.Y
                                y2 = y1
                                ry1 = y1
                                ry2 = y2
                                If (Cnt + 1) Mod 10 = 0 And Cnt < MaxCnt Then
                                    x3 = LeftBorder - RightBorder + Me.AutoScrollPosition.X
                                    rx3 = LeftBorder + Rep.Width + RightBorder - ((RightBorder / 4 * 1.65)) + Me.AutoScrollPosition.X
                                    y3 = y1 + (pvBrowseRep.BFInfo.FormSize.Height / pvBrowseRep.BFInfo.PageSize.Height)
                                    ry3 = y3
                                    Dim r As New RectangleF(x3, 0, x3 + RightBorder, y3)
                                    Dim sf As New StringFormat
                                    sf.Trimming = StringTrimming.None
                                    sf.FormatFlags = sf.FormatFlags Or StringFormatFlags.NoWrap
                                    sf.Alignment = StringAlignment.Near
                                    sf.LineAlignment = StringAlignment.Far
                                    g.DrawString(CStr(Cnt + 1), sft, fbrush, r, sf)

                                    rx3 = LeftBorder + Rep.Width + RightBorder + Me.AutoScrollPosition.X

                                    r = New RectangleF(0, 0, rx3, ry3)
                                    sf = New StringFormat
                                    sf.Trimming = StringTrimming.None
                                    sf.FormatFlags = sf.FormatFlags Or StringFormatFlags.NoWrap
                                    sf.Alignment = StringAlignment.Far
                                    sf.LineAlignment = StringAlignment.Far
                                    g.DrawString(CStr(Cnt + 1), sft, fbrush, r, sf)
                                End If
                                If Cnt Mod 10 = 0 Then
                                    x3 = LeftBorder - (RightBorder / 4 * 3) + Me.AutoScrollPosition.X
                                    rx3 = LeftBorder + Rep.Width + ((RightBorder / 4) * 3) + Me.AutoScrollPosition.X
                                    g.DrawLine(p, x1, y1, x3, y2)
                                    g.DrawLine(p, rx1, ry1, rx3, ry2)
                                ElseIf Cnt Mod 5 = 0 Then
                                    x3 = LeftBorder - (RightBorder / 4 * 1.5) + Me.AutoScrollPosition.X
                                    rx3 = LeftBorder + Rep.Width + ((RightBorder / 4) * 1.5) + Me.AutoScrollPosition.X
                                    g.DrawLine(p, x1, y1, x3, y2)
                                    g.DrawLine(p, rx1, ry1, rx3, ry2)
                                Else
                                    g.DrawLine(p, x1, y1, x2, y2)
                                    g.DrawLine(p, rx1, ry1, rx2, ry2)
                                End If
                            Next
                        End If
                    Next
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Function GetSectionFromPoint(ByVal y_point As Integer) As nbfSQLRepSection
        Dim rs As nbfSQLRepSection
        For Each rs In Rep.RepSections
            If rs.FormPos <= y_point And (rs.FormPos + rs.SectionHeight) > y_point Then
                Return rs
            End If
        Next
        Return Nothing
    End Function
    Function GetBodySection() As nbfSQLRepSection
        Dim rs As nbfSQLRepSection
        For Each rs In Rep.RepSections
            If rs.SectionType = "B" Then
                Return rs
            End If
        Next
        Return Nothing
    End Function
    Function SetAsLoc(ByVal InPt As Point) As Point
        Dim np As New Point
        np.X = InPt.X - x_offset
        np.Y = InPt.Y - y_offset
        Return np
    End Function
    Function RevAsLoc(ByVal InPt As Point) As Point
        Dim np As New Point
        np.X = InPt.X + x_offset
        np.Y = InPt.Y + y_offset
        Return np
    End Function
    Sub BindCtrl(ByVal c As Control)
        Dim SqlSce As nbfSqlSource
        Dim dq As nbfDB.nbfDBQuery
        Dim dsi As DataSourceInfo
        Dim ci As nbfSqlColInfo
        Dim cval As String
        Dim dsn As String
        Dim clnum As Integer
        Dim cnm As String = c.GetType.Name
        Dim bc As nbfBrowseCtrl
        Select Case cnm
            Case "SQLBrowseField", "SQLBrowseImage"
                Try
                    If cnm = "SQLBrowseImage" Then
                        If CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SourceType = "F" Then
                            CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SetImage()
                            Exit Sub
                        End If
                        clnum = CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SQlColumn
                        dsn = CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SQlSource
                    Else
                        clnum = CType(c, nbfSQLReportBrowserCtrls.SQLBrowseField).SQLColNumber
                        dsn = CType(c, nbfSQLReportBrowserCtrls.SQLBrowseField).SQLSource
                    End If
                    cval = pvBrowseRep.GetSqlValue(dsn, clnum)
                    If cnm = "SQLBrowseImage" Then
                        If InStr(cval, "\") = 0 Then
                            cval = pvBrowseRep.AppPath & "\" & cval
                        End If
                        CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SourceFile = cval
                        CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SetImage()
                    Else
                        c.Text = cval
                    End If
                Catch
                    If cnm = "SQLBrowseImage" Then
                        CType(c, nbfSQLReportBrowserCtrls.SQLBrowseImage).SourceFile = ""
                    Else
                        c.Text = ""
                    End If
                End Try
            Case "SQLBrowseGrid", "SQLBrowseTotal"
                Dim dtbl As DataTable
                Dim dtfnd As Boolean = False
                Dim SqsName As String
                If cnm = "SQLBrowseGrid" Then
                    SqsName = CType(c, nbfSQLReportBrowserCtrls.SQLBrowseGrid).SQLSource
                Else
                    SqsName = CType(c, nbfSQLReportBrowserCtrls.SQLBrowseTotal).SQLSource
                End If
                For Each dsi In pvBrowseRep.DataSourceList
                    If dsi.DataSourceName = SqsName Then
                        'if dsi.dtb is nothing then
                        '    For Each SqlSce in pvBrowseRep.BFInfo.SQLSources
                        '        if dsi.DataSourceName = SqlSce.BrowseTableName then
                        '            'dtbl = pvBrowseRep.CreateDTFromSqlSource(SqlSce)
                        '            'dsi.dtb = dtbl
                        '            exit for
                        '        end if
                        '    Next
                        'End If
                        dtfnd = True
                        If cnm = "SQLBrowseGrid" Then
                            SqlSce = pvBrowseRep.GetSqSFromName(CType(c, nbfSQLReportBrowserCtrls.SQLBrowseGrid).SQLSource)
                            CType(c, nbfSQLReportBrowserCtrls.SQLBrowseGrid).SetDataBinding(pvDBC, pvBrowseRep, pvAppFrmSI, SqlSce)
                        ElseIf cnm = "SQLBrowseTotal" Then
                            SqlSce = pvBrowseRep.GetSqSFromName(CType(c, nbfSQLReportBrowserCtrls.SQLBrowseTotal).SQLSource)
                            For Each ci In SqlSce.SqlColInfos
                                If CType(c, nbfSQLReportBrowserCtrls.SQLBrowseTotal).SQLColNumber = ci.ColPosition Then
                                    CType(c, nbfSQLReportBrowserCtrls.SQLBrowseTotal).Text = CStr(ci.RunningGrandTotal)
                                    Exit For
                                End If
                            Next
                        End If
                        Exit For
                    End If
                Next
                If Not dtfnd Then
                    For Each SqlSce In pvBrowseRep.BFInfo.SQLSources
                        If SqlSce.BrowseTableName = SqsName Then
                            If cnm = "SQLBrowseGrid" Then
                                CType(c, nbfSQLReportBrowserCtrls.SQLBrowseGrid).SetDataBinding(pvDBC, pvBrowseRep, pvAppFrmSI, SqlSce)
                            End If
                            dsi = New DataSourceInfo
                            dsi.DataSourceName = SqlSce.BrowseTableName
                            'dsi.dtb = dtbl
                            If cnm = "SQLBrowseTotal" Then
                                If Not SqlSce.TotSet Then
                                    pvBrowseRep.SetSqsTots(SqlSce)
                                End If
                                For Each ci In SqlSce.SqlColInfos
                                    If CType(c, nbfSQLReportBrowserCtrls.SQLBrowseTotal).SQLColNumber = ci.ColPosition Then
                                        CType(c, nbfSQLReportBrowserCtrls.SQLBrowseTotal).Text = CStr(ci.RunningGrandTotal)
                                        Exit For
                                    End If
                                Next
                            End If
                            pvBrowseRep.DataSourceList.Add(dsi)
                            Exit For
                        End If
                    Next SqlSce
                End If
            Case "SQLBrowseAmalgum"
                Dim sti As nbfSubTotItem
                Dim av As Decimal = 0
                For Each bc In pvBrowseRep.BFInfo.SQLBrowseCtrls
                    If bc.Name = c.Name Then
                        For Each sti In bc.SubTotList
                            For Each SqlSce In pvBrowseRep.BFInfo.SQLSources
                                For Each ci In SqlSce.SqlColInfos
                                    If ci.ColPosition = sti.SQLColNumber Then
                                        av += ci.RunningGrandTotal
                                    End If
                                Next
                            Next
                        Next
                    End If
                Next
                c.Text = CStr(av)
        End Select
    End Sub
    Sub SetGridAlign(ByVal bc As nbfBrowseCtrl, ByVal c As Control)
        Try
            If bc.AlignWithCol > 0 And bc.SQLSource <> "" Then
                Dim tc As Control
                Dim ts As DataGridTableStyle
                Dim cl As DataGridColumnStyle
                Dim lpos As Integer
                Dim rpos As Integer
                Dim ccnt As Integer
                For Each tc In Me.Controls
                    'debug.WriteLine(tc.GetType.Name)
                    Select Case tc.GetType.Name
                        Case "SQLBrowseGrid"
                            If CType(tc, nbfSQLReportBrowserCtrls.SQLBrowseGrid).SQLSource = bc.SQLSource Then
                                Try
                                    c.Left = CType(tc, nbfSQLReportBrowserCtrls.SQLBrowseGrid).Columns.Item(bc.AlignWithCol).Offset
                                    c.Width = CType(tc, nbfSQLReportBrowserCtrls.SQLBrowseGrid).Columns.Item(bc.AlignWithCol).Width
                                    Dim pt As Point
                                    pt.X = c.Left
                                    pt.Y = c.Top
                                    pt = RevAsLoc(pt)
                                    bc.Location = pt
                                    bc.Width = c.Width
                                Catch ex As Exception
                                    '
                                End Try
                            End If
                    End Select
                Next
            End If
        Catch
            'no action
        End Try
    End Sub
    Sub DrawLine(ByVal bc As nbfBrowseCtrl, ByVal p As Pen)
        Dim lg As Graphics = Nothing
        Try
            CheckGraphSet()
            lg = Me.CreateGraphics()
            Dim lc As Point = SetAsLoc(bc.Location)
            If p Is Nothing Then
                lg.DrawLine(LineDrawPen, lc.X, lc.Y, lc.X + bc.Width, lc.Y + bc.Height)
            Else
                lg.DrawLine(p, lc.X, lc.Y, lc.X + bc.Width, lc.Y + bc.Height)
            End If
        Catch ex As Exception
            'MsgBox("MM Error " & ex.Message)
        Finally
            If Not lg Is Nothing Then
                lg.Dispose()
                lg = Nothing
            End If
        End Try
    End Sub
    Sub DrawBox(ByVal bc As nbfBrowseCtrl, ByVal p As Pen)
        Dim lg As Graphics = Nothing
        Try
            CheckGraphSet()
            lg = Me.CreateGraphics()
            Dim lc As Point = SetAsLoc(bc.Location)
            If p Is Nothing Then
                lg.DrawRectangle(LineDrawPen, lc.X, lc.Y, bc.Width, bc.Height)
            Else
                lg.DrawRectangle(p, lc.X, lc.Y, bc.Width, bc.Height)
            End If
        Catch ex As Exception
            'MsgBox("MM Error " & ex.Message)
        Finally
            If Not lg Is Nothing Then
                lg.Dispose()
                lg = Nothing
            End If
        End Try
    End Sub
    Sub DrawRep(ByVal bc As nbfBrowseCtrl)
        Dim lg As Graphics = Nothing
        Try
            CheckGraphSet()
            lg = Me.CreateGraphics()
            Dim lc As Point = SetAsLoc(bc.Location)
            lg.DrawRectangle(HighlightPen, lc.X, lc.Y, bc.Width, bc.Height)
        Catch ex As Exception
            'MsgBox("MM Error " & ex.Message)
        Finally
            If Not lg Is Nothing Then
                lg.Dispose()
                lg = Nothing
            End If
        End Try
    End Sub
    Private Function CheckLineSelected(ByVal SelPoint As Point, ByVal lstart_x As Integer, ByVal lstart_y As Integer, ByVal l_width As Single, ByVal l_height As Integer) As Boolean
        Dim hit_range As Integer = 3
        Dim lend_x As Integer
        Dim lend_y As Integer
        Dim start_x As Integer
        Dim start_y As Integer
        Dim end_x As Integer
        Dim end_y As Integer
        Dim mid_y As Integer
        Dim Sel_x As Integer
        Dim Sel_y As Integer
        Dim SlopeUp As Boolean = True
        Dim Selected As Boolean
        If l_width < 0 Then
            lstart_x = lstart_x + l_width
            l_width = (-1) * l_width
            If l_height > 0 Then
                SlopeUp = False
            End If
        End If
        If l_height < 0 Then
            lstart_y = lstart_y + l_height
            l_height = (-1) * l_height
            If l_width > 0 Then
                SlopeUp = False
            End If
        End If
        start_x = lstart_x - hit_range
        end_x = lstart_x + l_width + hit_range
        lend_x = lstart_x + l_width
        start_y = lstart_y - hit_range
        end_y = lstart_y + l_height + hit_range
        lend_y = lstart_y + l_height
        If start_x < SelPoint.X And end_x > SelPoint.X And start_y < SelPoint.Y And end_y > SelPoint.Y Then
            If SelPoint.X < lstart_x Then
                Sel_x = lstart_x
            ElseIf SelPoint.X > lend_x Then
                Sel_x = lend_x
            Else
                Sel_x = SelPoint.X
            End If
            If SelPoint.Y < lstart_y Then
                Sel_y = lstart_y
            ElseIf SelPoint.Y > lend_y Then
                Sel_y = lend_y
            Else
                Sel_y = SelPoint.Y
            End If
            If (lend_x - lstart_x) = 0 Or (lend_y - lstart_y) = 0 Then
                If Sel_y >= start_y And Sel_y <= end_y Then
                    Return True
                End If
            Else
                If SlopeUp Then
                    mid_y = lstart_y + CInt(((Sel_x - lstart_x) * (lend_y - lstart_y)) / (lend_x - lstart_x))
                Else
                    mid_y = lend_y - CInt(((Sel_x - lstart_x) * (lend_y - lstart_y)) / (lend_x - lstart_x))
                End If
                If Sel_y >= (mid_y - hit_range) And Sel_y <= (mid_y + hit_range) Then
                    Return True
                End If
            End If
        End If
        Return False
    End Function
    Private Function SelectLinePoint(ByVal e As Point) As Point
        Dim RetPoint As New Point
        Dim bc As nbfBrowseCtrl
        Dim hit_range As Integer = 3
        Dim lstart_x As Integer
        Dim lstart_y As Integer
        Dim lend_x As Integer
        Dim lend_y As Integer
        Dim start_x As Integer
        Dim start_y As Integer
        Dim end_x As Integer
        Dim end_y As Integer
        Dim mid_y As Integer
        Dim Sel_x As Integer
        Dim Sel_y As Integer
        Dim Selected As Boolean
        RetPoint.X = e.X
        RetPoint.Y = e.Y
        RetPoint = SetAsLoc(RetPoint)
        Selected = False
        For Each bc In pvBrowseRep.BFInfo.SQLBrowseCtrls
            Select Case bc.CtlType
                Case "Line"
                    If bc.Size.Width >= 0 Then
                        start_x = bc.Location.X - hit_range
                        end_x = bc.Location.X + bc.Size.Width + hit_range
                        lstart_x = bc.Location.X
                        lend_x = bc.Location.X + bc.Size.Width
                    Else
                        start_x = bc.Location.X + bc.Size.Width - hit_range
                        end_x = bc.Location.X + hit_range
                        lstart_x = bc.Location.X + bc.Size.Width
                        lend_x = bc.Location.X
                    End If
                    If bc.Size.Height >= 0 Then
                        start_y = bc.Location.Y - hit_range
                        end_y = bc.Location.Y + bc.Size.Height + hit_range
                        lstart_y = bc.Location.Y
                        lend_y = bc.Location.Y + bc.Size.Height
                    Else
                        start_y = bc.Location.Y + bc.Size.Height - hit_range
                        end_y = bc.Location.Y + hit_range
                        lstart_y = bc.Location.Y + bc.Size.Height
                        lend_y = bc.Location.Y
                    End If
                    If start_x < e.X And end_x > e.X Then
                        If e.X < lstart_x Then
                            Sel_x = lstart_x
                        ElseIf e.X > lend_x Then
                            Sel_x = lend_x
                        Else
                            Sel_x = e.X
                        End If
                        If start_y < e.Y And end_y > e.Y Then
                            If e.Y < lstart_y Then
                                Sel_y = lstart_y
                            ElseIf e.Y > lend_y Then
                                Sel_y = lend_y
                            Else
                                Sel_y = e.Y
                            End If
                        End If
                        If (lend_x - lstart_x) = 0 Then
                            If Sel_y >= start_y And Sel_y <= end_y Then
                                Sel_x = lstart_x
                                Selected = True
                            End If
                        ElseIf (lend_y - lstart_y) = 0 Then
                            If Sel_y >= start_y And Sel_y <= end_y Then
                                Sel_y = lstart_y
                                Selected = True
                            End If
                        Else
                            mid_y = lstart_y + CInt(((Sel_x - lstart_x) * (lend_y - lstart_y)) / (lend_x - lstart_x))
                            If Sel_y >= (mid_y - hit_range) And Sel_y <= (mid_y + hit_range) Then
                                Sel_y = mid_y
                                Selected = True
                            End If
                        End If
                        If Selected Then
                            If (lstart_x - hit_range) < Sel_x And (lstart_x + hit_range) > Sel_x Then
                                Sel_x = lstart_x
                            ElseIf (lend_x - hit_range) < Sel_x And (lend_x + hit_range) > Sel_x Then
                                Sel_x = lend_x
                            End If
                            If (lstart_y - hit_range) < Sel_y And (lstart_y + hit_range) > Sel_y Then
                                Sel_y = lstart_y
                            ElseIf (lend_y - hit_range) < Sel_y And (lend_y + hit_range) > Sel_y Then
                                Sel_y = lend_y
                            End If
                            RetPoint.X = Sel_x
                            RetPoint.Y = Sel_y
                            Return RevAsLoc(RetPoint)
                        End If
                    End If
            End Select
        Next
        Return RevAsLoc(RetPoint)
    End Function
    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseMove(e)
        Dim ptCurrent As Point
        ptCurrent.X = e.X
        ptCurrent.Y = e.Y
        If InSplitMove Then
            SplitMM(ptCurrent)
        Else
            'convert to screen
            If Not (CtrlEditType = "L" Or CtrlEditType = "B" Or CtrlEditType = "P" Or CtrlEditType = "D") Then
                ptCurrent = PointToScreen(ptCurrent)
            End If
            CtrlMM(ptCurrent)
        End If
    End Sub
    Sub MainPanelMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        OnMouseDown(e)
        Exit Sub

        Dim cp As Point
        MyBase.OnMouseDown(e)
        If e.Button = MouseButtons.Right Then
            FormRtClick(e)
            Exit Sub
        ElseIf InCtrlEdit = False And InLineEdit = False And InBoxEdit = False Then
            FormLeftClick(e)
            Exit Sub
        End If
        cp.X = e.X
        cp.Y = e.Y
        CtrlMD(ts1.ContentPanel, cp)
    End Sub
    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim cp As Point
        MyBase.OnMouseDown(e)
        If InSplitMove Then
            SplitMoveEnd(e)
            Exit Sub
        End If
        If PrvPlacePoint.X = -1 And Not InCtrlEdit Then
            If e.Button = MouseButtons.Right Then
                FormRtClick(e)
            Else
                FormLeftClick(e)
            End If
        Else
            cp.X = e.X
            cp.Y = e.Y
            CtrlMD(ts1.ContentPanel, cp)
        End If
    End Sub
    Private Sub FormLeftClick(ByVal e As System.Windows.Forms.MouseEventArgs)
        Try
            Dim bc As nbfBrowseCtrl
            Dim hit_range As Integer = 3
            Dim lstart_x As Integer
            Dim lstart_y As Integer
            Dim lend_x As Integer
            Dim lend_y As Integer
            Dim start_x As Integer
            Dim start_y As Integer
            Dim end_x As Integer
            Dim end_y As Integer
            Dim mid_y As Integer
            Dim Sel_x As Integer
            Dim Sel_y As Integer
            Dim Selected As Boolean
            If InCtrlEdit Or InSplitMove Then
                Exit Sub
            End If
            Dim SelPoint As New Point
            Dim SecLoc As Point
            Dim SelFnd As Boolean = False
            SelPoint.X = e.X
            SelPoint.Y = e.Y
            If InLineEdit Or InBoxEdit Then
                CtrlMD(Me, SelPoint)
                Exit Sub
            End If
            SelPoint = RevAsLoc(SelPoint)
            SecLoc.X = SelPoint.X - LeftBorder
            Dim rs As New nbfSQLRepSection
            For Each rs In Rep.RepSections
                SecLoc.Y = SelPoint.Y - rs.FormPos
                If SelPoint.Y >= (rs.FormPos + rs.SectionHeight) And SelPoint.Y < (rs.FormPos + rs.SectionHeight + spw) Then
                    SplitMoveStart(rs)
                    Exit Sub
                End If
                For Each bc In rs.SectionCtrls
                    Select Case bc.CtlType
                        Case "Line"
                            If CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y, bc.Size.Width, bc.Size.Height) Then
                                SelectCtrl(bc)
                                SelFnd = True
                                Exit Sub
                            End If
                        Case "Box"
                            If CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y, bc.Size.Width, 0) _
                            Or CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y, 0, bc.Size.Height) _
                            Or CheckLineSelected(SecLoc, bc.Location.X + bc.Size.Width, bc.Location.Y, 0, bc.Size.Height) _
                            Or CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y + bc.Size.Height, bc.Size.Width, 0) Then
                                'DrawBox(bc,HighlightPen)
                                SelectCtrl(bc)
                                SelFnd = True
                                Exit Sub
                            End If
                        Case "Report", "Grid"
                            If SecLoc.Y >= bc.Top And SecLoc.Y < (bc.Top + bc.Height) _
                              And SecLoc.X >= bc.Left And SecLoc.X < (bc.Left + bc.Width) Then
                                SelFnd = True
                                'no action
                            End If
                        Case Else
                            If SecLoc.Y >= bc.Top And SecLoc.Y < (bc.Top + bc.Height) _
                              And SecLoc.X >= bc.Left And SecLoc.X < (bc.Left + bc.Width) Then
                                SelectCtrl(bc)
                                SelFnd = True
                                Exit Sub
                            End If
                    End Select
                Next
            Next
            If Not SelFnd Then
                Do While SelectedControls.Count > 0
                    SelectedControls.Remove(1)
                Loop
                RefreshDisplay()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub SelectCtrl(ByVal bc As nbfBrowseCtrl)
        Dim sbc As nbfBrowseCtrl
        Dim idx As Integer = 0
        For Each sbc In SelectedControls 'pvBrowseRep.BFInfo.SQLBrowseCtrls
            idx += 1
            If sbc Is bc Then
                SelectedControls.Remove(idx)
                RefreshDisplay()
                Exit Sub
            End If
        Next
        SelectedControls.Add(bc)
        RefreshDisplay()
    End Sub
    Private Sub FormRtClick(ByVal e As System.Windows.Forms.MouseEventArgs)
        Try
            Dim bc As nbfBrowseCtrl
            Dim hit_range As Integer = 3
            Dim lstart_x As Integer
            Dim lstart_y As Integer
            Dim lend_x As Integer
            Dim lend_y As Integer
            Dim start_x As Integer
            Dim start_y As Integer
            Dim end_x As Integer
            Dim end_y As Integer
            Dim mid_y As Integer
            Dim Sel_x As Integer
            Dim Sel_y As Integer
            Dim Selected As Boolean
            If InCtrlEdit Or InLineEdit Or InBoxEdit Or InSplitMove Then
                Exit Sub
                'else if InSplitMove then
                'SplitMoveEnd
                'exit sub
            End If
            Dim SelPoint As New Point
            Dim SecLoc As Point
            SelPoint.X = e.X
            SelPoint.Y = e.Y
            SelPoint = RevAsLoc(SelPoint)
            Dim rs As New nbfSQLRepSection
            For Each rs In Rep.RepSections
                If SelPoint.Y >= (rs.FormPos + rs.SectionHeight) And SelPoint.Y < rs.FormPos + spw Then
                    'SplitEdit(rs)
                    'exit sub
                End If
                SecLoc.X = SelPoint.X - LeftBorder
                SecLoc.Y = SelPoint.Y - rs.FormPos
                For Each bc In rs.SectionCtrls
                    Select Case bc.CtlType
                        Case "Line"
                            If CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y, bc.Size.Width, bc.Size.Height) Then
                                'DrawLine(bc,HighlightPen)
                                NewEditCtrl = bc
                                LineEditType = "L"
                                LineMenuDelLine.Visible = True
                                LineMenuDelBox.Visible = False
                                LineContextMenu.Show(Me, SetAsLoc(SelPoint))
                                Exit Sub
                                'LineContextMenu.Show(Me,bc.Location)
                            End If
                        Case "Box"
                            If CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y, bc.Size.Width, 0) _
                            Or CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y, 0, bc.Size.Height) _
                            Or CheckLineSelected(SecLoc, bc.Location.X + bc.Size.Width, bc.Location.Y, 0, bc.Size.Height) _
                            Or CheckLineSelected(SecLoc, bc.Location.X, bc.Location.Y + bc.Size.Height, bc.Size.Width, 0) Then
                                'DrawBox(bc,HighlightPen)
                                NewEditCtrl = bc
                                LineEditType = "B"
                                LineMenuDelLine.Visible = False
                                LineMenuDelBox.Visible = True
                                LineContextMenu.Show(Me, SetAsLoc(SelPoint))
                                'LineContextMenu.Show(Me,bc.Location)
                                Exit Sub
                            End If
                        Case Else
                            If SecLoc.Y >= bc.Top And SecLoc.Y < (bc.Top + bc.Height) _
                              And SecLoc.X >= bc.Left And SecLoc.X < (bc.Left + bc.Width) Then
                                ShowCtrlMenu(bc, SelPoint)
                                Exit Sub
                            End If
                    End Select
                Next
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub SplitMoveEnd(ByVal e As System.Windows.Forms.MouseEventArgs)
        InSplitMove = False
        Try
            Dim PtCurrent As Point
            Dim cpt As Point
            cpt.X = 0
            cpt.Y = SplitCeiling
            cpt = SetAsLoc(cpt)
            Dim rs As nbfSQLRepSection
            PrvRect.Height = -1
            rs = Rep.RepSections.Item(SplitMoving)
            PtCurrent.X = e.X
            PtCurrent.Y = e.Y
            If PtCurrent.Y < cpt.Y Then
                PtCurrent.Y = cpt.Y
            End If
            PtCurrent = RevAsLoc(PtCurrent)
            If PtCurrent.Y > rs.FormPos Then
                rs.SectionHeight = PtCurrent.Y - rs.FormPos
            End If
            RefreshDisplay()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub SplitMoveStart(ByVal rs As nbfSQLRepSection)
        If rs.SectionNumber = 0 Then
            SplitCeiling = 1
        Else
            Dim prs As nbfSQLRepSection
            prs = Rep.RepSections.Item(rs.SectionNumber - 1)
            SplitCeiling = prs.FormPos + prs.SectionHeight + spw + 1
        End If
        SplitMoving = rs.SectionNumber
        InSplitMove = True
        RefreshDisplay()
    End Sub
    'Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    'MyBase.OnPaint(e)
    'Redraw(e.Graphics)
    'End Sub
    'Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
    'MyBase.OnPaintBackground(pevent)
    'ReDraw(pevent.Graphics)
    'End Sub
    'Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
    'If Not vl Is Nothing Then
    'vl.Height = Me.Height
    'End If
    'If Not hl Is Nothing Then
    'hl.Width = Me.Width
    'End If
    'End Sub
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        MyBase.WndProc(m)
        Exit Sub


        Dim WM_HSCROLL As Integer = 276
        Dim WM_VSCROLL As Integer = 277
        Select Case m.Msg
            Case WM_VSCROLL, WM_HSCROLL
                Select Case m.WParam.ToInt32
                    Case 8
                        If SuspendDisplay = True Then
                            SuspendDisplay = False
                            pvShowSubReps = True
                        End If
                    Case Else
                        If pvShowSubReps Then
                            SuspendDisplay = True
                            pvShowSubReps = False
                        End If
                End Select
                Me.Invalidate()
        End Select

    End Sub
    Sub AddSqlSource(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ap As New nbfSqlSourceEdit
        Dim dq As nbfDB.nbfResultSet
        nbfBrowseHost.SetStyles(ap, pvAppFrmSI)
        Do
            ap.CheckBox1.Visible = True
            ap.ShowDialog()
            If ap.Abandoned Then
                MsgBox("Add Sql Source Abandoned")
                Exit Sub
            Else
                If Trim(ap.txtName.Text) = "" Then
                    MsgBox("No source name entered")
                    Exit Sub
                End If
                If pvBrowseRep.CheckSqlSourceExists(ap.txtName.Text) Then
                    MsgBox("A source with this name already exists")
                    Exit Sub
                End If
                Dim rp As New nbfSqlSource
                rp.BrowseTableName = Trim(ap.txtName.Text)
                rp.RepTitle = Trim(ap.txtDes.Text)
                rp.BrowseSQLSelect = Trim(ap.txtSelect.Text)
                rp.BrowseSQLFrom = Trim(ap.txtFrom.Text)
                rp.BrowseSQLWhere = Trim(ap.txtWhere.Text)
                rp.BrowseSQLOrder = Trim(ap.txtOrder.Text)
                rp.ParentSource = Rep.SQLSource
                rp.BrowseCaptionVisible = False
                rp.BrowseColHeaders = True
                rp.BrowseRowHeaders = False
                If pvBrowseRep.ValidateSqlSource(rp) Then
                    Rep.SQLSources.Add(rp)
                    Exit Do
                Else
                    Dim fe As New frmError
                    If Not String.IsNullOrEmpty(pvBrowseRep.ValidationError) Then
                        fe.ShowDetails(pvBrowseRep.ValidationError)
                    End If
                    fe.ShowDialog()
                End If
            End If
        Loop
    End Sub
    Sub DelSqlSource(ByVal sender As Object, ByVal e As System.EventArgs)
        EditDelSqlSource(True)
    End Sub
    Sub AddSection(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim asct As New nbfAddSection
            Dim sq As nbfSqlSource
            asct.AppFrmSI = pvAppFrmSI
            If Rep.SubItem Then
                For Each sq In Rep.ParentCtrl.SQLSources
                    If sq.BrowseTableName = Rep.SQLSource Then
                        asct.sqs = sq
                        Exit For
                    End If
                Next
            Else
                For Each sq In pvBrowseRep.BFInfo.SQLSources
                    If sq.BrowseTableName = Rep.SQLSource Then
                        asct.sqs = sq
                        Exit For
                    End If
                Next
            End If
            asct.NbfGrid1.AllowEdit = False
            asct.NbfGrid1.SourceObject = asct.bcs
            asct.NbfGrid1.ColHeadersVisible = False
            asct.NbfGrid1.RowHeadersVisible = False
            asct.RadioButton5.Checked = True
            asct.ShowDialog()
            If asct.Abandoned Then
                MsgBox("Add Section Abandoned")
                asct.NbfGrid1.ReleaseBinding()
                Exit Sub
            Else
                Dim rse As nbfSQLRepSection
                Dim rsn As New nbfSQLRepSection
                Dim rsn2 As New nbfSQLRepSection
                Dim mxi As Integer = 0
                If asct.RadioButton1.Checked Then
                    For Each rse In Rep.RepSections
                        If rse.SectionType = "H" And rse.SectionHead = True Then
                            asct.NbfGrid1.ReleaseBinding()
                            MsgBox("A section of this type already exists")
                            Exit Sub
                        End If
                    Next
                    rsn.SectionName = pvBrowseRep.BFInfo.GetCtrlName()
                    rsn.SectionHeight = CInt(pvBrowseRep.BFInfo.PageSize.Height / 4)
                    rsn.SectionType = "H"
                    rsn.SectionHead = True
                    If asct.CheckSuppHead.Checked Then
                        rsn.Suppress = True
                    End If
                    If asct.CheckPBBefore.Checked Then
                        rsn.PageBreakBefore = True
                    End If
                    rsn2 = New nbfSQLRepSection
                    rsn2.SectionName = pvBrowseRep.BFInfo.GetCtrlName()
                    rsn2.SectionHeight = CInt(pvBrowseRep.BFInfo.PageSize.Height / 4)
                    rsn2.SectionType = "H"
                    rsn2.SectionHead = False
                    If asct.CheckSuppFoot.Checked Then
                        rsn2.Suppress = True
                    End If
                    If asct.CheckPBAfter.Checked Then
                        rsn2.PageBreakAfter = True
                    End If
                ElseIf asct.RadioButton3.Checked Then
                    For Each rse In Rep.RepSections
                        If rse.SectionType = "P" And rse.SectionHead = True Then
                            asct.NbfGrid1.ReleaseBinding()
                            MsgBox("A section of this type already exists")
                            Exit Sub
                        End If
                    Next
                    rsn.SectionName = pvBrowseRep.BFInfo.GetCtrlName()
                    rsn.SectionHeight = CInt(pvBrowseRep.BFInfo.PageSize.Height / 4)
                    rsn.SectionType = "P"
                    rsn.SectionHead = True
                    If asct.CheckSuppHead.Checked Then
                        rsn.Suppress = True
                    End If
                    If asct.CheckPBBefore.Checked Then
                        rsn.PageBreakBefore = True
                    End If
                    rsn2 = New nbfSQLRepSection
                    rsn2.SectionName = pvBrowseRep.BFInfo.GetCtrlName()
                    rsn2.SectionHeight = CInt(pvBrowseRep.BFInfo.PageSize.Height / 4)
                    rsn2.SectionType = "P"
                    rsn2.SectionHead = False
                    If asct.CheckSuppFoot.Checked Then
                        rsn2.Suppress = True
                    End If
                    If asct.CheckPBAfter.Checked Then
                        rsn2.PageBreakAfter = True
                    End If
                ElseIf asct.RadioButton5.Checked Then
                    For Each rse In Rep.RepSections
                        If rse.SectionType = "S" And rse.SectionIndex > mxi Then
                            mxi = rse.SectionIndex
                        End If
                    Next
                    mxi += 1
                    rsn.SectionName = pvBrowseRep.BFInfo.GetCtrlName()
                    rsn.SectionHeight = CInt(pvBrowseRep.BFInfo.PageSize.Height / 4)
                    rsn.SectionType = "S"
                    rsn.SectionHead = True
                    rsn.SectionIndex = mxi
                    If asct.CheckSuppHead.Checked Then
                        rsn.Suppress = True
                    End If
                    If asct.CheckPBBefore.Checked Then
                        rsn.PageBreakBefore = True
                    End If
                    rsn2 = New nbfSQLRepSection
                    rsn2.SectionName = pvBrowseRep.BFInfo.GetCtrlName()
                    rsn2.SectionHeight = CInt(pvBrowseRep.BFInfo.PageSize.Height / 4)
                    rsn2.SectionType = "S"
                    rsn2.SectionHead = False
                    rsn2.SectionIndex = mxi
                    If asct.CheckSuppFoot.Checked Then
                        rsn2.Suppress = True
                    End If
                    If asct.CheckPBAfter.Checked Then
                        rsn2.PageBreakAfter = True
                    End If
                    Dim bk As nbfBreakColumn
                    For Each bk In asct.bcs
                        Dim bka As New nbfBreakColumn
                        bka.ColumnNumber = bk.ColumnNumber
                        bka.ColumnName = bk.ColumnName
                        rsn.BreakColumns.Add(bka)
                        Dim bka2 As New nbfBreakColumn
                        bka2.ColumnNumber = bk.ColumnNumber
                        bka2.ColumnName = bk.ColumnName
                        rsn2.BreakColumns.Add(bka2)
                    Next
                End If
                Rep.RepSections.Add(rsn)
                Rep.RepSections.Add(rsn2)
                OrderSections()
                'pvShowSubReps = True
                RefreshDisplay()
            End If
            asct.NbfGrid1.ReleaseBinding()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub DelSection(ByVal sender As Object, ByVal e As System.EventArgs)
        If Rep.RepSections.count = 0 Then
            MsgBox("No Sections available in this report")
            Exit Sub
        End If
        Dim mn As String = Rep.RepSections.GetType.Name
        Dim ss As New nbfDelSection
        nbfBrowseHost.SetStyles(ss, pvAppFrmSI)
        ss.Text = "Delete Section"
        ss.NbfGrid1.GridCaptionVisible = False
        ss.NbfGrid1.ColHeadersVisible = True
        ss.NbfGrid1.RowHeadersVisible = False
        ss.NbfGrid1.AllowEdit = False
        ss.NbfGrid1.AllowAdd = False

        Dim ncd As odGridControls.nbfGridColumn
        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "SectionName"
        ncd.ColHeader = "Name"
        ncd.Width = 60
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
        ss.NbfGrid1.Columns.Add(ncd)

        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "Description"
        ncd.ColHeader = "Description"
        ncd.Width = 100
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
        ss.NbfGrid1.Columns.Add(ncd)

        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "BreakDes"
        ncd.ColHeader = "Break On"
        ncd.Width = 200
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
        ss.NbfGrid1.Columns.Add(ncd)

        'ss.nbfGrid1.AutoScaleColumnWidths = true
        'ss.nbfGrid1.HorizontalScrollBar = false
        ss.NbfGrid1.SourceObject = Rep.RepSections

        ss.ShowDialog()
        If ss.Abandoned Then
            ss.NbfGrid1.ReleaseBinding()
            MsgBox("Selection Abandoned")
            Exit Sub
        End If
        Dim sss As nbfSQLRepSection
        Dim rs As nbfSQLRepSection
        Dim SecDes As String
        sss = Rep.RepSections.Item(ss.NbfGrid1.SelectedIndex)
        SecDes = sss.Description
        Select Case sss.SectionType
            Case "H", "P"
                If Rep.RepSections.count = 2 Then
                    ss.NbfGrid1.ReleaseBinding()
                    MsgBox("You cannot remove the last section group")
                    Exit Sub
                End If
                For Each rs In Rep.RepSections
                    If rs.SectionType = sss.SectionType Then
                        If rs.SectionCtrls.count > 0 Then
                            ss.NbfGrid1.ReleaseBinding()
                            MsgBox("This Section has controls, remove these first")
                            Exit Sub
                        End If
                    End If
                Next
                For Each rs In Rep.RepSections
                    If rs.SectionType = sss.SectionType Then
                        Rep.RepSections.Remove(rs)
                        Exit For
                    End If
                Next
                For Each rs In Rep.RepSections
                    If rs.SectionType = sss.SectionType Then
                        Rep.RepSections.Remove(rs)
                        Exit For
                    End If
                Next
            Case "S"
                If Rep.RepSections.count = 2 Then
                    ss.NbfGrid1.ReleaseBinding()
                    MsgBox("You cannot remove the last section group")
                    Exit Sub
                End If
                For Each rs In Rep.RepSections
                    If rs.SectionType = sss.SectionType And rs.SectionIndex = sss.SectionIndex Then
                        If rs.SectionCtrls.count > 0 Then
                            ss.NbfGrid1.ReleaseBinding()
                            MsgBox("This Section has controls, remove these first")
                            Exit Sub
                        End If
                    End If
                Next
                For Each rs In Rep.RepSections
                    If rs.SectionType = sss.SectionType And rs.SectionIndex = sss.SectionIndex Then
                        Rep.RepSections.Remove(rs)
                        Exit For
                    End If
                Next
                For Each rs In Rep.RepSections
                    If rs.SectionType = sss.SectionType And rs.SectionIndex = sss.SectionIndex Then
                        Rep.RepSections.Remove(rs)
                        Exit For
                    End If
                Next
            Case "B"
                If Rep.RepSections.count = 1 Then
                    ss.NbfGrid1.ReleaseBinding()
                    MsgBox("You cannot remove the last section group")
                    Exit Sub
                End If
        End Select
        MsgBox("Section " & SecDes & " Removed")
        'pvShowSubReps = True
        ss.NbfGrid1.ReleaseBinding()
        OrderSections()
        RefreshDisplay()
    End Sub
    Sub EditSections(ByVal sender As Object, ByVal e As System.EventArgs)
        If Rep.RepSections.count = 0 Then
            MsgBox("No Sections available in this report")
            Exit Sub
        End If

        Dim mn As String = Rep.RepSections.GetType.Name
        Dim ss As New nbfDelSection
        ss.btnControls.Visible = True
        ss.btnBreaks.Visible = True
        ss.Button2.Visible = False
        nbfBrowseHost.SetStyles(ss, pvAppFrmSI)
        ss.SetUpData(pvAppFrmSI, Rep.RepSections)

        ss.btnControls.Visible = True
        ss.Text = "Edit Sections"

        ss.NbfGrid1.GridCaptionVisible = False
        ss.NbfGrid1.ColHeadersVisible = True
        ss.NbfGrid1.RowHeadersVisible = False
        ss.NbfGrid1.HorizontalScrollBar = True
        ss.NbfGrid1.AllowEdit = True
        ss.NbfGrid1.AllowAdd = False

        Dim ncd As odGridControls.nbfGridColumn

        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "Description"
        ncd.ColHeader = "Description"
        ncd.ReadOnlyColumn = True
        'ncd.Width = 200
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
        ss.NbfGrid1.Columns.Add(ncd)

        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "Suppress"
        ncd.ColHeader = "Suppress"
        'ncd.Width = 200
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeBoolean
        ss.NbfGrid1.Columns.Add(ncd)

        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "PageBreakBefore"
        ncd.ColHeader = "Break Before"
        'ncd.Width = 200
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeBoolean
        ss.NbfGrid1.Columns.Add(ncd)

        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "PageBreakAfter"
        ncd.ColHeader = "Break After"
        'ncd.Width = 200
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeBoolean
        ss.NbfGrid1.Columns.Add(ncd)

        'ss.nbfGrid1.AutoScaleColumnWidths = true
        ss.NbfGrid1.SourceObject = Rep.RepSections

        Dim sq As nbfSqlSource
        If Rep.SubItem Then
            For Each sq In Rep.ParentCtrl.SQLSources
                If sq.BrowseTableName = Rep.SQLSource Then
                    ss.sqs = sq
                    Exit For
                End If
            Next
        Else
            For Each sq In pvBrowseRep.BFInfo.SQLSources
                If sq.BrowseTableName = Rep.SQLSource Then
                    ss.sqs = sq
                    Exit For
                End If
            Next
        End If

        ss.ShowDialog()
        ss.NbfGrid1.ReleaseBinding()
        If ss.Abandoned Then
            MsgBox("Selection Abandoned")
            Exit Sub
        End If
        'pvShowSubReps = True
        RefreshDisplay()
    End Sub
    Private Sub EditRep()
        If Not NewEditCtrl Is Nothing Then
            If NewEditCtrl.CtlType = "Report" Then
                Dim er As New nbfEditReport
                er.Rep = NewEditCtrl
                'er.BrowseMenuSubList.Visible = false
                er.Rep.ParentCtrl = Rep
                'er.Height = NewEditCtrl.Height
                er.pvBrowseRep = pvBrowseRep
                er.TopBorder = CInt(pvBrowseRep.BFInfo.MarginTop * pvBrowseRep.BFInfo.FormSize.Height / pvBrowseRep.BFInfo.PageSize.Height)
                er.LeftBorder = CInt((pvBrowseRep.BFInfo.MarginLeft + 10) * pvBrowseRep.BFInfo.FormSize.Width / pvBrowseRep.BFInfo.PageSize.Width)
                er.RightBorder = CInt(pvBrowseRep.BFInfo.MarginRight * pvBrowseRep.BFInfo.FormSize.Width / pvBrowseRep.BFInfo.PageSize.Width)
                er.BottomBorder = CInt(pvBrowseRep.BFInfo.MarginBottom * pvBrowseRep.BFInfo.FormSize.Height / pvBrowseRep.BFInfo.PageSize.Height)
                er.Width = NewEditCtrl.Width + er.LeftBorder + pvBrowseRep.BFInfo.MarginRight
                er.AppFrmSI = AppFrmSI
                er.SI = SI
                'er.SetDisplayStyle("D")
                er.SetUpForm()
                er.Invalidate()
                er.ShowDialog()
                pvShowSubReps = False
                RefreshDisplay()
            Else
                MsgBox("Invalid Control Type")
            End If
        End If
    End Sub
    Sub EditSqlSource(ByVal sender As Object, ByVal e As System.EventArgs)
        EditDelSqlSource(False)
    End Sub
    Sub EditDelSqlSource(ByVal dlt As Boolean)
        If Rep.SQLSources.count = 0 Then
            MsgBox("No SQL Sources available in this report")
            Exit Sub
        End If
        Dim mn As String = Rep.SQLSources.GetType.Name
        Dim ss As New nbfSelectSQLColumn
        nbfBrowseHost.SetStyles(ss, pvAppFrmSI)
        ss.Text = "Select Sql Source"
        ss.NbfGrid1.GridCaptionVisible = False
        ss.NbfGrid1.RowHeadersVisible = False
        ss.NbfGrid1.ColHeadersVisible = True
        ss.NbfGrid1.AllowEdit = False

        Dim ncd As odGridControls.nbfGridColumn
        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "BrowseTableName"
        ncd.ColHeader = "Name"
        ncd.Width = 20
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
        ss.NbfGrid1.Columns.Add(ncd)
        ncd = New odGridControls.nbfGridColumn
        ncd.PropertyName = "RepTitle"
        ncd.ColHeader = "Description"
        ncd.Width = 60
        ncd.DataType = odGridControls.nbfColumnDataType.nbfDataTypeString
        ss.NbfGrid1.Columns.Add(ncd)
        ss.NbfGrid1.AutoScaleColumnWidths = True
        ss.NbfGrid1.HorizontalScrollBar = False
        If Not dlt Then
            ss.btnColumns.Visible = True
        End If
        ss.NbfGrid1.SourceObject = Rep.SQLSources

        ss.ShowDialog()
        Rep.SQLSources.SetAllowNew(True)
        If ss.abandoned Then
            ss.NbfGrid1.ReleaseBinding()
            MsgBox("Selection Abandoned")
            Exit Sub
        End If
        Dim sss As String
        Dim rp As nbfSqlSource
        rp = Rep.SQLSources.Item(ss.NbfGrid1.SelectedIndex)
        sss = rp.BrowseTableName
        If dlt Then
            Dim bc As nbfBrowseCtrl
            Dim rs As nbfSQLRepSection
            For Each rs In Rep.RepSections
                For Each bc In rs.SectionCtrls
                    If Trim(UCase(bc.SQLSource)) = Trim(UCase(sss)) Then
                        ss.NbfGrid1.ReleaseBinding()
                        MsgBox("This SQL Source is referenced by a Control, unable to remove")
                        Exit Sub
                    End If
                Next
            Next
            Dim crid As Integer = ss.NbfGrid1.SelectedIndex
            ss.NbfGrid1.ReleaseBinding()
            Rep.SQLSources.RemoveAt(crid)
            MsgBox("Source " & sss & " Removed")
        Else
            If ss.ColEdit Then
                EditRepCols(SI, rp)
            Else
                Dim ap As New nbfSqlSourceEdit
                nbfBrowseHost.SetStyles(ap, pvAppFrmSI)
                Do
                    ap.txtName.Text = rp.BrowseTableName
                    ap.txtDes.Text = rp.RepTitle
                    If rp.BrowseSQLFrom = "<DIRECT>" Then
                        ap.txtSelect.Text = rp.BrowseSQLSelect
                        ap.Label3.Text = "SQL Statement"
                        ap.Label4.Visible = False
                        ap.Label5.Visible = False
                        ap.Label6.Visible = False
                        ap.txtFrom.Visible = False
                        ap.txtWhere.Visible = False
                        ap.txtOrder.Visible = False
                        ap.txtFrom.Text = "<DIRECT>"
                        ap.txtSelect.Height = (ap.txtOrder.Top + ap.txtOrder.Height) - ap.txtSelect.Top
                    Else
                        ap.txtSelect.Text = rp.BrowseSQLSelect
                        ap.txtFrom.Text = rp.BrowseSQLFrom
                        ap.txtWhere.Text = rp.BrowseSQLWhere
                        ap.txtOrder.Text = rp.BrowseSQLOrder
                    End If
                    ap.ShowDialog()
                    If ap.Abandoned Then
                        MsgBox("Edit Sql Source Abandoned")
                        Exit Sub
                    Else
                        rp.BrowseTableName = Trim(ap.txtName.Text)
                        rp.RepTitle = Trim(ap.txtDes.Text)
                        rp.BrowseSQLSelect = Trim(ap.txtSelect.Text)
                        rp.BrowseSQLFrom = Trim(ap.txtFrom.Text)
                        rp.BrowseSQLWhere = Trim(ap.txtWhere.Text)
                        rp.BrowseSQLOrder = Trim(ap.txtOrder.Text)
                        rp.BrowseCaptionVisible = False
                        rp.BrowseColHeaders = True
                        rp.BrowseRowHeaders = False
                        If pvBrowseRep.ValidateSqlSource(rp) Then
                            pvBrowseRep.RemoveDataSource(rp.BrowseTableName)
                            Exit Do
                        End If
                    End If
                Loop
            End If
            ss.NbfGrid1.ReleaseBinding()
        End If
    End Sub
    Private Sub Display(ByVal sender As System.Object, ByVal e As System.EventArgs)
        pvShowSubReps = True
        pvBrowseRep.ResetSqlSources()
        RefreshDisplay()
    End Sub
    Private Sub DisplayData(ByVal sender As System.Object, ByVal e As System.EventArgs)
        pvShowSubReps = False
        RefreshDisplay()
    End Sub
    Private Sub ChangeCaption(ByVal sender As System.Object, ByVal e As System.EventArgs)
        pvBrowseRep.BFInfo.Caption = InputBox("Enter Caption", "Change Caption", pvBrowseRep.BFInfo.Caption)
        Me.Text = pvBrowseRep.BFInfo.Caption
    End Sub
    Private Sub DrawCtlLabel(ByVal bc As nbfBrowseCtrl, ByVal lc As Point, ByVal g As Graphics)
        pvBrowseRep.DrawCtlLabel(bc, lc, g, LineDrawPen, pvAppFrmSI.FormFont)
    End Sub
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Me.HelpProvider1.HelpNamespace = "OpenDoor.chm"
        Me.HelpProvider1.SetShowHelp(Me, True)
    End Sub
    Private Sub CMPopup(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            'handles context popup
            If SelectedControls.Count > 0 Then
                MenuClearSelect.Visible = True
                CtxtAlign.Visible = True
                ctxtVSpace.Visible = True
                ctxtHSpace.Visible = True
            Else
                MenuClearSelect.Visible = False
                CtxtAlign.Visible = False
                ctxtVSpace.Visible = False
                ctxtHSpace.Visible = False
            End If
            'else
            '    CtxtMenuEdit.Visible = false
            'End If
        Catch ex As Exception
            'msgb(pvSI,ex.Message)
        End Try
    End Sub
    Sub FileSave(ByVal sender As Object, ByVal e As System.EventArgs)
        pvBrowseRep.Save()
    End Sub
    Sub HScrolled(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs)
        If e.Type = ScrollEventType.EndScroll Or e.Type <> ScrollEventType.ThumbTrack Then
            x_offset = HScrollBar1.Value
            ''Dim WebServiceClass As New batman.Services()()
            RepositionControls()
            ts1.ContentPanel.Invalidate()
        End If
    End Sub
    Sub VScrolled(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs)
        If e.Type = ScrollEventType.EndScroll Or e.Type <> ScrollEventType.ThumbTrack Then
            y_offset = VScrollBar1.Value
            ''Dim WebServiceClass As New batman.Services()()
            RepositionControls()
            ts1.ContentPanel.Invalidate()
        End If
    End Sub
    Sub RepositionControls()
        Exit Sub
        'SuspendLayout()
        'Dim c As Control
        'For Each bc As nbfBrowseCtrl In pvBrowseRep.BFInfo.SQLBrowseCtrls
        ' c = GetControlFromBC(bc.Name)
        'If Not c Is Nothing Then
        'c.Location = SetAsLoc(bc.Location)
        'End If
        'Next
        'ResumeLayout()
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions