30 Ocak 2014 Perşembe

Combobox Renk Seç Formu Boya


1ComboBox ekleyip, comboBox’ın içinden bir renk seçildiğinde hem ComboBox boyansın hem de form o seçtiğimiz renkle boyansın. Bu işlemi yapan programın kodu.
Kodu;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.CommaText:='Kırmızı,Yeşil,Sarı,Siyah,Mavi,Gri';
ComboBox1.Style:=csOwnerDrawFixed;
end;

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
  var
  renk:TColor;
  eleman:String;
  begin
  eleman:=ComboBox1.Items[index];
  case index of
  0:
  renk:=clRed;
  1:
  renk:=clGreen;
  2:
  renk:=clYellow;
  3:
  renk:=clBlack;
  4:
  renk:=clBlue;
  5:
  renk:=clGray;
  end;
  if State= [odselected] then
  combobox1.Canvas.Brush.Color:= clskyblue
  else
  ComboBox1.Canvas.Brush.Color:=renk;
  ComboBox1.Canvas.FillRect(rect);
  ComboBox1.canvas.Font.Color:=clWhite;
  ComboBox1.Canvas.textout (rect.Left,rect.Top,eleman) ;
  end;
procedure TForm1.ComboBox1Change(Sender: TObject);
var
renk:tcolor;
begin
case ComboBox1.ItemIndex of
 0:
  renk:=clRed;
  1:
  renk:=clGreen;
  2:
  renk:=clYellow;
  3:
  renk:=clBlack;
  4:
  renk:=clBlue;
  5:
  renk:=clGray;
end;
  self.color:=renk;
  end;
end.

Hiç yorum yok:

Yorum Gönder