The runtime designer uses four main events to control the actions performed by the end user. These events are LayoutChanged, SelChange, StatusChange and ValidateChange.
LayoutChanged
LayoutChanged fires when the designer's layout is changed. The event can be used to monitor changes made to the report layout and update any dependent data such as SQL queries or custom user interfaces. The following list gives a description for the different layout changes.
Setting | Description |
---|---|
ddLCControlMove | 0 – A control's position has changed. |
ddLCControlSize | 1 – A control's size has changed. |
ddLCControlDelete | 2 – A control has been deleted. |
ddLCSectionSize | 3 – A section's size has changed. |
ddLCSectionDelete | 4 – A section is deleted. |
ddLCSectionMove | 5 – A section is moved. |
ddLCReportSize | 6 – The report's size is changed. |
ddLCControlAdd | 7 – A new control has been added to the report. |
SelChange
SelChange fires when an item in the designer is selected. The event can be used to identify the selected item by accessing the designer's SelectedObjects property.
StatusChange
StatusChange fires for each change in the status of the designer action. Designer actions represent the commands typically invoked from UI elements such as toolbars or menus. The following list gives a description for all of the actions:
Setting | Description |
---|---|
ddActionFOpen | 1 - File: Open. |
ddActionFSave | 2 - File: Save. |
ddActionFPageSetup | 3 - File: Page Setup. |
ddActionECut | 4 - Edit: Cut. |
ddActionEPaste | 5 - Edit: Paste. |
ddActionECopy | 6 - Edit: Copy. |
ddActionEUndo | 7 - Edit: Undo. |
ddActionEDelete | 8 - Edit: Delete. |
ddActionEDeleteSection | 9 - Edit: Delete Section. |
ddActionEInsertReportHF | 10 - Edit: Insert Report Header/Footer. |
ddActionEInsertPageHF | 11 - Edit: Insert Page Header/Footer. |
ddActionEInsertGroupHF | 12 - Edit: Insert Group Header/Footer. |
ddActionEReorderGroups | 13 - Edit: Reorder Groups. |
ddActionEInsertField | 14 - Edit: Insert Field. |
ddActionViewExplorer | 15 - View: Report Explorer. |
ddActionViewFieldsList | 16 - View: Fields List. |
ddActionViewPropertyList | 17 - View: Property Listbox. |
ddActionViewGrid | 18 - View: Grid. |
ddActionViewSnapToGrid | 19 - View: Snap to grid. |
ddActionViewFullScreen | 20 - View: Full screen. |
ddActionViewCodeEditor | 21 - View: Script Code Editor. |
ddActionFoAlignLefts | 22 - Format: Align Control Lefts. |
ddActionFoAlignRights | 23 - Format: Align Control Rights. |
ddActionFoAlignCenters | 24 - Format: Align Control Centers. |
ddActionFoAlignTops | 25 - Format: Align Control Tops. |
ddActionFoAlignMiddles | 26 - Format: Align Control Middles. |
ddActionFoAlignBottoms | 27 - Format: Align Control Bottoms. |
ddActionFoAlignToGrid | 28 - Format: Align to Controls Grid. |
ddActionFoAlignCenterInSec | 29 - Format: Align: Center Control in Section. |
ddActionFoSizeSameWidth | 30 - Format: Size controls to the same width. |
ddActionFoSizeSameHeight | 31 - Format: Size controls to the same height. |
ddActionFoSizeSameBoth | 32 - Format: Size controls to the same width and height. |
ddActionFoVSpaceEqual | 33 - Format: Space controls even vertically. |
ddActionFoVSpaceIncrease | 34 - Format: Increase vertical spacing. |
ddActionFoVSpaceDecrease | 35 - Format: Decrease vertical spacing. |
ddActionFoHSpaceEqual | 36 - Format: Space controls even horizontally. |
ddActionFoHSpaceIncrease | 37 - Format: Increase horizontal spacing. |
ddActionFoHSpaceDecrease | 38 - Format: Decrease horizontal spacing. |
ddActionFoOrderBringToFront | 39 - Format: Bring control to the foreground. |
ddActionFoOrderSendToBack | 40 - Format: Send control to the background. |
ddActionFoLockControls | 41 - Format: Lock controls size and position. |
ddActionFoStyle | 42 - Format: Style. |
ddActionFoFontName | 43 - Format: Font name. |
ddActionFoFontSize | 44 - Format: Font size. |
ddActionFoFontBold | 45 - Format: bold. |
ddActionFoFontItalic | 46 - Format: Italic. |
ddActionFoTextAlignLeft | 47 - Format: Align text left. |
ddActionFoTextAlignCenter | 48 - Format: Align text center. |
ddActionFoTextAlignRight | 49 - Format: Align text Right. |
ddActionFoForeColor | 50 - Format: Set foreground color. |
ddActionFoBackColor | 51 - Format: Set background color. |
ddActionFoLineStyle | 52 - Format: Set line style. |
ddActionFoLineColor | 53 - Format: Set line color. |
ddActionFoBorder | 54 - Format: Set border styles. |
ddActionFoBullets | 55 - Format: Set bullet style. |
ddActionFoIndent | 56 - Format: Indent text. |
ddActionFoOutdent | 57 - Format: Outdent text. |
ddActionFoUnderline | 58 - Underline. |
Note: The ExecuteAction method can be used to execute most of the actions above. The items that cannot be executed with this method are items requiring parameters, such as color, font, size and style.
ValidateChange
ValidateChange fires before an item is moved, sized or deleted. This event can be used to control the end user's actions. For instance, this event can be used to prevent the user from removing or moving an important control.
These events can be demonstrated by adding the following to the sample project.
Microsoft Windows Common Controls 6.0
Microsoft Common Dialog Control 6.0
Caption | &File |
---|---|
Name | mFile |
Caption | &Exit |
---|---|
Name | mExit |
Caption | &Edit |
---|---|
Name | mEdit |
Caption | &Font |
---|---|
Name | mFont |
Private Sub mExit_Click()
Unload Me
End Sub
Private Sub mFont_Click()
'Show the font dialog box
cmDLG.Flags = cdlCFBoth
cmDLG.ShowFont
'Updated the selected item(s) with the new font specs
For x = 0 To ard.SelectedObjects.Count - 1
ard.SelectedObjects(x).Font.Name = cmDLG.FontName
ard.SelectedObjects(x).Font.Size = cmDLG.FontSize
ard.SelectedObjects(x).Font.Underline = cmDLG.FontUnderline
ard.SelectedObjects(x).Font.Italic = cmDLG.FontItalic
Next x
End Sub
Private Sub prepPreview()
On Error GoTo errHndl
'Writes the designer's layout
'to the report so it can be previewed.
ard.SaveToObject rpt
'Saves the report object to the specified style
rpt.Save App.Path & "\sample report.rpx", ddSOFile
'Resets report
rpt.Restart
'Run the new report
rpt.Run False
'Add the report to the veiwer
Set arv.ReportSource = rpt
'Disable menu items in preview mode
mFile.Enabled = False
mEdit.Enabled = False
Exit Sub
errHndl:
MsgBox "Error Previewing the Report: " & Err.Number & " " & Err.Description
End Sub
Private Sub prepDesigner()
On Error GoTo errHndl
If Not arv.ReportSource Is Nothing Then
arv.ReportSource.Cancel
Set arv.ReportSource = Nothing
End If
'Load the saved RPX file into a report object
rpt.Load App.Path & "\sample report.rpx"
'Load the report object into the designer
ard.LoadFromObject rpt
'Enable the menu items in design mode
mFile.Enabled = True
mEdit.Enabled = True
Exit Sub
errHndl:
MsgBox "Error in Design Preview: " & Err.Number & " " & Err.Description
End Sub
Private Sub ard_LayoutChanged(ByVal changedObject As Object, ByVal changeType As DDActiveReportsDesignerCtl.ayoutChangeTypes)
Dim cnv As DDActiveReports2.Canvas
Dim w As Long, h As Long
Dim sLCaption As String
'The following code checks to see if a lable has been added
'If a label is added, it will prompt the user for a caption
'And set the lable's width and height to fit the caption
'Check if a label as been added
If TypeOf changedObject Is DDActiveReports2.Label And changeType = ddLCControlAdd Then
'Get a caption for the label
sLCaption = InputBox("Enter a Caption for the Label", "Enter Caption")
'If no caption is given, use the added object's name
If sLCaption = "" Then sLCaption = changedObject.Name
'Set the added label's caption to the given caption
changedObject.Caption = sLCaption
'Use the canvas object to get a width and height for the caption
Set cnv = New DDActiveReports2.Canvas
'makes sure the canvas is measures with the same font size
cnv.Font = changedObject.Font
cnv.MeasureText sLCaption, w, h
'Change the added controls width and height
changedObject.Width = w
changedObject.Height = h
'unload the canvas
Set cnv = Nothing
End If
End Sub
Private Sub ard_SelChange()
Dim sControl As String
'Following code displays the selected label or field's name,
'Top, left, height and width
If ard.SelectedObjects.Count = 1 Then
If TypeOf ard.SelectedObjects(X) Is DDActiveReports2.Field Or _
TypeOf ard.SelectedObjects(X) Is DDActiveReports2.Label Then
sControl = ard.SelectedObjects(X).Name
sControl = sControl & " Top:" & ard.SelectedObjects(X).Top
sControl = sControl & " Left:" & ard.SelectedObjects(X).Left
sControl = sControl & " " & ard.SelectedObjects(X).Height & _
" twips X "
sControl = sControl & ard.SelectedObjects(X).Width & " twips"
End If
Else
sControl = ""
End If
sb.Panels(2).Text = sControl
End Sub
Private Sub ard_StatusChange(ByVal action As DDActiveReportsDesignerCtl.DesignerActionTypes)
Select Case action
Case ddActionFoFontName
'Enable/Disable the font menu option
mFont.Enabled = ard.QueryStatus(ddActionFoFontName)
End Select
End Sub
Private Sub ard_ValidateChange(ByVal changedObject As Object, ByVal changeType As DDActiveReportsDesignerCtl.LayoutChangeTypes, Cancel As Boolean)
'The following code prevents the end user from deleting the
'Data control
If TypeName(changedObject) = "DataControl" Then
If changeType = ddLCControlDelete Then
MsgBox "You are not allowed to delete the report's data control", _
vbCritical, "Cannot Remove Control"
Cancel = True
End If
End If
End Sub