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.
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 });
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.
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