ImageList ( Win32 ) (, ), , . , , , ImageList.
ImageList . ImageList ImageList. ( ), , .
, , , . , , \Program Files\Common Files\Borland Shared\Images\Buttons.
, . , , , , . , , . : Bitmap dimensions for are greater then imagelist dimensions. Separate into separate bitmaps? ( . ?). , . . . , , , .
. , , .., . , .
, , : . clNone.
, , , .. :
TreeView ( ) | Win32 | Windows 95/98/2000 |
Outline ( ) | Win3.1 | Windows 3.x |
ListView ( Windows 95) | Win32 | Windows |
|
|
TreeView Outline , . . TreeView , Outline. TreeView.
TreeView, , Items. Items TTreeNodes . Items->Item[int Index]. , TreeView1> Items>Item[0] 0 ( ). TTreeNodes, .
.
.
1. ( Windows), C++Builder 6, , TREEVIEW_1 .
2. TreeView1 Win32 .
3. TreeView1 ( ). Items . : . .
. , , .
. , .
.
. , , . . ,
-11
-12
. , . , , . ( , ), ImageList. Images TreeView. . -1 ( ), . - , . . , -, , ImageList, StateImages TreeView.
|
|
4. ImageList1 ImageList2. 14 , 7 .
5. TreeView1. Images ImageList1, StateImages ImageList2.
6. , 3 . , - 0. , 0, 1, 1, 2, 3, 2 ..
7. Button1 . Close();.
8. . .
. TTreeNodes.
:
Add(TTreeNode* Node, const System::AnsiString S) | S , Node |
AddFirst(TTreeNode* Node, const System::AnsiString S) | S , Node. - 1 |
Insert(TTreeNode* Node, const System::AnsiString S) | S Node -. 1 |
AddChild(TTreeNode* Node, const System::AnsiString S) | S Node |
AddChildFirst(TTreeNode* Node, const System::AnsiString S) | S Node. - 1 |
. , , :
AddObject(TTreeNode* Node, const System::AnsiString S, void* Ptr) | S Ptr , Node |
AddObjectFirst(TTreeNode* Node, const System::AnsiString S, void* Ptr) | S Ptr - , Node. - 1 |
InsertObject(TTreeNode* Node, const System::AnsiString S, void* Ptr) | S Ptr Node . - 1 |
AddChildObject(TTreeNode* Node, const System::AnsiString S, void* Ptr) | S - Ptr Node |
AddChildObjectFirst(TTreeNode* Node, const System::AnsiString S, void* Ptr) | S Ptr - Node. - 1 |
.
1. . TREEVIEW_2. TreeView1, Button1 ( ) Button2 ( ).
2. :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TreeView1->Items->Clear();
TreeView1->Items->Add(NULL," ");
|
|
TreeView1->Items->AddChild(TreeView1->Items->Item[0],"");
TreeView1->Items->AddChild(TreeView1->Items->Item[0],"");
TreeView1->Items->Add(TreeView1->Items->Item[0]," ");
TreeView1->Items->AddChild(TreeView1->Items->Item[3],"");
TreeView1->Items->AddChild(TreeView1->Items->Item[1],"-11");
TreeView1->Items->AddChild(TreeView1->Items->Item[1],"-12");
}
3. . .
, , Text. , TreeView1->Items->Item[1]->Text ".
, , Data. , TreeView1->Items->Item[1]->Data.
: Clear(void), , Delete(TTreeNode* Node), Node -. , , .
, , . BeginUpdate ( ) EndUpdate ( ). , :
TreeView1->Items->BeginUpdate();
< >
TreeView1->Items->EndUpdate();
BeginUpdate , , E ndUpdate.
Count , , .. , .. Count 0, .
TreeView Selected. , . , , . , Selected NULL.
OnChanging ( ) OnChange . OnChanging TTreeNode* Node , , bool &AllowChange . AllowChange = false, . OnChange TTreeNode* Node . , .
TreeView . OnExpanding ( ) OnExpanded ( ). TTreeNode* Node . , OnExpanding bool &AllowExpansion, false, . OnCollapsing ( ) OnCollapsed ( ). , , , TTreeNode* Node , OnCollapsing bool &AllowCollapse, .
ReadOnly TreeView . , OnEditing OnEdited, ( OnEditing bool &AllowEdit ).
|
|
TreeView: ShowButtons, ShowLines, ShowRoot , , , , .
SortType . stNone, , . SortType stText, . Data ( SortType stData), Data ( SortType stBoth) .
OnCompare, TTreeNode*Node1 TTreeNode*Node2 , int &Compare, : , Node1 Node2, , , , Node1 Node2. , OnCompare :
OnCompare = -AnsiStrIComp(Node1->Text.c_str(),Node2->Text.c_str());
OnCompare SortType, stNone, (, ), SortType stNone. . SortType=stNone , OnCompare, .. , , . , SortType=stNone, SortType, stNone. OnCompare.
. , AlphaSort(void) SortType, OnCompare ( , AlphaSort ). AlphaSort SortType=stText , SortType=stText.
OnKeyDown OnKeyUp. OnKeyDown / OnKeyUp , , / , , , Shift, Alt Ctrl. , Sender, , , Key Shift. Key / . Shift , : ssShift, ssAlt, ssCtrl ( Shift, Alt, Ctrl ).
StatusBar ( Win32) , Windows. .
SimplePanel , . SimplePanel = true, , SimpleText. SimplePanel = false, , Panels. SizeGrip , .
TStatusPanels. , : Panels, StatusBar , Panels Editor. , . .
Text, . , . Width ().
|
|
Panels Items. , :
StatusBar1->Panels->Items[0]->Text= 1;
1 .
Count Panels. :
for(int i=0; i<StatusBar1->Panels->Count; i++)
{ StatusBar1->Panels->Items[i]->Text=;}
4. . StatusBar1, SimplePanel true. bool ShiftPressed OnChange, OnKeyDown, OnKeyUp:
void __fastcall TForm1::TreeView1Change(TObject *Sender, TTreeNode *Node)
{
String pn="",cn="";
TTreeNode*ParentNode=Node->Parent;
if(ParentNode) pn="..: "+ParentNode->Text;
TTreeNode*ChildNode=Node->getFirstChild();
if(ChildNode) cn="..:.."+ChildNode->Text;
Caption=pn+cn;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TreeView1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
TTreeNode*Node=TreeView1->Selected;
switch(Key)
{ case VK_DELETE:
if(Node)
{ StatusBar1->SimpleText=" : "+Node->Text;
Node->Delete();
} ShiftPressed=false; break;
case VK_INSERT:
if(Node)
{ StatusBar1->SimpleText=" : "+Node->Text;
TreeView1->Items->Insert(Node," ");
} ShiftPressed=false; break;
case VK_SHIFT:
ShiftPressed=true; return;
}
TreeView1->Update();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TreeView1KeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
ShiftPressed=false;
}
//---------------------------------------------------------------------------
5. , Insert Delete. .
( Drag&Drop), . , .
, , , TControl, C++Builder. .
DragMode, dmManual dmAutomatic. dmAutomatic () . dmManual () , . BeginDrag. , OnMouseDown, . - ( , ) BeginDrag.
. , , crNoDrop: . , , , DragCursor. crDrag, . , DragCursor , , .
, , . OnDragOver, , . , , , false Accept. true, .
Accept, OnDragOver, , . OnDragOver, , .
OnDragDrop . , . Source (-) X Y .
OnEndDrag, - . OnStartDrag, - . , .
.
6. DragMode TreeView1 dmAutomatic.
7. OnDragOver, OnDragDrop:
void __fastcall TForm1::TreeView1DragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept)
{
Accept=Source->ClassNameIs("TTreeView");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TreeView1DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(TreeView1->Selected==NULL) return;
THitTests HT=TreeView1->GetHitTestInfoAt(X,Y);
TNodeAttachMode AttachMode;
TTreeNode*Node=TreeView1->GetNodeAt(X,Y);
if(HT.Contains(htOnItem)) AttachMode=naAddChild;
else if(HT.Contains(htNowhere)) AttachMode=naAdd;
else if(HT.Contains(htOnIndent)) AttachMode=naInsert;
else return;
if(ShiftPressed)
{ StatusBar1->SimpleText=" : "+ TreeView1->Selected->Text;
Node->Assign(TreeView1->Selected);
}
else
{ StatusBar1->SimpleText=" : "+ TreeView1->Selected->Text;
TreeView1->Selected->MoveTo(Node,AttachMode);
}
TreeView1->Update();
}
8. , , Shift.
ListView Windows , , . ViewStyle, . : vsIcon , vsSmallIcon , vsList , vsReport .
ListView .
1. , LISTVIEW .
2. ImageList1 ImageList2. 11 , 2 .
3. ListView1 Win32 .
4. , Items. , ListView.
5. :
-11
-12
-11
-12
-13,
0, 1, 6, - ( ) 0 1. Tab.
6. ListView1. LargeImages SmallImages ImageList1, StateImages ImageList2.
7. Columns vsReport. ListView1 Columns ( List). , , . , , . Caption , 1, 2, 3, ImageIndex , 7, 8, 9, 10 . MinWidth MaxWidth . . MaxWidth 300. Width.
8. ViewStyle: vsIcon , vsSmallIcon , vsList , vsReport . . .
ListView1 , , vsIcon vsSmallIcon .
9. MainMenu1. , ImageList, , .. , , .
10. MainMenu1 Items. , MainMenu Items . ( MIcon), ( MSmallIcon), ( MList), ( MReport). () Caption, Name . , , . , .
11. , , GroupIndex RadioItem true, .
12. OnDragOver, OnDragDrop ListView1:
void __fastcall TForm1::MIconClick(TObject *Sender)
{
ListView1->ViewStyle=vsIcon;
MIcon->Checked=true;
ListView1->DragMode=dmAutomatic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MSmallIconClick(TObject *Sender)
{
ListView1->ViewStyle=vsSmallIcon;
MSmallIcon->Checked=true;
ListView1->DragMode=dmAutomatic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MListClick(TObject *Sender)
{
ListView1->ViewStyle=vsList;
MList->Checked=true;
ListView1->DragMode=dmAutomatic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MReportClick(TObject *Sender)
{
ListView1->ViewStyle=vsReport;
MReport->Checked=true;
ListView1->DragMode=dmAutomatic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1DragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept)
{
Accept=(Source=ListView1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
((TListView*)Sender)->Selected->Position=Point(X,Y);
}
13. . , ListView1 , , vsIcon vsSmallIcon .
14. Arrange:
void _fastcall Arrange(TListArrangement Code);
vsIcon vsSmallIcon. Code :
arAlignBottom | |
arAlignLeft | |
arAlignRight | |
arAlignTop | |
arDefault | ( ) |
arSnapToGrid |
:
ListView1->Arrange(arAlignTop);
, .