Checkbox Transparente?
#1
Escrito 22 octubre 2009 - 03:03
Nose si es malo que pida,pero intentare ayudar en lo que sepa
Mmmm..Ultimamente me quede con la duda de alguna forma de quitarle al checkbox el color de fondo,osea que quede transparente encima de un Image y solo quede la cajita de marcado y el texto.
He estado buscando como loco y no he encontrado ninguna solucion,Habra algun componente o codigo que haga lo que quiero?
Espero su ayuda Saludos..
#2
Escrito 22 octubre 2009 - 03:20
saludos
#3
Escrito 22 octubre 2009 - 03:29
Primero que todo bienvenido al foro, acabo de ensayar en D2010 con un checkbox y un Timage y con solo poner True a la propiedad parentColor del checkBox este se torna transparente.
saludos
Mmmmm.. por cierto estoy usando delphi 7 jeje de todas formas gracias
#4
Escrito 22 octubre 2009 - 03:39
unit Unit1; interface uses Forms, StdCtrls, Messages, Controls; type // Example of a check box with tranparent caption TMyCheckBox = class(TCheckBox) protected procedure CNDrawItem(var Msg: TWMDrawItem); message CN_DRAWITEM; procedure CreateParams(var Params: TCreateParams); override; procedure CreateWnd; override; procedure SetButtonStyle; end; TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormPaint(Sender: TObject); public fCB: TCheckBox; fMyCB: TMyCheckBox; end; var Form1: TForm1; implementation uses Classes, Windows, Graphics; {$R *.dfm} { TMyCheckBox: } procedure TMyCheckBox.CNDrawItem(var Msg: TWMDrawItem); var XCanvas: TCanvas; XCaptionRect, XGlyphRect: TRect; procedure xxDrawBitMap(ACanvas: TCanvas); const xx_h = 13; xx_w = 13; var xxGlyph: TBitmap; xxX, xxY, xxStepY, xxStepX: integer; begin xxGlyph := TBitmap.Create; try xxGlyph.Handle := LoadBitmap(0, PChar(OBM_CHECKBOXES)); xxY := XGlyphRect.Top + (XGlyphRect.Bottom - XGlyphRect.Top - xx_h) div 2; xxX := 2; xxStepX := 0; xxStepY := 0; case State of cbChecked: xxStepX := xxStepX + xx_w; cbGrayed: xxStepX := xxStepX + xx_w * 3; end; ACanvas.CopyRect( Rect(xxX, xxY, xxX + xx_w, xxY + xx_h), xxGlyph.Canvas, Rect(xxStepX, xxStepY, xx_w + xxStepX, xx_h + xxStepY) ); finally xxGlyph.Free; end; end; procedure xxDrawCaption; var xXFormat: longint; begin xXFormat := DT_VCENTER + DT_SINGLELINE + DT_LEFT; xXFormat := DrawTextBiDiModeFlags(xXFormat); DrawText( Msg.DrawItemStruct.hDC, PChar(Caption), Length(Caption), XCaptionRect, xXFormat ); end; begin XGlyphRect := Msg.DrawItemStruct.rcItem; XGlyphRect.Right := 20; XCaptionRect := Msg.DrawItemStruct.rcItem; XCaptionRect.Left := XGlyphRect.Right; XCanvas := TCanvas.Create; try XCanvas.Handle := Msg.DrawItemStruct.hDC; XCanvas.Brush.Style := bsClear; xxDrawBitMap(XCanvas); xxDrawCaption; finally XCanvas.Free; end; end; procedure TMyCheckBox.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); Params.ExStyle := Params.ExStyle or WS_EX_Transparent; end; procedure TMyCheckBox.CreateWnd; begin inherited CreateWnd; SetButtonStyle; end; procedure TMyCheckBox.SetButtonStyle; const BS_MASK = $000F; var Style: Word; begin if HandleAllocated then begin Style := BS_CHECKBOX or BS_OWNERDRAW; if GetWindowLong(Handle, GWL_STYLE) and BS_MASK <> Style then SendMessage(Handle, BM_SETSTYLE, Style, 1); end; end; { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin // Normal check box fCB := TCheckBox.Create(Self); fCB.Parent := Self; fCB.Left := 20; fCB.Top := 20; fCB.Caption := fCB.ClassName; // Subclasses check box fMyCB := TMyCheckBox.Create(Self); fMyCB.Parent := Self; fMyCB.Left := 20; fMyCB.Top := fCB.Top + fCB.Height + 40; fMyCB.Caption := fMyCB.ClassName; end; // Paints a yellow / white candy stripe on the form procedure TForm1.FormPaint(Sender: TObject); var Idx: Integer; begin for Idx := 0 to ClientHeight div 8 do begin if Odd(Idx) then Canvas.Brush.Color := clWhite else Canvas.Brush.Color := $aaffff; // pale yellow Canvas.FillRect(Rect(0, Idx * 8, ClientWidth, Idx * 8 + 8)); end; end; end.
#5
Escrito 22 octubre 2009 - 04:37
Crea un nuevo proyecto con un form llamado form1 y intercepta los evento Onpaint y OnCreate , coloca el siguiente codigo y ensaya;
Probé el código en D7 y trabaja perfectamente, el evento OnPaint lo puedes quitar que solo es para pintar el form de colores.
Saludos
#6
Escrito 22 octubre 2009 - 05:41
Crea un nuevo proyecto con un form llamado form1 y intercepta los evento Onpaint y OnCreate , coloca el siguiente codigo y ensaya;
Probé el código en D7 y trabaja perfectamente, el evento OnPaint lo puedes quitar que solo es para pintar el form de colores.
Saludos
Gracias... Funciona perfectamente parece que dibuja el checkbox o le edita sus valores? pero esto lo quiero usar en mi aplicacion cuyo usa como 30 checkbox,habra alguna manera de ponerselos directamente? sin tanto codigo.. disculpa por ser pregunton jeje