📄 listview.cpp
字号:
#include "Stdafx.h"
#using <mscorlib.dll>
using namespace System;
// required dlls for WinForms
#using "System.dll"
#using "System.Windows.Forms.dll"
#using "System.Drawing.dll"
// required namespaces for WinForms
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Drawing;
__gc class WinForm: public Form
{
private:
Windows::Forms::ImageList* pImageList1;
Windows::Forms::ListView* pListView1;
Windows::Forms::ImageList* pImageList2;
Windows::Forms::Button* pButton1;
Windows::Forms::RadioButton* pRadioButton1;
Windows::Forms::RadioButton* pRadioButton2;
Windows::Forms::RadioButton* pRadioButton3;
Windows::Forms::RadioButton* pRadioButton4;
Windows::Forms::ColumnHeader* pColumnHeader1;
Windows::Forms::ColumnHeader* pColumnHeader2;
Windows::Forms::ColumnHeader* pColumnHeader3;
public:
WinForm()
{
InitForm();
}
void ~WinForm()
{
// Form is being destroyed:: Do any necessary clean-up here::
Form::Dispose();
}
void InitForm()
{
// Setup controls here
String* tempObjarr[] = new String*[3];
tempObjarr[0] = S"01";
tempObjarr[1] = S"张军";
tempObjarr[2] = S"20";
System::Windows::Forms::ListViewItem* pListViewItem1 = new System::Windows::Forms::ListViewItem(tempObjarr, -1, System::Drawing::SystemColors::WindowText, System::Drawing::SystemColors::Window, new System::Drawing::Font("宋体", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, ((System::Byte)(134))));
pListViewItem1->set_ImageIndex(0);
tempObjarr[0] = S"02";
tempObjarr[1] = S"张明";
tempObjarr[2] = S"21";
System::Windows::Forms::ListViewItem* pListViewItem2 = new System::Windows::Forms::ListViewItem(tempObjarr, -1, System::Drawing::SystemColors::WindowText, System::Drawing::SystemColors::Window, new System::Drawing::Font("宋体", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, ((System::Byte)(134))));
pListViewItem2->set_ImageIndex(1);
pImageList1 = new System::Windows::Forms::ImageList();
pListView1 = new System::Windows::Forms::ListView();
pImageList2 = new System::Windows::Forms::ImageList();
pColumnHeader1 = new System::Windows::Forms::ColumnHeader();
pColumnHeader2 = new System::Windows::Forms::ColumnHeader();
pColumnHeader3 = new System::Windows::Forms::ColumnHeader();
pButton1 = new System::Windows::Forms::Button();
pRadioButton1 = new System::Windows::Forms::RadioButton();
pRadioButton2 = new System::Windows::Forms::RadioButton();
pRadioButton3 = new System::Windows::Forms::RadioButton();
pRadioButton4 = new System::Windows::Forms::RadioButton();
SuspendLayout();
//
// pImageList1
//
pImageList1->ColorDepth = System::Windows::Forms::ColorDepth::Depth8Bit;
pImageList1->ImageSize = System::Drawing::Size(32, 32);
pImageList1->TransparentColor = System::Drawing::Color::Transparent;
pImageList1->Images->Add(Image::FromFile(S"ImagesBig\\new.bmp"));
pImageList1->Images->Add(Image::FromFile(S"ImagesBig\\open.bmp"));
//
// pListView1
//
pListView1->AllowColumnReorder = true;
System::Windows::Forms::ColumnHeader* Col[]=new System::Windows::Forms::ColumnHeader*[3];
Col[0]=pColumnHeader1;
Col[1]=pColumnHeader2;
Col[2]=pColumnHeader3;
pListView1->Columns->AddRange(Col);
System::Windows::Forms::ListViewItem* Item[]=new System::Windows::Forms::ListViewItem*[2];
Item[0]= pListViewItem1;
Item[1]= pListViewItem2;
pListView1->Items->AddRange(Item);
pListView1->LabelEdit = true;
pListView1->LargeImageList = pImageList1;
pListView1->Name = "pListView1";
pListView1->Size = System::Drawing::Size(288, 168);
pListView1->SmallImageList = pImageList2;
pListView1->TabIndex = 0;
pListView1->View = System::Windows::Forms::View::Details;
//
// pImageList2
//
pImageList2->ColorDepth = System::Windows::Forms::ColorDepth::Depth8Bit;
pImageList2->ImageSize =System::Drawing::Size(16, 16);
pImageList2->TransparentColor = System::Drawing::Color::Transparent;
pImageList2->Images->Add(Image::FromFile(S"ImagesSmall\\new.bmp"));
pImageList2->Images->Add(Image::FromFile(S"ImagesSmall\\open.bmp"));
//
// pColumnHeader1
//
pColumnHeader1->Text = "序号";
//
// pColumnHeader2
//
pColumnHeader2->Text = "姓名";
//
// pColumnHeader3
//
pColumnHeader3->Text = "年龄";
//
// Form1
//
AutoScaleBaseSize =System::Drawing::Size(6, 14);
ClientSize =System::Drawing::Size(292, 266);
pButton1->Location = System::Drawing::Point(104, 240);
pButton1->Name = "button1";
pButton1->TabIndex = 1;
pButton1->Text = "退出";
pButton1->Click += new System::EventHandler(this,button1_Click);
//
// button1
//
pButton1->Location =System::Drawing::Point(104, 240);
pButton1->Name = "button1";
pButton1->TabIndex = 1;
pButton1->Text = "退出";
pButton1->Click += new System::EventHandler(this,button1_Click);
//
// radioButton1
//
pRadioButton1->Location =System::Drawing::Point(24, 176);
pRadioButton1->Name = "radioButton1";
pRadioButton1->Size = System::Drawing::Size(72, 24);
pRadioButton1->TabIndex = 2;
pRadioButton1->Text = "大图标";
pRadioButton1->CheckedChanged += new System::EventHandler(this,CheckChanged);
//
// radioButton2
//
pRadioButton2->Location =System::Drawing::Point(96, 176);
pRadioButton2->Name = "radioButton2";
pRadioButton2->Size = System::Drawing::Size(64, 24);
pRadioButton2->TabIndex = 3;
pRadioButton2->Text = "小图标";
pRadioButton2->CheckedChanged += new System::EventHandler(this,CheckChanged);
//
// radioButton3
//
pRadioButton3->Location =System::Drawing::Point(224, 176);
pRadioButton3->Name = "radioButton3";
pRadioButton3->Size = System::Drawing::Size(48, 24);
pRadioButton3->TabIndex = 4;
pRadioButton3->Text = "列表";
pRadioButton3->CheckedChanged += new System::EventHandler(this,CheckChanged);
//
// radioButton4
//
pRadioButton4->Location =System::Drawing::Point(160, 176);
pRadioButton4->Name = "radioButton4";
pRadioButton4->Size = System::Drawing::Size(56, 24);
pRadioButton4->TabIndex = 5;
pRadioButton4->Text = "报表";
pRadioButton4->CheckedChanged += new System::EventHandler(this,CheckChanged);
Controls->Add(pRadioButton1);
Controls->Add(pRadioButton2);
Controls->Add(pRadioButton3);
Controls->Add(pRadioButton4);
Controls->Add(pButton1);
Controls->Add(pListView1);
Name = "Form1";
Text = "Form1";
// Setup controls here
}
private:
void button1_Click(Object *Sender,EventArgs *s)
{
Close ();
}
void CheckChanged(Object *Sender,EventArgs *s)
{
if( pRadioButton1->Checked )
pListView1->View =View::LargeIcon ;
if( pRadioButton2->Checked )
pListView1->View =View::SmallIcon ;
if( pRadioButton3->Checked )
pListView1->View =View::List ;
if(pRadioButton4->Checked )
pListView1->View =View::Details ;
}
};
void main()
{
// This line creates an instance of WinForm, and
// uses it as the Main Window of the application::
Application::Run(new WinForm());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -