鼠标在wxStaticBitmap上面移动时,想实时显示该点的坐标和颜色值,
看看下面的代码吧,很容易实现:
void testwx1Frame::OnStaticBitmap1Move(wxMouseEvent& event)
{
int X=event.GetX();
int Y=event.GetY();
//---------------------------------
wxClientDC dc(StaticBitmap1);
wxColor xycolor(0,0,0);
dc.GetPixel(X,Y,&xycolor);
wxString rgbs=xycolor.GetAsString(wxC2S_CSS_SYNTAX);
//----------------------------------
this->SetTitle(rgbs);
TextCtrl1->SetLabel(wxString::Format(wxT("X:%i,Y:%i,Red: %i"),X,Y,xycolor.Red()));
}
当然不要忘记添加头文件,否则会出
error: 'wxClientDC' was not declared in this scope|.....
#include <wx/dcclient.h>
#include <wx/colour.h>
#include <wx/bitmap.h>
有图有真相: