请教一下 VCL控件制作的问题

likeyrain 2009-01-19 11:10:15
H头文件
//---------------------------------------------------------------------------

#ifndef MyPanelH
#define MyPanelH

//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <ExtCtrls.hpp>
#include <Buttons.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------


//typedef void __fastcall (__closure *MyWM_LBUTTONUP)(System::TObject* Sender);

class PACKAGE TMyPanel : public TPanel
{
private:
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TImage *Image1;
TSpeedButton *SpeedButton1;
TSpeedButton *SpeedButton2;
TSpeedButton *SpeedButton3;
TNotifyEvent FSp1OnClick;
protected:

public:
__fastcall TMyPanel(TComponent* Owner);

__published:

};
//---------------------------------------------------------------------------
#endif


CPP文件
//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "MyPanel.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TMyPanel *)
{
new TMyPanel(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMyPanel::TMyPanel(TComponent* Owner)
: TPanel(Owner)
{
TImage *Image1 = new TImage(this);
Image1->Parent = this;
Image1->Width = 25;
Image1->Height = 25;
Image1->Top = this->Top;
Image1->Left = this->Left;
Image1->Picture->LoadFromFile("C:\\Documents and Settings\\Administrator\\桌面\\bmp\\1.bmp");

// (0,18,0,fpDefault,TFontStylesBase[fsBold],GB2312_CHARSET,"宋体");
TLabel *Label1 = new TLabel(this);
Label1->Parent = this;
Label1->Top = this->Top+8;
Label1->Left = this->Left+30;
Label1->Font->Style = Label1->Font->Style<< fsBold;
Label1->Font->Size = 11;
Label1->Font->Charset = GB2312_CHARSET;
Label1->Font->Name = "宋体";
Label1->Caption = "袁肇斌";

TLabel *Label2 = new TLabel(this);
Label2->Parent = this;
Label2->Top = this->Top+30;
Label2->Left = Label1->Left;
Label2->Font->Style = Label2->Font->Style<< fsBold;
Label2->Font->Size = 10;
Label2->Font->Charset = GB2312_CHARSET;
Label2->Font->Name = "宋体";
Label2->Font->Color = clBlue;
Label2->Caption = "83380000041";

TLabel *Label3 = new TLabel(this);
Label3->Parent = this;
Label3->Top = this->Top+45;
Label3->Left = Label1->Left;
// Label3->Font->Style = Label3->Font->Style<< fsBold;
Label3->Font->Size = 10;
Label3->Font->Charset = GB2312_CHARSET;
Label3->Font->Name = "宋体";
Label3->Caption = "时间: 2009-01-18";

TLabel *Label4 = new TLabel(this);
Label4->Parent = this;
Label4->Top = this->Top+60;
Label4->Left = Label1->Left;
// Label4->Font->Style = Label4->Font->Style<< fsBold;
Label4->Font->Size = 10;
Label4->Font->Charset = GB2312_CHARSET;
Label4->Font->Name = "宋体";
Label4->Caption = "时长: 18:21";

TSpeedButton *SpeedButton1 = new TSpeedButton(this);
SpeedButton1->Parent = this;
SpeedButton1->Height= 25;
SpeedButton1->Width = 25;
SpeedButton1->Top = this->Top +20;
SpeedButton1->Left = Label2->Left +Label2->Width +10;
SpeedButton1->Flat= 1;
// SpeedButton1->OnClick =Sp1Execute;
SpeedButton1->Glyph->LoadFromFile("C:\\Documents and Settings\\Administrator\\桌面\\bmp\\+.bmp");

TSpeedButton *SpeedButton2 = new TSpeedButton(this);
SpeedButton2->Parent = this;
SpeedButton2->Height= 25;
SpeedButton2->Width = 25;
SpeedButton2->Top = SpeedButton1->Top;
SpeedButton2->Left = SpeedButton1->Left +SpeedButton1->Width;
SpeedButton2->Flat= SpeedButton1->Flat;
SpeedButton2->Glyph->LoadFromFile("C:\\Documents and Settings\\Administrator\\桌面\\bmp\\-.bmp");

TSpeedButton *SpeedButton3 = new TSpeedButton(this);
SpeedButton3->Parent = this;
SpeedButton3->Height= 25;
SpeedButton3->Width = 25;
SpeedButton3->Top = SpeedButton1->Top;
SpeedButton3->Left = SpeedButton2->Left +SpeedButton2->Width;
SpeedButton3->Flat= SpeedButton1->Flat;
SpeedButton3->Glyph->LoadFromFile("C:\\Documents and Settings\\Administrator\\桌面\\bmp\\P.bmp");

this->Height = 80;
this->Width = 210;
this->Color =clWhite;
this->Caption = " ";
}
//---------------------------------------------------------------------------
namespace Mypanel
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMyPanel)};
RegisterComponents("Standard", classes, 0);
}
}
//---------------------------------------------------------------------------


我这样继承Panel,里面放上几个控件,怎样把控的属性和事件开放出来啊?
主要是把Image的Picture,Label的Captionn属性和Button的Oclick事件
...全文
87 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
likeyrain 2009-01-22
  • 打赏
  • 举报
回复
试验功能
真的很感谢
的之前是用DELPHI的,因工作,现在刚接触BCB,语法真的有些不懂,不好意思!!
likeyrain 2009-01-22
  • 打赏
  • 举报
回复
我现在去试试
谢谢!!
hemiya 2009-01-21
  • 打赏
  • 举报
回复

// 还要加上析构函数
public:
__fastcall ~TMyPanel();

//--------
// .cpp
__fastcall TMyPanel::~TMyPanel()
{
delete Label1;
delete Label2;
delete Label3;
delete Label4;
delete SpeedButton1;
delete SpeedButton2;
delete SpeedButton3;
}

是你自己c++语法没搞懂,不是控件怎么写的问题.
hemiya 2009-01-21
  • 打赏
  • 举报
回复

// TLabel *Label1 = new TLabel(this); 此处错误
// Label1,Label2,Label3,Label4,SpeedButton1 ,SpeedButton2,SpeedButton3都一样相同的错误.

Label1 = new TLabel(this);// 这样写

Label1->Parent = this;
Label1->Top = this->Top+8;
Label1->Left = this->Left+30;
Label1->Font->Style = Label1->Font->Style < < fsBold;
Label1->Font->Size = 11;
Label1->Font->Charset = GB2312_CHARSET;
Label1->Font->Name = "宋体";
Label1->Caption = "袁肇斌";
likeyrain 2009-01-21
  • 打赏
  • 举报
回复
怎么还是没有人理我呢?是很难还是很白痴啊。。。
likeyrain 2009-01-20
  • 打赏
  • 举报
回复
定义是可以定义,编译也没有问题,但引用的时候报错。也就是我安装这个控件后,改变它的SetSubCaption值时就报错。
hemiya 2009-01-19
  • 打赏
  • 举报
回复
写到
__published:

__published:
__property String SubCaption = {read=GetSubCaption, write=SetSubCaption};
private:
String __fastcall GetSubCaption(){return Label->Caption;]
void __fastcall SetSubCaption(const String &str){Label->Caption = str;}
likeyrain 2009-01-19
  • 打赏
  • 举报
回复
很难吗?怎么没人理我呢

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧