Advertisement
jpfassis

MyEditColor - Delphi

Apr 21st, 2020
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.32 KB | None | 0 0
  1. unit EditColor;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TMyEditColor = class(TEdit)
  11.   private
  12.     { Private declarations }
  13.     FBorder : TColor;
  14.     FBorderColor : TColor;
  15.     FBorderColorEnter: TColor;
  16.     procedure SetBorderColor(const Value: TColor);
  17.     procedure WMNCPaint( var msg: TWMNCPaint ); message WM_NCPAINT;
  18.     procedure CMMouseEnter(var msg: TMessage); message CM_MOUSEENTER;
  19.     procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
  20.     procedure CMEnter(var msg: TCMEnter); message CM_ENTER;
  21.     procedure CMExit(var msg: TCMExit); message CM_EXIT;
  22.     procedure SetBorderColorEnter(const Value: TColor);
  23.   public
  24.     constructor Create( aOwner: TComponent ); override;
  25.     property ParentColor default true;
  26.   published
  27.     property BorderColor : TColor read FBorderColor write SetBorderColor;
  28.     property BordColorEnter: TColor read FBorderColorEnter write SetBorderColorEnter;
  29.   end;
  30.  
  31. procedure Register;
  32.  
  33. implementation
  34.  
  35. procedure Register;
  36. begin
  37.   RegisterComponents('My Componentes', [TMyEditColor]);
  38. end;
  39.  
  40. { TPBLineEdit }
  41.  
  42. procedure TMyEditColor.CMEnter(var msg: TCMEnter);
  43. begin
  44. inherited;
  45.   FBorder := FBorderColorEnter;
  46.   SendMessage(Handle, WM_NCPAINT, 0, 0);
  47. end;
  48.  
  49. procedure TMyEditColor.CMExit(var msg: TCMExit);
  50. begin
  51. inherited;
  52.   FBorder := FBorderColor;
  53.   SendMessage(Handle, WM_NCPAINT, 0, 0);
  54. end;
  55.  
  56. procedure TMyEditColor.CMMouseEnter(var msg: TMessage);
  57. begin
  58. inherited;
  59.   FBorder := FBorderColorEnter;
  60.   SendMessage(Handle, WM_NCPAINT, 0, 0);
  61. end;
  62.  
  63. procedure TMyEditColor.CMMouseLeave(var msg: TMessage);
  64. begin
  65. inherited;
  66.   FBorder := FBorderColor;
  67.   SendMessage(Handle, WM_NCPAINT, 0, 0);
  68. end;
  69.  
  70. constructor TMyEditColor.Create(aOwner: TComponent);
  71. begin
  72.   inherited;
  73.   ParentColor := true;
  74. end;
  75.  
  76. procedure TMyEditColor.SetBorderColorEnter(const Value: TColor);
  77. begin
  78.   FBorderColorEnter := Value;
  79. end;
  80.  
  81. procedure TMyEditColor.SetBorderColor(const Value: TColor);
  82. begin
  83.   FBorderColor := Value;
  84.   FBorder := FBorderColor;
  85.   SendMessage(Handle, WM_NCPAINT, 0, 0);
  86. end;
  87.  
  88. procedure TMyEditColor.WMNCPaint(var msg: TWMNCPaint);
  89. var
  90.   DC: HDC;
  91.   BorderBrush: HBRUSH;
  92.   R: TRect;
  93. begin
  94. DC:= GetWindowDC(Handle);
  95. SetRect(R,0,0,Width,Height);
  96. BorderBrush:= CreateSolidBrush(FBorder);
  97. FrameRect(Dc, R, BorderBrush);
  98. DeleteObject(BorderBrush);
  99. InflateRect(R,-1,-1);
  100. end;
  101.  
  102. end.
  103.  
  104.  
  105.  
  106.  
  107. //somente desenha a borda inferior
  108. //procedure TMyEditColor.WMNCPaint(var msg: TWMNCPaint);
  109. //var
  110. //  cv: TCanvas;
  111. //  dc: HDC;
  112. //  r: TRect;
  113. //begin
  114. //  dc:= GetWindowDC( handle );
  115. //  SaveDC( dc );
  116. //  try
  117. //    cv:= TCanvas.Create;
  118. //    try
  119. //      cv.Handle := dc;
  120. //      cv.Lock;
  121. //      r:= Rect( 0, 0, Width, Height );
  122. //      With cv.Brush Do Begin
  123. //        Color := Self.Color;
  124. //        Style := bsSolid;
  125. //      End;
  126. //      cv.FrameRect( r );
  127. //      InflateRect( r, -1, -1 );
  128. //      cv.FrameRect( r );
  129. //      With cv.Pen Do Begin
  130. //        Color := FBorder;
  131. //        Style := psSolid;
  132. //        Width := 2;
  133. //      End;
  134. //      cv.MoveTo( r.Left, r.Bottom );
  135. //      cv.LineTo( r.right, r.Bottom );
  136. //    finally
  137. //      cv.Unlock;
  138. //      cv.free;
  139. //    end;
  140. //  finally
  141. //    RestoreDC( dc, -1 );
  142. //    ReleaseDC( handle, dc );
  143. //  end;
  144. //end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement