1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
|
const flaeche: array[0..2] of TColor = (clYellow, clLime, clBlue); schrift: array[0..2] of TColor = (clRed, clBlack, clwhite); procedure TForm1.FormCreate(Sender: TObject); var x: integer; begin PageControl1.Ownerdraw := true; for x := 0 to 2 do PageControl1.Pages[x].brush.color := flaeche[x]; end; procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); var r: TRect; begin with PageControl1.canvas do begin brush.color := flaeche[TabIndex]; Font.color := schrift[TabIndex]; r := Rect; fillrect(r); Drawtext(handle, Pchar(PageControl1.pages[Tabindex].caption), -1, r, DT_CENTER or DT_VCENTER or DT_SINGLELINE); end; end;
... public procedure TabShow(TS: TTabSheet; showtab: boolean); end; var Form1: TForm1; implementation {$R *.DFM} const TabMaxZahl = 4; flaeche: array[0..TabMaxZahl - 1] of TColor = (clYellow, clFuchsia, clBlue, clGreen); schrift: array[0..TabMaxZahl - 1] of TColor = (clGreen, clBlack, clWhite, clYellow); hlp: array[0..TabMaxZahl - 1] of integer = (0, 1, 2, 3); procedure TForm1.FormCreate(Sender: TObject); var x: integer; begin with PageControl1 do begin Ownerdraw := true; if PageCount > TabMaxZahl then begin showmessage('Falsche Tabzahl'); application.terminate; exit; end; for x := 0 to PageCount - 1 do begin Pages[x].tag := x; Pages[x].tabvisible := true; Pages[x].brush.color := flaeche[x]; end; end; end; procedure TForm1.TabShow(TS: TTabSheet; showtab: boolean); begin if TS.tabvisible <> showtab then begin if showtab then begin TS.Pagecontrol.ActivePage := TS; TS.tabvisible := true; movememory(@hlp[TS.TabIndex + 1], @hlp[TS.TabIndex], (TabMaxZahl - 1 - TS.TabIndex) * sizeof(integer)); hlp[TS.TabIndex] := TS.tag; end else begin movememory(@hlp[TS.TabIndex], @hlp[TS.TabIndex + 1], (TabMaxZahl - 1 - TS.TabIndex) * sizeof(integer)); TS.tabvisible := false; end; end; end; procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); var r: TRect; begin with TPageControl(Control), Canvas do begin brush.color := flaeche[hlp[TabIndex]]; Font.color := schrift[hlp[TabIndex]]; r := Rect; fillrect(r); Drawtext(handle, Pchar(Pages[hlp[TabIndex]].caption), -1, r, DT_CENTER or DT_VCENTER or DT_SINGLELINE); end; end; procedure TForm1.Button1Click(Sender: TObject); begin TabShow(TabSheet2, false); end; procedure TForm1.Button2Click(Sender: TObject); begin if PageControl1.Pagecount = 0 then exit; TabShow(PageControl1.Pages[PageControl1.Pagecount - 1], not PageControl1.Pages[PageControl1.Pagecount - 1].tabvisible); end; |