鼠标左键按下不放移动指针问题
C++builder6中,怎样实现运行时在一个控件上按下鼠标左键不放,将指针移动到其他控件,另一控件也响应OnMouseDown事件?
例如:
窗体Form1中放置两个Panel控件Panel1、Panel2。
当鼠标在Panel1上按下时改变颜色,代码:
void __fastcall TForm1::Panel1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Panel1->Color==clWhite)
Panel1->Color=clSkyBlue;
else if(Panel1->Color==clSkyBlue)
Panel1->Color=clWhite;
}
鼠标左键保持按下状态,指针移动到Panel2,让Panel2也响应OnMouseDown事件,改变颜色。
注:窗体中有20个小Panel,一个一个点太麻烦。
[解决办法]
本帖最后由 ccrun 于 2012-09-21 12:33:31 编辑 给你个简单实现,自己再加工吧。
.h文件中:
private:// User declarations
bool m_bFlags[25][8];
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
StringGrid1->Font->Name = "宋体";
StringGrid1->Font->Size = 9;
StringGrid1->Options = StringGrid1->Options >> goRowSizing >> goColSizing
>> goRowMoving >> goColMoving >> goEditing;
StringGrid1->Width = 560;
StringGrid1->Height = 175;
StringGrid1->RowCount = 8;
StringGrid1->ColCount = 25;
StringGrid1->DefaultColWidth = 20;
StringGrid1->DefaultRowHeight = 20;
StringGrid1->ColWidths[0] = 45;
LPTSTR lpWeeks[] =
{
"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
};
for (int i = 0; i < 7; i++)
StringGrid1->Cells[0][i + 1] = lpWeeks[i];
for (int i = 0; i < 24; i++)
StringGrid1->Cells[i + 1][0] = String().sprintf(TEXT("%02d"), i);
memset(m_bFlags, 0x0, sizeof(m_bFlags));
}
// ---------------------------------------
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (ACol == 0
[解决办法]
ARow == 0) return;
if (State.Contains(gdSelected))
m_bFlags[ACol][ARow] = !m_bFlags[ACol][ARow];
if (m_bFlags[ACol][ARow])
StringGrid1->Canvas->Brush->Color = clRed;
else
StringGrid1->Canvas->Brush->Color = clWhite;
StringGrid1->Canvas->FillRect(Rect);
}