| Chapter 2: C++ .NET WinForm Walk-Through |
|
We've had a few customer using C++ and WinForms so we decided to include this information. However, we recommend you develop with the Visual Basic or C# language targeting .NET as Microsoft has broken C++/.NET code in the past.
ProEssentials WinForm interfaces are used when creating stand-alone client-side EXEs to be distributed and ran on an end-users machine.
If you haven't read the .NET Overview, this is a recommended prerequisite and will help understanding this walk-through.
Walk-Through:
The following information demonstrates how to create your first .NET ProEssentials implementation using the C++ language. It discusses using the WinForm .NET interfaces to add interactive charting content to your EXEs. Other examples are provided within the product/evaluation. Also refer to the "ReadMe.htm", "AspReadMe.htm", and "AspReadMe.htm" files installed onto your system with the eval/product (accessible via Start menu).
1) Start Visual Studio.NET and create a new project targeting a [Windows Forms Application (.NET)] using C++ as your language. Provide the project name [HelloWorld].
Note this code only works with VS.NET 2005 and .NET 2.0 binaries .
2) When the new project opens, you will be presented the design view of "Form1.h".
If you have already installed the ProEssentials WinForm interfaces, skip to step 4.
| Customize
Toolbox... Dialog |
Adding
ProEssentials to Visual Studio.NET... |
|
3) Installing WinForm interfaces into Visual Studio.NET
VS2005 Instructions
- Under the Tools menu, select [Choose Toolbox Items...],
-
If not selected, left click the [.NET Framework Components] tab,
-
Left click the [Browse...] button and find the file "Gigasoft.ProEssentials.dll" found in the DotNet20 subdirectory where you installed ProEssentials. By default, this should be located at "C:\ProEssentials6\DotNet20\",
-
Select the file "Gigasoft.ProEssentials.dll" and close the [Open File] dialog,
-
The [Choose Toolbox Items] dialog should now show 5 highlighted controls: Pe3do, Pego, Pepco, Pepso, and Pesgo.
-
Close the dialog and the 5 new ProEssentials components will be at the bottom of the toolbox.
|
| Form1.h
[Design]... |
Adding
ProEssentials to a Form... |
|
4) Double click the [Pego]
tool within the toolbox. This places an instance of the Pego component
within "Form1.h". Left click bottom-right corner of control
and drag down-right to fill up client area of Form1. The adjacent image
shows what you see.
This
represents the default state of a ProEssentials Graph. The default state
has one subset with four data points. In the course of constructing your
own charts, you'll set the properties PeData.Subsets
and PeData.Points which define the quantity of data your chart
will hold. You'll then pass data via the PeData.Y[subset, point]
two dimensional property array. The following section shows example code
of passing data.
ProEssentials uses the terms Subsets and
Points but you can think of these as Rows and Columns. Passing data is
as simple as filling each Subset with Points worth of data.
|
|
|
Adjusting
design time settings... |
|
5) ProEssentials currently has limited point-and-click
programmability. Our
next release will have extensive point-and-click features, but until then,
you'll have to write a tiny bit a code. Note, when setting color and font
size attributes, we recommend setting the parent Form's versions as these
properties as ProEssentials will use the parent form's settings to help
facilitate a uniform look among sibling controls.
If new to Visual Basic, the
(Name) property is probably the most fundamental property as its
name is reflected in all code. Example: Pego1->PeData->Subsets = 1;
is a line of code, and it shows how the (Name) property (Pego1) starts the line.
|
|
| Form1.h
[Code]... |
|
6) Double click Form1's Title/Caption Bar to
open the code view for "Form1.h" with default System::Void Form1_Load
event initialized.
The
cursor will be within the Form1_Load code section, enter the following
code into this section.
You can copy and paste if you must, but
hand-typing at least some of this code will really help familiarize yourself
with the Gigasoft.ProEssentials namespace.
Note:
adding the following using declaration
at the top of the namespace HelloWorld implementation
will shorten enumeration syntax.
using namespace Gigasoft::ProEssentials::Enums;
Note:
Intellisense within C++ does not provide much help. This
makes WinForm/C++ development the most tedious compared to VB and C#.
For example,
after typing...
[pego1->PeFont->FontSize]you
will need help determining the possible options. You
will have to reference this help file to learn that the FontSize
property is of type Gigasoft.ProEssentials.Enums.FontSize.
So typing
[= Fontsize::] will show available options for this property (assuming
you've added the above using
declaration).
|
pego1->PeString->MainTitle = "Hello .NET";
pego1->PeString->SubTitle = "";
pego1->PeData->Subsets = 1;
pego1->PeData->Points = 6;
pego1->PeData->Y[0,0] = 10.0F;
pego1->PeData->Y[0, 1] = 30.0F;
pego1->PeData->Y[0, 2] = 20.0F;
pego1->PeData->Y[0, 3] = 40.0F;
pego1->PeData->Y[0, 4] = 30.0;
pego1->PeData->Y[0, 5] = 50.0;
pego1->PeString->PointLabels[0] = "Jan";
pego1->PeString->PointLabels[1] = "Feb";
pego1->PeString->PointLabels[2] = "Mar";
pego1->PeString->PointLabels[3] = "Apr";
pego1->PeString->PointLabels[4] = "May";
pego1->PeString->PointLabels[5] = "June";
pego1->PeString->SubsetLabels[0] = "Framework";
pego1->PeString->YAxisLabel = "Microsoft";
pego1->PeColor->SubsetColors[0] = System::Drawing::Color::Red;
pego1->PeColor->BitmapGradientMode = true;
pego1->PeColor->QuickStyle = Gigasoft::ProEssentials::Enums::QuickStyle::LightInset;
pego1->PeTable->Show = GraphPlusTable::Both;
pego1->PeData->Precision = DataPrecision::NoDecimals;
pego1->PeFont->Label->Bold = true;
pego1->PePlot->Method = GraphPlottingMethod::Bar;
pego1->PePlot->Option->GradientBars = 8;
pego1->PeFont->FontSize = FontSize::Large;
pego1->PeUserInterface->HotSpot->Data = true;
pego1->PeFunction->ReinitializeResetImage();
pego1->Refresh(); // call standard .NET Refresh method to force paint
|
| Form1.cs
[Design]... |
Adding
a DataHotSpot event... |
|
7) The code above enabled the DataHotSpot event,
so we should place some appropriate code in the DataHotSpot event.
Left click the pego
control within Form1 to give it the focus.
From the main menu
select [View] and [Properties
Window]
Within the [Properties Window], click the event icon.
Within the available events, double-click PeDataHotSpot
This opens the code view of "Form1.h"
with cursor within the pego1_PeDataHotSpot event handler. |
Add the following code to the pego1_PeDataHotSpot
event.
|
System::String ^ps;
ps = "Point ";
ps += e->PointIndex.ToString();
ps += " has a value of ";
ps += pego1->PeData->Y[0, e->PointIndex].ToString();
System::Windows::Forms::MessageBox::Show(ps); |
8)
Save and run the project. Your project
will show an image as follows. Move the mouse over a bar and click to
trigger the DataHotSpot event. |
| Run
the project... |
Success!!! |
|
|
This
completes this walkthrough.
Please
read the remaining sections within Chapter 2 and review the demo code
and documentation that's installed with the eval/product.
Once installed, the demo program can be
accessed via shortcut...
Start / All Programs / ProEssentials v6 /
PEDemo
Note that the demo is replicated in native
VB.NET, C#.NET, VB6,
and VC6 projects all accessible from the start menu. These
are great for modifying an existing demo to test potential modifications
before implementing within your applications. |
|