1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
private: void drawNode(Node^ myNode, int level)
{ // 1 Declare variables
int x;
int nodeDistance = nodeLength + arrowLength;
// 2 calculate x coord of the corner
x = headX+(nodeDistance * level);
// 3 Create a rectangle
Drawing::Rectangle nodeRect(x,headY,nodeLength,nodeHeight);
// 4 Draw the Node
g->FillRectangle(whiteBrush,nodeRect);
g->DrawRectangle(blackPen,nodeRect);
g->DrawLine(blackPen,x+nodeLength-15,headY,x+nodeLength-15,headY+nodeHeight);
// 5 Draw next
if (myNode->next) // 5.1 if next Node draw arrow
{
g->DrawLine(blackPen,x+nodeLength,headY+12,x+nodeDistance,headY+12);
g->DrawLine(blackPen,x+nodeLength+25,headY+7,x+nodeDistance,headY+12);
g->DrawLine(blackPen,x+nodeLength+25,headY+17,x+nodeDistance,headY+12);
}
else // 5.2 if there is no next Node draw null pointer
g->DrawLine(blackPen,x+nodeLength-15,headY,x+nodeLength,headY+25);
// 6 Draw nodeData
g->DrawString(myNode->nodeData.ToString(),arialFont,blackBrush,x+5,headY+5);
// 7 Label head node
g->DrawString("Head",arialFont,blackBrush,headX,headY-20);
// 8 Increment level
level++;
// 9 If next points to a Node go there and draw it
if (myNode->next)
drawNode(myNode->next, level);
}
private: System::Void btnInsert_Click(System::Object^ sender, System::EventArgs^ e) {
if (Node::nodeCount < 7)
{
Node^ temp = gcnew Node;
temp->next = head;
head = temp;
drawNode(head, 0);
}
else
{
MessageBox::Show("Only 7 nodes allowed.");
btnInsert->Enabled = false;
btnDelete->Enabled = true;
}
}
private: System::Void btnDelete_Click(System::Object^ sender, System::EventArgs^ e) {
//DELETEING CODE HERE
}
private: System::Void btnClear_Click(System::Object^ sender, System::EventArgs^ e) {
//CLEARING LIST CODE HERE
}
};
}
|