Glossary Item Box

Samples | Walkthroughs

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Walkthrough: Adding Code for the Report Toolbar

This walkthrough is split up into the following activities:

Adding code for the Report toolbar's SelectionChanged event

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

'Visual Basic
Private Sub selChangeReportToolbar()
        Dim m_arrayFont As New ArrayList()
        Dim m_arrayFontSize As New ArrayList()
        Dim m_arrayClassName As New ArrayList()
        Dim sFont As String
        Dim sFontSize As String
        Dim sClassName As String
        sFont = ""
        sFontSize = ""
        sClassName = ""
        Dim ctl As String
        cnt = Designer1.Selection.Count
        If cnt = 0 Then
            Exit Sub
        End If
        For i = 0 To cnt - 1
            ctl = Designer1.Selection(i).GetType().ToString
            If ((ctl.IndexOf("TextBox") > 0) Or (ctl.IndexOf("CheckBox") > 0) Or _
              (ctl.IndexOf("Label") > 0)) Then
                Select Case ctl
                    Case "DataDynamics.ActiveReports.TextBox"
                        sFont = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.TextBox).Font.Name.ToString()
                        sFontSize = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.TextBox).Font.Size.ToString()
                        sClassName = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.TextBox).ClassName.ToString()
                        If m_arrayFont.Contains(sFont) = False Then
                            m_arrayFont.Add(sFont)
                            If m_arrayFontSize.Contains(sFontSize) = False Then
                                m_arrayFontSize.Add(sFontSize)
                                If m_arrayClassName.Contains(sClassName) = False Then
                                    m_arrayClassName.Add(sClassName)
                                End If
                            End If
                        End If
                    Case "DataDynamics.ActiveReports.Label"
                        sFont = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.Label).Font.Name.ToString()
                        sFontSize = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.Label).Font.Size.ToString()
                        sClassName = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.Label).ClassName.ToString()
                        If m_arrayFont.Contains(sFont) = False Then
                            m_arrayFont.Add(sFont)
                            If m_arrayFontSize.Contains(sFontSize) = False Then
                                m_arrayFontSize.Add(sFontSize)
                                If m_arrayClassName.Contains(sClassName) = False Then
                                    m_arrayClassName.Add(sClassName)
                                End If
                            End If
                        End If
                    Case "DataDynamics.ActiveReports.CheckBox"
                        sFont = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.CheckBox).Font.Name
                        sFontSize = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.CheckBox).Font.Size
                        sClassName = CType(Designer1.Selection(i), _
                          DataDynamics.ActiveReports.CheckBox).ClassName
                        If m_arrayFont.Contains(sFont) = False Then
                            m_arrayFont.Add(sFont)
                            If m_arrayFontSize.Contains(sFontSize) = False Then
                                m_arrayFontSize.Add(sFontSize)
                                If m_arrayClassName.Contains(sClassName) = False Then
                                    m_arrayClassName.Add(sClassName)
                                End If
                            End If
                        End If
                End Select
            End If
        Next
        If ((m_arrayFont.Count >= 1) AndAlso (cnt > 1)) Then
            cmbFonts.Text = ""
            cmbFonts.Enabled = True
        ElseIf (m_arrayFont.Count = 0) Then
            cmbFonts.Text = ""
            cmbFonts.Enabled = False
        ElseIf (m_arrayFont.Count = 1) Then
            cmbFonts.Text = m_arrayFont(0).ToString()
            cmbFonts.Enabled = True
        End If
        If ((m_arrayFont.Count >= 1) AndAlso (cnt > 1)) Then
            cmbFontSize.Text = ""
            cmbFontSize.Enabled = True
        ElseIf (m_arrayFontSize.Count = 0) Then
            cmbFontSize.Text = ""
            cmbFontSize.Enabled = False
        ElseIf (m_arrayFontSize.Count = 1) Then
            cmbFontSize.Text = m_arrayFontSize(0).ToString()
            cmbFontSize.Enabled = True
        End If
        If ((m_arrayFont.Count >= 1) AndAlso (cnt > 1)) Then
            cmbClassName.Text = ""
            cmbClassName.Enabled = True
        ElseIf (m_arrayClassName.Count = 0) Then
            cmbClassName.Text = ""
            cmbClassName.Enabled = False
        ElseIf (m_arrayClassName.Count = 1) Then
            cmbClassName.Text = m_arrayClassName(0).ToString()
            cmbClassName.Enabled = True
        End If
End Sub

 

//C#
private void selChangeReportToolbar()
{
	ArrayList m_arrayFont=new ArrayList();
	ArrayList m_arrayFontSize = new ArrayList();
	ArrayList m_arrayClassName = new ArrayList();
	string sFont=null;	string sFontSize=null;
	string sClassName=null;
	int cnt = this.designer1.Selection.Count;
	for(int i=0;i<cnt;i++)
	{
		string ctl = designer1.Selection[i].
		  GetType().ToString();
		if((ctl.IndexOf("TextBox") >0)||
		  (ctl.IndexOf("CheckBox") >0)||(ctl.
		  IndexOf("Label") >0))
		{
			switch(ctl)
			{
				case "DataDynamics.ActiveReports.TextBox":
					sFont =((DataDynamics.ActiveReports.
						TextBox)designer1.Selection[i]).
						Font.Name.ToString();
					sFontSize =((DataDynamics.
						ActiveReports.TextBox)designer1.
						Selection[i]).Font.Size.ToString();
					sClassName =((DataDynamics.
						ActiveReports.TextBox)designer1.
						Selection[i]).ClassName.ToString();
					if(m_arrayFont.Contains(sFont)==false)
						m_arrayFont.Add(sFont);
					if(m_arrayFontSize.Contains
						(sFontSize)==false)
						m_arrayFontSize.Add(sFontSize);
					if(m_arrayClassName.Contains
						(sClassName)==false)
						m_arrayClassName.Add(sClassName);
					break;	
				case "DataDynamics.ActiveReports.Label":
					sFont =((DataDynamics.ActiveReports.
						Label)designer1.Selection[i]).
						Font.Name.ToString();
					sFontSize =((DataDynamics.
						ActiveReports.Label)designer1.
						Selection[i]).Font.Size.ToString();
					sClassName =((DataDynamics.
						ActiveReports.Label)designer1.
						Selection[i]).ClassName.ToString();
					if(m_arrayFont.Contains(sFont)==false)
						m_arrayFont.Add(sFont);
					if(m_arrayFontSize.Contains
						(sFontSize)==false)
						m_arrayFontSize.Add(sFontSize);
					if(m_arrayClassName.Contains
						(sClassName)==false)
						m_arrayClassName.Add(sClassName);
					break;
				case "DataDynamics.ActiveReports.CheckBox":
					sFont =((DataDynamics.ActiveReports.
						CheckBox)designer1.Selection[i]).
						Font.Name.ToString();
					sFontSize =((DataDynamics.ActiveReports.
						CheckBox)designer1.Selection[i]).
						Font.Size.ToString();
					sClassName =((DataDynamics.ActiveReports.
						CheckBox)designer1.Selection[i]).
						ClassName.ToString();
					if(m_arrayFont.Contains(sFont)==false)
						m_arrayFont.Add(sFont);
					if(m_arrayFontSize.Contains
						(sFontSize)==false)
						m_arrayFontSize.Add(sFontSize);
					if(m_arrayClassName.Contains
						(sClassName)==false)
						m_arrayClassName.Add(sClassName);
					break;	
			}
		}
		if((m_arrayFont.Count>=1) && (cnt>1))
		{
			cmbFonts.Text = "";
			cmbFonts.Enabled =true;
		}
		else if(m_arrayFont.Count==0)
		{
			cmbFonts.Text = "";
			cmbFonts.Enabled = false;
		}
		else if(m_arrayFont.Count ==1)
		{
			cmbFonts.Text = m_arrayFont[0].ToString();
			cmbFonts.Enabled =true;
		}
		if((m_arrayFont.Count>=1) && (cnt>1))
		{
			cmbFontSize.Text = "";
			cmbFontSize.Enabled = true;
		}
		else if(m_arrayFontSize.Count ==0)
		{
			cmbFontSize.Text = "";
			cmbFontSize.Enabled = false;
		}
		else if(m_arrayFontSize.Count==1)
		{
			cmbFontSize.Text = m_arrayFontSize[0].ToString();
			cmbFontSize.Enabled = true;
		}
		if((m_arrayFont.Count>=1) && (cnt>1))
		{
			cmbClassName.Text = "";
			cmbClassName.Enabled = true;
		}
		else if(m_arrayClassName.Count==0)
		{
			cmbClassName.Text = "";
			cmbClassName.Enabled = false;
		}
		else if(m_arrayClassName.Count ==1)
		{
			cmbClassName.Text = m_arrayClassName[0].ToString();
			cmbClassName.Enabled = true;
		}
	}
}

Adding code for the DesignerAction to be returned

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

'Visual Basic
Private Function getActionFromString(ByVal action As String) As _
  DataDynamics.ActiveReports.Design.DesignerAction
        Dim m_action As New DataDynamics.ActiveReports.Design.DesignerAction()
        Select Case (action)
            Case "Bold"
                m_action = DesignerAction.FormatFontBold
            Case "Italic"
                m_action = DesignerAction.FormatFontItalic
            Case "Underline"
                m_action = DesignerAction.FormatFontUnderline
            Case "Bullets"
                m_action = DesignerAction.FormatRTFBullets
            Case "IncreaseIndent"
                m_action = DesignerAction.FormatRTFIndent
            Case "DecreaseIndent"
                m_action = DesignerAction.FormatRTFOutdent
            Case "EditScript"
                m_action = DesignerAction.EditScript
            Case "ReorderGroups"
                m_action = DesignerAction.ReorderGroups
            Case "ViewGrid"
                m_action = DesignerAction.ViewGrid
            Case "AlignLeft"
                m_action = DesignerAction.FormatTextAlignLeft
            Case "Center"
                m_action = DesignerAction.FormatTextAlignCenter
            Case "AlignRight"
                m_action = DesignerAction.FormatTextAlignRight
            Case "Justify"
                m_action = DesignerAction.FormatTextAlignJustify
        End Select
        Return m_action
End Function

 

//C#
private DataDynamics.ActiveReports.Design.DesignerAction 
  getActionFromString(string action)
{
	switch(action)
	{
		case "Bold":
		    result =DataDynamics.ActiveReports.Design.DesignerAction.FormatFontBold;
		    break;
		case "Italic":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.FormatFontItalic;
		    break;	
		case "Underline":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.FormatFontUnderline;
		    break;
		case "Bullets":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.FormatRTFBullets;
		    break;
		case "IncreaseIndent":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.FormatRTFIndent;
		    break;
		case "DecreaseIndent":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.FormatRTFOutdent;
		    break;
		case "EditScript":
		    result =DataDynamics.ActiveReports.Design.DesignerAction.EditScript;
		    break;
		case "ReorderGroups":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.ReorderGroups;
		    break;
		case "ViewGrid":
		    result=DataDynamics.ActiveReports.Design.DesignerAction.ViewGrid;
		    break;
		case "AlignLeft":
		    result = DataDynamics.ActiveReports.Design.DesignerAction.FormatTextAlignLeft;
		    break;
		case "Center":
		    result = DataDynamics.ActiveReports.Design.DesignerAction
		      .FormatTextAlignCenter;
		    break;
		case "AlignRight":
		    result = DataDynamics.ActiveReports.Design.DesignerAction
		      .FormatTextAlignRight;
		    break;
		case "Justify":
		    result = DataDynamics.ActiveReports.Design.DesignerAction
		      .FormatTextAlignJustify;
		    break;
	}
	return result;
}

Adding code for the Report toolbar's setStatus event

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

'Visual Basic
Private Sub setStatus(ByVal action As String, ByVal toolbutton As _
  System.Windows.Forms.ToolBarButton)
        Dim m_action As New DataDynamics.ActiveReports.Design.DesignerAction()
        m_action = getActionFromString(action)
        toolbutton.Enabled = Designer1.QueryActionEnabled(m_action)
        toolbutton.Pushed = Designer1.QueryActionChecked(m_action)
End Sub

 

//C#
private void setStatus(string action,System.Windows.Forms.ToolBarButton toolButton)
{
	DataDynamics.ActiveReports.Design.DesignerAction m_action = getActionFromString(action);
	toolButton.Enabled = designer1.QueryActionEnabled(m_action);
	toolButton.Pushed = designer1.QueryActionChecked(m_action);
}

Adding code for the Idle and Designer1_StatusChanged events

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

'Visual Basic    
Private Sub Idle(ByVal sender As Object, ByVal e As System.EventArgs)
    If doStatusChange = True Then
        Me.RunStatusChangeCode()
        doStatusChange = False
    End If
End Sub

Private Sub RunStatusChangeCode()
    For i = 0 To Me.tlbReport.Buttons.Count - 1
        Dim tb As New System.Windows.Forms.ToolBarButton()
        tb = Me.tlbReport.Buttons(i)
        If tb.Tag Is Nothing = False Then
            setStatus(tb.Tag, tb)
        End If
    Next
End Sub

Private Sub Designer1_StatusChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles Designer1.StatusChanged
    doStatusChange = True
End Sub

 

//C#
private void Idle(object sender, System.EventArgs e)
{
	if(doStatusChange)
	{
		this.RunStatusChangeCode();
		doStatusChange = false;
	}
}

private void RunStatusChangeCode()
{
	for(int i=0;i<this.tlbReport.Buttons.Count;i++)
	{
		System.Windows.Forms.ToolBarButton tb = this.tlbReport.Buttons[i];
		if(tb.Tag != null)
		{
			setStatus (tb.Tag.ToString(),tb);	
		}
	}
}

private void designer1_StatusChanged(object sender, System.EventArgs e)
{
	doStatusChange = true;
}

Adding code for the Report toolbar's executeReportAction event

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

'Visual Basic
Private Sub executeReportAction(ByVal action As String, ByVal e As System.Windows.Forms._
 	ToolBarButtonClickEventArgs)
        Try
            Select Case action
                Case "Bold"
                    Designer1.ExecuteAction(DesignerAction.FormatFontBold)
                Case "Italic"
                    Designer1.ExecuteAction(DesignerAction.FormatFontItalic)
                Case "Underline"
                    Designer1.ExecuteAction(DesignerAction.FormatFontUnderline)
                Case "AlignRight"
                    Designer1.ExecuteAction(DesignerAction.FormatTextAlignRight)
                Case "Center"
                    Designer1.ExecuteAction(DesignerAction.FormatTextAlignCenter)
                Case "AlignLeft"
                    Designer1.ExecuteAction(DesignerAction.FormatTextAlignLeft)
                Case "Justify"
                    Designer1.ExecuteAction(DesignerAction.FormatTextAlignJustify)
                Case "Bullets"
                    Designer1.ExecuteAction(DesignerAction.FormatRTFBullets)
                Case "DecreaseIndent"
                    Designer1.ExecuteAction(DesignerAction.FormatRTFOutdent)
                Case "IncreaseIndent"
                    Designer1.ExecuteAction(DesignerAction.FormatRTFIndent)
            End Select
        Catch ex As Exception
            MessageBox.Show(Me, ex.Message, "Action Failed", MessageBoxButtons.OK, _
              MessageBoxIcon.Error)
        End Try
End Sub

 

//C#
private void executeReportAction(string action)
{
	switch(action)
	{
		case "Bold":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatFontBold);
			break;
		case "Italic":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatFontItalic);
			break;
		case "Underline":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatFontUnderline);
			break;
		case "Bullets":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatRTFBullets);
			break;
		case "IncreaseIndent":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatRTFIndent);
			break;
		case "DecreaseIndent":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatRTFOutdent);
			break;
		case "EditScript":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.EditScript);
			break;
		case "ReorderGroups":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.ReorderGroups);
			break;
		case "ViewGrid":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.ViewGrid);
			break;
		case "AlignLeft":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatTextAlignLeft);
			break;
		case "Center":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatTextAlignCenter);
			break;
		case "AlignRight":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatTextAlignRight);
			break;
	case "Justify":
			designer1.ExecuteAction(DataDynamics.ActiveReports.Design.
				DesignerAction.FormatTextAlignJustify);
			break;
	}
}

Adding code for tlbReport's ButtonClick event

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

'Visual Basic
Private Sub tlbReport_ButtonClick(ByVal sender As Object, ByVal e As _
	System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tlbReport.ButtonClick
        executeReportAction(e.Button.Tag.ToString(), e)
End Sub

 

//C#
private void tlbReport_ButtonClick(object sender, System.Windows.
	Forms.ToolBarButtonClickEventArgs e)
{
	executeReportAction(e.Button.Tag.ToString());
}

Samples | Walkthroughs

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.