Author: Tomas Rutkauskas
How to disable the transparent part of a TSpeedButton from clicking
Answer:
1 2 procedure TMFSpeedButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:
3 Integer);
4 var5 ScreenDC: HDC;
6 Transp, Bits: Boolean;
7 begin8 inherited MouseDown(Button, Shift, X, Y);
9 if (Button = mbLeft) and Enabled then10 begin11 Bits := False;
12 Transp := False;
13 ScreenDC := GetDC(0);
14 try15 {Transparent color is color of form background. Test for True Color 24bit16 or more, because on lower color depth the color is blended, so it works only17 on true color for some colors. If it is for example clBlack, it works18 on everything}19 Bits := GetDeviceCaps(ScreenDC, BITSPIXEL) >= 24;
20 {test for desired color}21 Transp := GetPixel(ScreenDC, Mouse.CursorPos.x, Mouse.CursorPos.Y) =
22 $0094ADBD;
23 finally24 ReleaseDC(0, ScreenDC);
25 end;
26 {leave procedure if test for transp. color was successful}27 if Transp and Bits then28 Exit;
29 ifnot FDown then30 begin31 FState := bsDown;
32 Invalidate;
33 end;
34 FDragging := True;
35 end;
36 end;