Skip to main content Skip to footer

HowTo: Add Comment & Uncomment Button to ActiveReports Designer

The End User Designer is a great tool which allows the End Users to create their own reports. However since it is a standalone designer, a majority of code to create a report has to be written using scripts. Generally when we write any program in Visual Studio, we make use of the comment/uncomment button present in the toolbar to disable/enable any particular part of the code. We simply need to select the range of code we want to disable and click the comment button or vice-versa. When we talk about the End User Designer, this is one feature which is not available for the users by default. You have to go line by line through the script code to comment/uncomment it by adding the "//" or "'" symbols, depending upon the language (C# or VB.NET) which you are using to write the script, which is rather time consuming. So does this mean that the End User Designer is missing an important feature? Of course not, because the amount of flexibility which ActiveReports offer is one of its coolest features. We can add buttons to the End User Designer toolbar to provide the functionality which we have been talking about in this post. Let us first take a look how the designer looks with the newly added buttons and what are the steps involved in the process. DesignerScript

  1. The first step involves addition of two custom ToolStripButtons in the Edit MenuStrip for commenting and uncommenting the code. Here is the code for the same:

    //ADDING COMMENT UNCOMMENT BUTTONS TO TOOLSTRIP.....  
    ToolStrip EditMenuStrip = reportdesigner.CreateToolStrips(DesignerToolStrips.Edit)[0];  
    btnCom = new ToolStripButton("Comment", Image.FromFile(@"../../Images/Comment.jpg"));  
    btnCom.Text = "";  
    btnUnCom = new ToolStripButton("UnComment", Image.FromFile(@"../../Images/Uncomment.jpg"));  
    btnUnCom.Text = "";  
    btnCom.Click += new EventHandler(btnCom_Click);  
    btnUnCom.Click += new EventHandler(btnUnCom_Click);  
    EditMenuStrip.Items.Add(btnCom);  
    EditMenuStrip.Items.Add(btnUnCom);  
    btnCom.Enabled = false;  
    btnUnCom.Enabled = false;  
    AppendToolStrips(1, new ToolStrip[] { EditMenuStrip });
    
  2. As you must have noticed from the code in the previous step, we have added event handlers to handle the button clicks. The next two steps describe in brief how both the buttons actually perform this function.

  3. For performing the comment operations using the buttons, we need to check the selection of the script text, which means we are checking the range of the selected text. From the range we need to find the start line and the end line of the selected text and then we add the comment characters to the selected lines on the basis of the scripting language being used.
  4. The approach to uncomment the script code is quite similar to the approach we followed to perform the comment operation. The only difference here is that from the range of selected lines we look for the comment characters at the beginning of the lines and remove them.
  5. Since we are providing an option to comment/uncomment script, the buttons which we add to perform these functions should only be enabled when the Script tab is selected. To do this we will identify whether the Script tab is active using the DesignerTabChanged event and enable the comment/uncomment buttons. The code will look like:
private void reportdesigner_DesignerTabChanged(object sender, DesignerTabChangedEventArgs e)  
{  
   if (e.ActiveTab == DesignerTab.Script)  
   {  
      btnCom.Enabled = true;  
      btnUnCom.Enabled = true;  
   }  
   else  
   {  
      btnCom.Enabled = false;  
      btnUnCom.Enabled = false;  
   }  
}

I am not writing the code for steps 3-4 here, since it would take a lot of space. However to show its actual implementation, I have uploaded a sample which will ease things up. The code to handle the comment/uncomment part has been divided into separate regions in the sample. The remaining code which I have added to the existing End User Designer sample is preceded by comments in UPPER CASE and ends with "...." (dots). The sample can be downloaded from the link below: Download C# Sample

MESCIUS inc.

comments powered by Disqus