nesnelerin focus anında ve focusdan sonraki renkleri

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
delphist
Üye
Mesajlar: 595
Kayıt: 05 Oca 2005 04:34

nesnelerin focus anında ve focusdan sonraki renkleri

Mesaj gönderen delphist »

S.a. Arkadaşlar aşağıya yazdığım procedure buldum...Bu procedure mdi main ana formun içinde tanımlayıp tüm bu mdi main formun içinde açılan mdi child formlarda etkili olmasını sağlayabilirmiyiz. Teşekkürler.

Kod: Tümünü seç

procedure CMfocuschanged(var message: TCMfocuschanged); message CM_Focuschanged;

procedure Tfrm_stokkartikayit.CMFocusChanged(var Message: TCMFocusChanged);
var
i:integer;
grenk,crenk : tcolor;
BEGIN
grenk := clwhite;
crenk := clBlue;
	if (message.sender is tedit) or
  (message.sender is Tcxgrid) or
	(message.sender is tcombobox) or
	(message.sender is tlistbox) or
	(message.sender is tcheckbox) or
	(message.sender is tradiobutton) or
	(message.sender is tdbedit)or
	(message.sender is tdbcombobox) or
	(message.sender is tdblistbox) or
	(message.sender is tdbcheckbox) or
	(message.sender is TDBGrid) or
	(message.sender is TMaskEdit) or
  (message.sender is TcxdbTextEdit) or
	//(message.sender is TStringGrid) or
	//(message.sender is TDrawGrid) or
	(message.sender is TDBRichEdit) or
	(message.sender is TDBLookupListBox) or
	(message.sender is TDBLookupComboBox) or
  (message.Sender is TcxDBLookupComboBox) or
  (message.Sender is TcxDBMemo) or
  (message.Sender is TcxDBComboBox)
	then 
	begin
		for i:=0 to componentcount-1 do
		begin
			if components[i] is tedit then 
			tedit(components[ i ]).color:=   grenk;


			if components[i] is tcombobox then
			tcombobox(components[i]).color:= grenk;


			if components[i] is tlistbox then
			tlistbox(components[i]).color:=  grenk;


			if components[i] is tcheckbox then
			tcheckbox(components[i]).color := grenk;

			if components[i] is tradiobutton then
			tradiobutton(components[i]).color:= grenk;


			if components[i] is tdbedit then
			tdbedit(components[i]).color:=  grenk;


			if components[i] is tdbcombobox then
			tdbcombobox(components[i]).color:=  grenk;


			if components[i] is tdblistbox then
			tdblistbox(components[i]).color:= grenk;


			if components[i] is tdbcheckbox then
			tdbcheckbox(components[i]).color:= grenk;


			if components[i] is TDBGrid then
			TDBGrid(components[i]).color:=  grenk;


			if components[i] is TMaskEdit then
			TMaskEdit(components[i]).color:= grenk;

      if components[i] is TcxdbTextEdit then
			TcxdbTextEdit(components[i]).Style.color:= grenk;

      if components[i] is TMaskEdit then
			TMaskEdit(components[i]).color:= grenk;

			if components[i] is TDBRichEdit then
			TDBRichEdit(components[i]).color:=  grenk;


			if components[i] is TDBLookupListBox then
			TDBLookupListBox(components[i]).color:= grenk;


			if components[i] is TDBLookupComboBox then
			TDBLookupComboBox(components[i]).color:= grenk;

      if components[i] is TcxDBMemo then
		  TcxDBMemo(components[i]).Style.color:= grenk;

      if components[i] is TcxDBComboBox then
			TcxDBComboBox(components[i]).Style.color:= grenk;

      if components[i] is TcxDBLookupComboBox then
			TcxDBLookupComboBox(components[i]).Style.color:= grenk;

     if components[i] is Tcxgrid then
			Tcxgrid(components[i]).Canvas.Brush.Color := grenk;

		end ;
	       	tedit(message.sender).color :=crenk;
          TcxDBTextEdit(message.Sender).Style.Color := crenk;
          TcxDBMemo(message.sender).Style.Color := crenk;
          TcxDBComboBox(message.sender).Style.Color := crenk;
          TcxDBLookupComboBox(message.sender).style.Color := crenk;
          Tcxgrid(message.sender).Canvas.Brush.Color := clRed;
	end
end;

Kullanıcı avatarı
husonet
Admin
Mesajlar: 2962
Kayıt: 25 Haz 2003 02:14
Konum: İstanbul
İletişim:

Mesaj gönderen husonet »

Base form yaratıp bu kodu base forma yazıp diğer child formlarınıda base formdan türetirsen istediğin olur.


Kolay Gelsin...

Gazete manşetleri
* DİKKAT :Lütfen forum kurallarını okuyalım ve uyalım...!
* Warez,crack vs. paylaşımı kesinlikle yasaktır.
Kullanıcı avatarı
delphist
Üye
Mesajlar: 595
Kayıt: 05 Oca 2005 04:34

Mesaj gönderen delphist »

S.a. projemde kullandığım 300 den fazla form var yani base formu şu an oluşturmam mümkün değil. Ama sanki base formdan türetmiş gibi nasıl yapabilirim ki bu kodu tüm heryerde kullanabilirim hüseyin bey.
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

- Ben kendi projelerimde aşağıdaki şekilde kullanıyorum. Böylece skin çözümlerini kendim için üretmiş oluyorum. :idea:

- Kodu seninkine uyarladım, devamını getirirsin... Afiyet olsun...

Kod: Tümünü seç

procedure TForm1.RenkleriDuzenle(Sender: TObject);
var
  i     : integer;
  gRenk,
  cRenk : TColor;
begin
  gRenk := clWhite;
  cRenk := clBlue;
  for I:= 0 to TScreen(Sender).ActiveForm.ControlCount -1 do
  begin
    if TScreen(Sender).ActiveForm.Controls[I] is TWinControl then
    begin
      If TScreen(Sender).ActiveForm.Controls[i] is TEdit then
        with TEdit(TScreen(Sender).ActiveForm.Controls[i]) do
          If Focused then Color := gRenk
                     else Color := cRenk;
      If TScreen(Sender).ActiveForm.Controls[i] is TCheckBox then
        with TCheckBox(TScreen(Sender).ActiveForm.Controls[i]) do
          If Focused then Color := gRenk
                     else Color := cRenk;
    end;
  end;
end;

Kod: Tümünü seç

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.OnActiveControlChange := RenkleriDuzenle;
end;
- Sadece ana forma koyman yeterli. Tüm formlar bundan etkilenir. TScreen tipi tüm application için global bir çözümdür. Delphi help'den yardım alarak diğer fonksiyonlarını da kullan çok faydalıdır. :idea:
Resim
Resim ....Resim
Kullanıcı avatarı
delphist
Üye
Mesajlar: 595
Kayıt: 05 Oca 2005 04:34

Mesaj gönderen delphist »

s.a. Her zamanki gibi eline koluna sağlık abi...Eyvallah...Teşekkür ederim.
Erd_turkmen
Üye
Mesajlar: 38
Kayıt: 27 Ara 2006 03:13

Mesaj gönderen Erd_turkmen »

S.A
Merhabalar hayırlı bayramlar hepinize..
Ya üstte

Kod: Tümünü seç

mrmarman
hocamın yazdığı kodu bende bi deniyeyim dedim ancak beceremedim :(
Yardımcı Olursanız Sevinirim. İyi Günler
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

selam...

- Aldığınız hatayı bildirirseniz ona göre cevap vereyim. Hata vermiyorsa örnekte sadece TEdit ve TCheckbox için ayarlama yapılmıştı, formunuzda yoksa sonuç doğaldır...

- Yeni bir proje açın, gelen forma birkaç tane Edit, birkaç tane CheckBox koyun. Ayrıca örnekte verilen

Kod: Tümünü seç

procedure TForm1.RenkleriDuzenle(Sender: TObject); 
kod bloğunu ekleyin. Formun OnCreate kısmında ise

Kod: Tümünü seç

  Screen.OnActiveControlChange := RenkleriDuzenle; 
kodunu eklemeyi ihmal etmeyin. Hazırlıklar böylece tamamlanmış oldu.

- Dilerseniz artık projeye yeni bir form ekleyin onda da birkaç tane Edit ve bir kaç tane CheckBox koyun. Program ana formunda ekleyeceğiniz bir button yardımı ile çağrı yaptırın. Açılan her form da ana formdaki kurgudan ötürü etkilenecektir.

Örnek proje :
Ref: http://rapidshare.com/files/10002520/TS ... k.zip.html
Resim
Resim ....Resim
Erd_turkmen
Üye
Mesajlar: 38
Kayıt: 27 Ara 2006 03:13

Mesaj gönderen Erd_turkmen »

Hocam çok teşekkür ederim saolun..
Kullanıcı avatarı
delphist
Üye
Mesajlar: 595
Kayıt: 05 Oca 2005 04:34

Mesaj gönderen delphist »

s.a. mrmarman abicim...bu sistem sadece modal formlarda çalışıyor mdi child larda aktif olmuyor mdi main forma bu kodu yazdığım ve nerdeyse tüm bileşenleri ekledim ama mdi childlarda hareket yok ama normal formda renklendirme yapıyor.
:?
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

Hocam emin misin... Ben şimdi aynı örneği MDIForm'a uyguladım Child'lar da etkilendi
:?:

Resim
Resim
Resim ....Resim
Kullanıcı avatarı
delphist
Üye
Mesajlar: 595
Kayıt: 05 Oca 2005 04:34

Mesaj gönderen delphist »

s.a. Yanlız mrmarman abi...Benim mdi mainler biraz farklı normalde bir projede sadece bir adet mdi main form kullanılabiliyor ama delphide bununla ilgili procedure function override ettim. Dll ler içindede ben mdi main form kulalnıyorum yani projemde birden fazla mdi main form var ve bunlar exede değil dll ler içerisinde...Ve mdi mainde bu olayı aktif ettiğim zaman açılan modal formda renkledirme oluyor ve formu kapatır kapatmaz program hata veriyor. Sence problem neden kaynaklanıyor olabilir.
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

- Soru sorarken bunun gibi önemli detayları da verseydin daha iyi olurdu. Projen yaz boz tahtasına dönmezdi. :idea:

- Eğer sen örneğimizdeki RenkleriDuzenle fonksiyonunu olduğu ana formu sonlandırıyorsan hata vermesi doğaldır.

- Programın çalışmaya devam ettiğinden Screen.OnActiveControlChange kontrolü tekrar çalışma ihtiyacı doğduğunda başvuracağı fonksiyonu yoketmiş olmuş olursun. Böyle durumlar AccessViolation'luk hatalardır.

- Şimdi bu renk kontrolü içeren ana form FREE ediliecek olurda program henüz sonlandırılmayacak ise aşağıdaki şekilde bu kontrolün serbest burakılması gerekir.

Kod: Tümünü seç

  Screen.OnActiveControlChange := Nil;
- Bunu yaparsan hata almazsın.

- SCREEN kontrolü tüm program boyunca bir kontroldür. Onun için DLL içerisinde üretilen başka formlar varsa hepsine Parametre aktararak CreateParams ile ANAForm'un bir parçası olmasını sağlamalısın ki Screen kontrolune dahil olabilsinler.

- Yani biraz mesai yapacak kendi çözümünü üreteceksin. Kodlar üzerinde yapman gereken bu kadar. Gerisi sana kalmış. :idea:
Resim
Resim ....Resim
Kullanıcı avatarı
mcuyan
Üye
Mesajlar: 28
Kayıt: 04 Eki 2010 10:47

Re: nesnelerin focus anında ve focusdan sonraki renkleri

Mesaj gönderen mcuyan »

biraz geç oldu ama olayı yeni kullanmaya başladım.. peki panel üzerindeki editlere kontrolü nasıl yapcağız?
M.Cihan UYAN
SNC Tech&Soft
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: nesnelerin focus anında ve focusdan sonraki renkleri

Mesaj gönderen mrmarman »

Geç olsun güç olmasın demişler...

- Geçmiş zaman aklımıza gelmemiş.

- Kendime sordum; TPanel'in kendi içinde alt kontrolleri olduğuna göre deyip aşağıdaki şekilde düzenledim. Denedim çalışıyor...

Kod: Tümünü seç

procedure TForm1.RenkleriDuzenle(Sender: TObject);
var
  i, j     : integer;
  gRenk,
  cRenk : TColor;
begin
  gRenk := clWhite;
  cRenk := clBlue;
  for I:= 0 to TScreen(Sender).ActiveForm.ControlCount -1 do
  begin
    if TScreen(Sender).ActiveForm.Controls[I] is TWinControl then
    begin
      If TScreen(Sender).ActiveForm.Controls[i] is TEdit then
        with TEdit(TScreen(Sender).ActiveForm.Controls[i]) do
          If Focused then Color := gRenk
                     else Color := cRenk;
      If TScreen(Sender).ActiveForm.Controls[i] is TCheckBox then
        with TCheckBox(TScreen(Sender).ActiveForm.Controls[i]) do
          If Focused then Color := gRenk
                     else Color := cRenk;
// -----------------------------------------------------------------------------
// Panel için eklediğim kısım....
// -----------------------------------------------------------------------------
      If TScreen(Sender).ActiveForm.Controls[i] is TPanel then
      begin
        for j:= 0 to TPanel(TScreen(Sender).ActiveForm.Controls[i]).ControlCount -1 do
        begin
          If TPanel(TScreen(Sender).ActiveForm.Controls[i]).Controls[j] is TEdit then
          with TEdit( TPanel(TScreen(Sender).ActiveForm.Controls[i]).Controls[j] ) do
            If Focused then Color := gRenk
                       else Color := cRenk;
        end;
      end;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.OnActiveControlChange := RenkleriDuzenle;
end;
Resim
Resim ....Resim
Kullanıcı avatarı
mcuyan
Üye
Mesajlar: 28
Kayıt: 04 Eki 2010 10:47

Re: nesnelerin focus anında ve focusdan sonraki renkleri

Mesaj gönderen mcuyan »

ilginize çok teşekkürler mrmarman..
siz delphiturkde bulunmuşmuydunuz?

adınız muharremmiydi? trt mi çalışıyordunuz?
M.Cihan UYAN
SNC Tech&Soft
Cevapla