To handle the clicks on the toolbar buttons and dispatch them to the appropriate handlers, use the following code:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' handle clicks on toolbar buttons Private Sub _tb_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles _tb.ButtonClick ' design/preview mode If e.Button.Equals(_btnDesign) Then SetDesignMode(True) End If If e.Button.Equals(_btnPreview) Then SetDesignMode(False) ' file commands If e.Button.Equals(_btnNew) Then NewFile() If e.Button.Equals(_btnOpen) Then OpenFile() If e.Button.Equals(_btnSave) Then SaveFile() ' allow user to undo clipboard operations If e.Button.Equals(_btnCut) Or e.Button.Equals(_btnPaste) Then _c1rd.UndoStack.SaveState() End If ' clipboard If e.Button.Equals(_btnCut) Then _c1rd.ClipboardHandler.Cut() If e.Button.Equals(_btnCopy) Then _c1rd.ClipboardHandler.Copy() If e.Button.Equals(_btnPaste) Then _c1rd.ClipboardHandler.Paste() ' undo/redo If e.Button.Equals(_btnUndo) Then _c1rd.UndoStack.Undo() If e.Button.Equals(_btnRedo) Then _c1rd.UndoStack.Redo() ' add/remove reports If e.Button.Equals(_btnAddReport) Then NewReport() If e.Button.Equals(_btnDelReport) Then DeleteReport() ' add fields ' (just set create info and wait for CreateField event from designer) If e.Button.Equals(_btnAddField) Then _c1rd.CreateFieldInfo = e.Button End If If e.Button.Equals(_btnAddLabel) Then _c1rd.CreateFieldInfo = e.Button End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
// handle clicks on toolbar buttons private void _tb_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { // design/preview mode if (e.Button == _btnDesign) SetDesignMode(true); if (e.Button == _btnPreview) SetDesignMode(false); // file commands if (e.Button == _btnNew) NewFile(); if (e.Button == _btnOpen) OpenFile(); if (e.Button == _btnSave) SaveFile(); // allow user to undo clipboard operations if (e.Button == _btnCut || e.Button == _btnPaste) _c1rd.UndoStack.SaveState(); // clipboard if (e.Button == _btnCut) _c1rd.ClipboardHandler.Cut(); if (e.Button == _btnCopy) _c1rd.ClipboardHandler.Copy(); if (e.Button == _btnPaste) _c1rd.ClipboardHandler.Paste(); // undo/redo if (e.Button == _btnUndo) _c1rd.UndoStack.Undo(); if (e.Button == _btnRedo) _c1rd.UndoStack.Redo(); // add/remove reports if (e.Button == _btnAddReport) NewReport(); if (e.Button == _btnDelReport) DeleteReport(); // add fields // (just set create info and wait for CreateField event from designer) if (e.Button == _btnAddField) _c1rd.CreateFieldInfo = e.Button; if (e.Button == _btnAddLabel) _c1rd.CreateFieldInfo = e.Button; } |
This routine dispatches about half of the commands to specialized handlers. These will be described later. The other half (clipboard, undo/redo) is handled directly by the C1ReportDesigner control.
Note that before calling the Cut and Paste methods, the code calls the SaveState method to save the current state of the report. This allows the user to undo and redo clipboard operations. In general, your code should always call SaveState before making changes to the report.