今日编程手札

首先是TControlBar:
OnPaint事件和OnBandPaint的关系是:
procedure TCustomControlBar.Paint;
--> OnPaint(Self);
-->for I := 0 to FItems.Count - 1 do
-->PaintControlFrame(Canvas, Control, R);
-->DoBandPaint(AControl, Canvas, ARect, Options);
--> OnBandPaint(Self, Control, Canvas, ARect, Options);

OnPaint事件解发在先,对整个TControlBar。OnBandPaint在后仅一个Band。
当然OnPaint中不能决定它绘什么不绘什么,而OnBandPaint中则可以更改Options决定它能绘什么。
若果windows没有启用Themesp,TControlBar画的那条竖线确实有碍美观,特别是bpoGradient时,不过完全可以参考TCustomControlBar.PaintControlFrame自己画一个。
TCustomControlBar.PaintControlFrame的代码:
  1. procedureTCustomControlBar.PaintControlFrame(Canvas:TCanvas;AControl:TControl;
  2. varARect:TRect);
  3. const
  4. Offset=3;
  5. var
  6. R:TRect;
  7. ElemDetails:TThemedElementDetails;
  8. Options:TBandPaintOptions;
  9. procedureDrawGrabber;
  10. begin
  11. withCanvas,Rdo
  12. begin
  13. Pen.Color:=clBtnHighlight;
  14. MoveTo(R.Left+2,R.Top);
  15. LineTo(R.Left,R.Top);
  16. LineTo(R.Left,R.Bottom+1);
  17. Pen.Color:=clBtnShadow;
  18. MoveTo(R.Right,R.Top);
  19. LineTo(R.Right,R.Bottom);
  20. LineTo(R.Left,R.Bottom);
  21. end;
  22. end;
  23. begin
  24. ifFDrawingStyle=dsGradientthen
  25. Options:=[bpoGrabber,bpoGradient,bpoRoundRect]
  26. else
  27. Options:=[bpoGrabber,bpoFrame];
  28. DoBandPaint(AControl,Canvas,ARect,Options);
  29. withCanvasdo
  30. begin
  31. ifbpoFrameinOptionsthen
  32. DrawEdge(Handle,ARect,BDR_RAISEDINNER,BF_RECT);
  33. ifbpoRoundRectinOptionsthen
  34. begin
  35. BeginPath(Handle);
  36. Polyline([Point(ARect.Left+Integer(CornerEdge),ARect.Top),
  37. Point(ARect.Right-Integer(CornerEdge),ARect.Top),{Topline}
  38. Point(ARect.Right,ARect.Top+Integer(CornerEdge)),{Toprightcurve}
  39. Point(ARect.Right,ARect.Bottom-Integer(CornerEdge)),{Rightsideline}
  40. Point(ARect.Right-Integer(CornerEdge),ARect.Bottom),{Bottomrightcurve}
  41. Point(ARect.Left+Integer(CornerEdge),ARect.Bottom),{Bottomline}
  42. Point(ARect.Left,ARect.Bottom-Integer(CornerEdge)),{Bottomleftcurve}
  43. Point(ARect.Left,ARect.Top+Integer(CornerEdge)),{Leftsideline}
  44. Point(ARect.Left+Integer(CornerEdge),ARect.Top)]);{Topleftcurve}
  45. EndPath(Handle);
  46. {Clipsthecanvastoourroundrectdrawnaboveusingpolyline}
  47. SelectClipPath(Handle,RGN_COPY);
  48. end;
  49. ifbpoGradientinOptionsthen
  50. begin
  51. {Thisgradientisactuallythebordergradient}
  52. GradientFillCanvas(Canvas,GetHighlightColor(GradientStartColor),
  53. GetShadowColor(GradientEndColor),ARect,GradientDirection);
  54. R:=ARect;
  55. InflateRect(R,-Pen.Width,-Pen.Width);
  56. {Thegradientoftheband}
  57. GradientFillCanvas(Canvas,GradientStartColor,GradientEndColor,
  58. R,GradientDirection);
  59. end;
  60. ifbpoGrabberinOptionsthen
  61. begin
  62. ifThemeServices.ThemesEnabledthen
  63. begin
  64. ElemDetails:=ThemeServices.GetElementDetails(trGripper);
  65. R:=Rect(ARect.Left+2,ARect.Top+2,ARect.Left+5+2,ARect.Bottom-3);
  66. ThemeServices.DrawElement(Canvas.Handle,ElemDetails,R);
  67. endelse
  68. begin
  69. R:=Rect(ARect.Left+Offset,ARect.Top+2,ARect.Left+Offset+2,
  70. ARect.Bottom-3);
  71. DrawGrabber;
  72. end;
  73. end;
  74. end;
  75. end;
改掉上面的DrawGrabber,爱怎么画就怎么画。当然还是建议在OnBandPaint事件里画,而不是改控件代码。


然后是TDBComboboxEh:
EhLib的控件不错,但总有些毛病,比如将控件连接到一个Boolean类型的字段,在KeyItems里写下false和true,结果呢?下拉列表能出来,选了也能更新到数据库,但控件自己显示的却是空白。翻了翻代码,原来它用KeyItems.IndexOf(FDataLink.Field.Text)来查找(GetDisplayTextForPaintCopy函数里),Boolean类型的Field.Text是False和True(首字母大写),改正后一切正常。


接着是Abstract Error:
将一个界面的控件类型大批量换掉后(直接改dfm文件),运行程序报Abstract Error,查来查去才发现,原来之前为Form指定了ActiveControl,而那个Control已经被转换成TDBText了,晕~~~~~


FastReport:
已经有4.7.3了,不过项目太紧,不敢现在更新控件。


Toad Data Modeler Library:
Case Studio卖了后,取而代之的是Toad Data Modeler Library,看了看资料,变了很多,功能也加强了很多,不敢马上用,项目完了再试。


最后是db4o:
最后的O是Object,面向对象的开源数据库,支持Java和.Net,遵守GPL协议,且免费!!!有兴趣了的Google去!


个人札记,拒绝转载!

你可能感兴趣的:(编程,.net,windows,Google)