|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionSome of you may have already come to realize I have previously written and released a similar control via CodeProject. Even though the last control was written using C++ along with MFC, some readers may wonder why I would recreate the same control without branching out into uncharted territory. But the fact of the matter is: I am indeed branching out, and this isn't simply a recreation. I've never ventured into C# before. So rather than jump the gun and start out with an ambitious project that is nothing but of a stranger to me, I have decided to stick with something I am both familiar and comfortable with: porting my C2DPushGraph control to C#. After porting the control and discovering C# wasn't much different than C++ in ideology, I quickly shifted my focus to improving the feature set and overall design of the control, all while conforming to general C# standards and ethics. That being said (or rather typed), the basis of the control remains the same. So my previously written CodeProject article's introduction also applies here: "In past programming experiences, I've often had a desire to display and monitor the rate or performance of some operation on a graph. Whether it be the rate of write operations or the number of content results extracted each second, I always thought a graph similar to the graphs found in Windows XP’s Task Manager (CTRL-Alt-Delete) performance and networking tabs would do the trick well. After a quick search on Google for the graph control clone yielded no relevant results, I decided cloning it myself would be an interesting and beneficial experience. As time progressed and cloning the control proved itself easy, I decided to add more features and make it completely customizable in nearly every aspect. In the end, as the smoke cleared, I was left face to face with the control this article revolves around. It looked and behaved astonishingly beautiful for being developed with such haste. But who cares about its pastime, let's move on and see how easy it is to implement..." Using the CodeAdding the Control to your Windows FormThe easiest and simplest method of adding the
After performing these steps, you'll be able to drag and drop the The alternate method of adding the control to your form involves manually coding the control instantiation and its creation within your form. While seldom used, this method proves itself useful if you want to add the control “on the fly”. The first suggested step is including the Next, you'll need to add a new // This example creates the control and automatically
// adds it to the form ('this') with the positioning
// referenced in the passed Rectangle:
m_PushGraph = new C2DPushGraph( this,
new Rectangle( Xpos, Ypos, GraphWidth, GraphHeight ));
// This example simple creates the control
// and automatically add it to the form ('this'):
m_PushGraph = new C2DPushGraph( this );
// This example uses the standard manual
// method for adding a control:
m_PushGraph = new C2DPushGraph();
this.Controls.Add( m_PushGraph );
Setting the Graph RangeAfter instantiating the You set the range by setting ' Note: If Adding a New LineNow that we have our basic graph all ready to roll, we'll want to add one or more new lines to it. But before we dive any deeper into the conventions of calling this method, it's important to understand how lines are identified. A line can either be uniquely identified using a numerical ID (slightly better performance) or by using a name (more convenient). This identification provides us with a way to obtain references to lines at anytime without having to keep track of the line handles. It is important to note that the choice of using IDs or just obtaining and storing the line handle after line creation is a matter of personal preference (you could even use a combination of both). To add a new line, we call the control's conveniently named ' // This example uses a numerical ID for our line:
const int EXAMPLE_LINE = 47;
MyLineHandle = m_PushGraph.AddLine( EXAMPLE_LINE, Colors.Blue );
if (MyLineHandle == null)
{
// ... Line already exists.
}
// This example uses a name for our line:
MyLineHandle = m_PushGraph.AddLine( "My Example Line", Colors.Blue );
if (MyLineHandle == null)
{
// ... Line already exists.
}
Pushing a New Magnitude Point to your LinePushing a new point to our newly created line is anything but non-trivial. The first thing to do, is to call the control's ' const int EXAMPLE_LINE = 47; // Used in our last example
// Push a magnitude of 20 to our numerically identified line:
m_PushGraph.Push( EXAMPLE_LINE, 20 );
// Push a magnitude of 76 to our named line:
m_PushGraph.Push( "My Example Line", 76 );
// Update the graph (explained in next section):
m_PushGraph.UpdateGraph();
Updating the GraphWith our graph fundamentally established and our first set of magnitudes pleasantly awaiting their visual debut, our last required step is to update and redraw our Luckily, Customizing the Appearance and Behavior of your GraphAlthough our graph is now incorporated and completely functional within our application (assuming you've been referring to this tutorial as a general guide to implementing the control), we still have a great deal of features to explore. All of these features involve properties to adjust aesthetics and behavior. While altering them is purely optional, they'll provide greater depth and visual splendor to your application. To provide you with a mental representation of the general graph components, refer to the following image:
Additional Properties
Customizing the appearance of your linesThe appearance of individual lines can be altered by changing properties using the line's handle. If you have not retained handles for each of your lines, they can be retrieved by calling “ Properties:
Additional Notes
Contacting the AuthorIf you have any questions or comments regarding this control, please feel free to send Stuart Konen an e-mail at skonen@gmail.com. Stuart Konen can also be contacted via AOL's Instant Messenger: Screen name 'Griblik3'. History
|
||||||||||||||||||||||