⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 C++Builder程序员编程手记《配书光盘》
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
AnsiString ListItem[20]={"项目1","项目2","项目3","项目4","项目5","项目6","项目7","项目8","项目9","项目10",
                            "项目11","项目12","项目13","项目14","项目15","项目16","项目17","项目18","项目19","项目20"};
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  RadioButton1->Checked=true;
  ListBox1->Style=lbStandard;
  for(int i=0;i<20;i++)
    ListBox1->Items->Add(ListItem[i]);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CheckBox2Click(TObject *Sender)
{
  ListBox1->MultiSelect=CheckBox2->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::CheckBox1Click(TObject *Sender)
{
  if(CheckBox1->Checked)
     ListBox1->Columns=2;
  else
      ListBox1->Columns=0;
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::RadioButton2Click(TObject *Sender)
{
  ListBox1->Style=lbOwnerDrawVariable;
  ListBox1->Update();
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::RadioButton1Click(TObject *Sender)
{
  ListBox1->Style=lbStandard;  
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ListBox1MeasureItem(TWinControl *Control,
      int Index, int &Height)
{
  Height = ListBox1->Canvas->TextHeight("Wg") +4;
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ListBox1DrawItem(TWinControl *Control,
      int Index, TRect &Rect, TOwnerDrawState State)
{
  TCanvas *pCanvas=ListBox1->Canvas;

  ListBox1->Canvas->FillRect(Rect);
  ImageList1->Draw(pCanvas,Rect.Left+2,Rect.Top+2,Index, true);
  ListBox1->Canvas->TextOut(ImageList1->Width+Rect.Left+4,Rect.Top+2, ListBox1->Items->Strings[Index].c_str());
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ListBox1Click(TObject *Sender)
{
    if(!ListBox1->MultiSelect||ListBox1->SelCount>0&&ListBox1->SelCount<2)
      StaticText1->Caption=ListBox1->Items->Strings[ListBox1->ItemIndex];
    else if(ListBox1->SelCount>=2)
      StaticText1->Caption="选中了"+IntToStr(ListBox1->SelCount)+"个";
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -