天天看點

NTGraph.ocx的使用(轉載) 收藏

1,下載下傳NTGraph.ocx控件,具體下載下傳位址:www.codeproject.com/KB/miscctrl/NTGraph_ActiveX/NTGraph_bin.zip。

2,在本機注冊控件:把步驟1所下載下傳的壓縮包解壓到一個指定位置,然後打開VC++,在菜單欄選擇tools-->Activex Test Control Container後在彈出的視窗中選擇File--》register controls,接下來就是選擇NTGraph.ocx所在的路徑就可以完成注冊。

3,當完成第二步後就應該在系統Acticex控件庫裡面有你所注冊的控件。當你确認控件已完成注冊時就可以進行下一步的操作了。否則重新注冊一遍。

4,具體使用過程:

   a.用MFC向導建立一個單文檔或多文檔視圖,該視圖派生自CFormView類。

   b.在project--->Add to project --->compoments and controls然後選擇你所需要的控件,當然這裡選擇NTGraph控件。

   c.完成上一步驟後Visual C++ 就會為我們建立NTGraph類,而你不需要對該類再做修改,而隻要跟其他系統自帶的控件使用NTGraph就行了

   d.接下來,你就會在資源視圖的控件菜單中找到NTGraph,使用方式和Edit 或Button控件一模一樣。

The control's customization options are straightforward:

// Customize Graph Properties

m_Graph.SetBackColor (RGB(0,0,0));

m_Graph.SetAxisColor (RGB(0,255,0));

m_Graph.SetLabelColor (RGB(128,255,255));

// Control's Frame and Plot area options

m_Graph.SetFrameColor((RGB(0,0,0));

m_Graph.SetPlotAreaColor(RGB(212,222,200));

m_Graph.SetFrameStyle(2) // (1) - Flat

                        //(2) - Scope (raised frame and sunken plot area borders)

                        //(3) - 3DFrame (a bitmap frame picture)

m_Graph.SetGridColor(RGB(192,192,192));

m_Graph.SetShowGrid (TRUE);

m_Graph.SetCursorColor (RGB(255,0,0));

m_Graph.SetTrackMode (1);

m_Graph.SetGraphTitle("XY Plot");

m_Graph.SetXLabel ("X Axis");

m_Graph.SetYLabel("Y Axis");

m_Graph.SetRange(0.,10,-1,1.);

You don't need to call the control   Invalidate()   function every time you change a Graph property. The changes are automatically reflected on the control appearance.

To load the data into the control...

// Customize Graph Elements

// The Graph elements are dynamically allocated!

// Element 0 is allocated by default

// Even after a call to the ClearGraph method, the Element-0 is automaticaly allocated.

m_Graph.SetElementLineColor(RGB(255,0,0));

m_Graph.SetElementLinetype(0);

m_Graph.SetElementWidth(1);

m_Graph.SetElementPointColor(RGB(0,0,255);

m_Graph.SetElementPointSymbol(3);

m_Graph.SetElementSolidPoint(TRUE);

// Allocate a new element: Element-1

m_Graph.AddElement();

m_Graph.SetElementLineColor(RGB(0,255,0));

m_Graph.SetElementwidth(1);

m_Graph.SetElementLinetype(2);

// Allocate a new element: Element-2

m_Graph.AddElement();

m_Graph.SetElementLineColor(RGB(0,0,255));

m_Graph.SetElementLinetype(3);

// Now change again the properties of Element-1

m_Graph.SetElement(1);

m_Graph.SetElementColor (RGB(0,0,255)); ...

Load Data int the Graph Elements

double y;

for (int i = 0; i < NumberOfElements; i++) {

     for (int x = 0; x < NumberOfPoints; x++) {

            y = (double)rand() / RAND_MAX * 10.0;

            y = y / 3 + 10.0 / 2 * i + 1;

            m_Graph.PlotXY(x, y, i);// or PlotY(double data, long ElementID)

             //不同的i保證了在一個控件内畫出NumberOfElements條獨立的曲線

     }

本文來自CSDN部落格,轉載請标明出處:http://blog.csdn.net/ssh_2008/archive/2009/09/02/4512137.aspx

繼續閱讀