Экспертная система Delphi.int.ru

Сообщество программистов
Общение, помощь, обмен опытом

Логин:
Пароль:
Регистрация | Забыли пароль?

Delphi.int.ru Expert

Другие разделы портала

Переход к вопросу:

#   

Статистика за сегодня:  


Лучшие эксперты

Подробнее »



Вопрос # 1 870

/ вопрос открыт /

Здравствуйте!
У меня к вам вопрос: можно ли компонент TListBox сделать прозрачным, только чтобы все что в нем писалось было видно?
Заранее спасибо!

IlluminatI Вопрос ожидает решения (принимаются ответы, доступен мини-форум)

Вопрос задал: IlluminatI (статус: 2-ой класс)
Вопрос отправлен: 2 сентября 2008, 20:25
Состояние вопроса: открыт, ответов: 1.

Ответ #1. Отвечает эксперт: Feniks

Здравствуйте, IlluminatI!
Держите в Приложении новый компонент TransparentListBox, потомок от стандартного TListBox. Возможно он вам поможет. :-D

P.S. Желаю удачи.

Приложение:
  1. unit TransparentListBox;
  2.  
  3. (*
  4. *
  5. * Written by Walter Irion (CIS 114254, 2455) after the THotSpot
  6. * sample component that Arne Sch?pers presented in the German
  7. * c''t magazine (issue 6/1996, pp. 286 ff.).
  8. *
  9. * TTransparentListBox is far from being a universal solution:
  10. * it does not prevent Windows'' scrolling mechanism from
  11. * shifting the background along with scrolled listbox lines.
  12. * Moreover, the scroll bar remains hidden until the keyboard
  13. * is used to change the selection, and the scroll buttons
  14. * become visible only when clicked.
  15. *
  16. * To break it short: TTransparentListBox is only suitable
  17. * for non-scrolling lists.
  18. *
  19. * In fact it must be possible to write a listbox component
  20. * that handles scrolling correctly. But my essays to intercept
  21. * EM_LINESCROLL messages were fruitles, even though I tried
  22. * subclassing via WndProc.
  23. *
  24. * A solution for transparent TEdit and TMemo controls is
  25. * introduced in issue 9/1996 of the c''t magazine, again
  26. * by Arne Sch?pers. But these are outright monsters with
  27. * wrapper windows to receive notification messages as well
  28. * as so-called pane windows that cover the actual control''s
  29. * client area and display its content.
  30. *
  31. * Previous issues of the c''t magazine can be ordered from:
  32. *
  33. * c''t-Kopierservice
  34. * Helstorfer Str. 7
  35. * 30625 Hannover, Germany
  36. *
  37. * They expect a crossed cheque amounting to DM 14,00
  38. * to be included with your order, but I don''t know about
  39. * international orders.
  40. *
  41. *)
  42.  
  43. interface
  44.  
  45. uses
  46. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  47. StdCtrls;
  48.  
  49. type
  50. TTransparentListBox = class(TListBox)
  51. private
  52. { Private declarations }
  53. protected
  54. { Protected declarations }
  55. procedure CreateParams(var Params: TCreateParams); override;
  56. procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
  57. procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
  58. override;
  59. public
  60. { Public declarations }
  61. constructor Create(AOwner: TComponent); override;
  62. procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  63. published
  64. { Published declarations }
  65. property Style default lbOwnerDrawFixed;
  66. property Ctl3D default False;
  67. property BorderStyle default bsNone;
  68. end;
  69.  
  70. procedure Register;
  71.  
  72. implementation
  73.  
  74. constructor TTransparentListBox.Create(AOwner: TComponent);
  75. begin
  76. inherited Create(AOwner);
  77. Ctl3D := False;
  78. BorderStyle := bsNone;
  79. Style := lbOwnerDrawFixed; // changing it to lbStandard results
  80. // in loss of transparency
  81. end;
  82.  
  83. procedure TTransparentListBox.CreateParams(var Params: TCreateParams);
  84. begin
  85. inherited CreateParams(Params);
  86. Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
  87. end;
  88.  
  89. procedure TTransparentListBox.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
  90. begin
  91. Msg.Result := 1; // Prevent background from getting erased
  92. end;
  93.  
  94. procedure TTransparentListBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  95. var
  96. tlbVisible: Boolean;
  97. begin
  98. tlbVisible := (Parent <> nil) and IsWindowVisible(Handle); // Check for
  99. visibility
  100. if tlbVisible then ShowWindow(Handle, SW_HIDE); // Hide-Move-Show
  101. strategy...inherited SetBounds(ALeft, ATop, AWidth, AHeight); // ... to prevent
  102. background...if tlbVisible then ShowWindow(Handle, SW_SHOW); // ... from
  103. getting copied
  104. end;
  105.  
  106. procedure TTransparentListBox.DrawItem(Index: Integer; Rect: TRect;
  107. State: TOwnerDrawState);
  108. var
  109. FoundStyle: TBrushStyle;
  110. R: TRect;
  111. begin
  112. FoundStyle := Canvas.Brush.Style; // Remember the brush style
  113.  
  114. R := Rect; // Adapt coordinates of drawing
  115. rect...MapWindowPoints(Handle, Parent.Handle, R, 2); // ... to parent''s coordinate
  116. system
  117. InvalidateRect(Parent.Handle, @R, True); // Tell parent to redraw the
  118. item Position
  119. Parent.Update; // Trigger instant redraw
  120. (required)
  121.  
  122. if not (odSelected in State) then
  123. begin // If an unselected line is being
  124. handled
  125. Canvas.Brush.Style := bsClear; // use a transparent background
  126. end
  127. else
  128. begin // otherwise, if the line needs to be
  129. highlighted,
  130. Canvas.Brush.Style := bsSolid; // some colour to the brush is
  131. essential
  132. end;
  133.  
  134. inherited DrawItem(Index, Rect, State); // Do the regular drawing and give
  135. component users...
  136. // ... a chance to provide an
  137. OnDrawItem handler
  138.  
  139. Canvas.Brush.Style := FoundStyle; // Boy-scout rule No. 1: leave site as
  140. you found it
  141. end;
  142.  
  143. procedure Register;
  144. begin
  145. RegisterComponents('Samples', [TTransparentListBox]);
  146. end;
  147.  
  148. end.


Ответ отправил: Feniks (статус: Бакалавр)
Время отправки: 3 сентября 2008, 11:33


Мини-форум вопроса

Всего сообщений: 1; последнее сообщение — 3 сентября 2008, 18:04; участников в обсуждении: 1.
IlluminatI

IlluminatI (статус: 2-ой класс), 3 сентября 2008, 18:04 [#1]:

Спасибо! А как это чудо установить?))

Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.

Версия движка: 2.6+ (26.01.2011)
Текущее время: 22 февраля 2025, 11:35
Выполнено за 0.03 сек.