代码:
void __fastcall TForm1::createButtonCtrl(TImage *image ,String ctrlName ,String actionName)
{
int i,picX ,picY;
for(i =0 ; i < this->ControlCount ; i++)
{
if(controls[i].ctrlName == ctrlName) //循环查找,找到ctrlName控件
{
break;
}
}
image->Width = controls[i].width;
image->Height = controls[i].height;
image->Left = controls[i].formPos.x;
image->Top = controls[i].formPos.y; //设置按钮的位置 和 大小
if(actionName == "normal") //判断当前需要获取的事件按钮
{
if(!controls[i].hasNormal)
return;
picX = controls[i].normal.x; //获取普通按钮效果图在整个图片的位置
picY = controls[i].normal.y;
}
else if(actionName =="mouseUp")
{
if(!controls[i].hasMouseUp)
return;
picX = controls[i].mouseUp.x;
picY = controls[i].mouseUp.y;
}
else if(actionName == "mouseDown")
{
if(!controls[i].hasMouseDown)
return;
picX = controls[i].mouseDown.x;
picY = controls[i].mouseDown.y;
}
else if(actionName == "disable")
{
if(!controls[i].hasDisable)
return;
picX = controls[i].disable.x;
picY = controls[i].disable.y;
}
else
{
if(!controls[i].hasFocus)
return;
picX = controls[i].focus.x;
picY = controls[i].focus.y;
}
////获取图片
TRect rect0,rect1; //在整个图片中获取指定的效果图
rect0.left = picX;
rect0.top = picY;
rect0.right = image->Width + picX;
rect0.Bottom = image->Height + picY;
rect1.left = 0;
rect1.top = 0;
rect1.right = image->Width ;
rect1.Bottom = image->Height;
image->Picture->Bitmap->Height = image->Height;
image->Picture->Bitmap->Width = image->Width;
//通过内存拷贝获取
image->Picture->Bitmap->Canvas->CopyRect(rect1,this->LoginDlgBG->Canvas,rect0);
}
上面的代码很简单,同时也很好的说明了一个问题,图片是可以代替按钮来使用的,主要有几种情况:当按钮为普通的状态时,只要获取标识为"normal"的效果图片,当鼠标放在按控件上时就获取标识为"mouseUp"的效果图片,当鼠标按下时就获取标识为"mouseDown"的效果图片,等等,根据自己的需要可以定义很多的事件图片,就是这么简单。 完成后的效果图:
图三:完成后的效果图
至于换肤,那只是美工人员的事情了,多做一些皮肤吧! |