Solved

Change EditBox color

Posted on 2003-11-28
13
308 Views
Last Modified: 2010-04-05
Var
    Hcol: HDC;

Begin
 Hcol:=GetWindowDC(HandleOfEditBox);
 SetBkColor(HCol,RGB(255,0,0));
 SetTextColor(Hcol,RGB(255,0,0));
End;

Ok any idea why this does not work?
0
Comment
Question by:craig_capel
  • 5
  • 4
13 Comments
 

Accepted Solution

by:
Brr earned 50 total points
ID: 9838280
Dont know - but you can use the Color and Font.Color properties of the editbox
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9838313
I am not using the VCL, i need to use windows API
0
 
LVL 3

Assisted Solution

by:JDuncan
JDuncan earned 50 total points
ID: 9838532
It may be that you are not drawing to the edit box eith the nex settings because this chages the text.

procedure TForm1.Button1Click(Sender: TObject);
Var
  Hcol: HDC;
  mystr : array [0..5] of char;
Begin
 mystr:='abcdef';
 Hcol:=GetWindowDC(Edit1.Handle);
 label1.caption:=inttohex(hcol,8);
 SetBkColor(HCol,RGB(0,100,0));
 SetTextColor(Hcol,RGB(128,0,0));
 TextOut(Hcol,0,0,myStr,5);
 ReleaseDC(Edit1.Handle,Hcol);
end;

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:craig_capel
ID: 9838585
I see what that's doing but it's not changing all of the edit box to a different color, just the text, but hey it's something to go on thanks....

i will keep trying...
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9838590
Chances are i am going about it the wrong way, maybe it's a different call :O
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 9838604
get the text and re draw it, you could maybe use the invalidaterect call to force a redraw or just do this

 Hcol:=GetWindowDC(Edit1.Handle);
 SetBkColor(HCol,RGB(0,100,0));
 SetTextColor(Hcol,RGB(128,0,0));
 GetWindowText(Hcol,myStr,6);
 TextOut(Hcol,0,0,myStr,5);
 ReleaseDC(Edit1.Handle,Hcol);
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 9838721
This is strange , when you set the backgroud color the systems reports it as changed to
the new value .

It looks like you are only changing the windows context and this may be causing the delphi edit box to re paint to the original settings.

You amy have to create the edit box using windows calls instead of delphi calls to do what you want to do.


0
 
LVL 2

Author Comment

by:craig_capel
ID: 9840333
I use CreateWindowEx to make my edit control, there are no params to set the color of the edit box, you should be able to take the handle of the edit box (from any application) and with nothing more than the handle change the edit color box like doing...

EditBox1.Color:=$FF00FF;

That's all i am trying to do but in Win32 API
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 9845336
What operating system are you using <=win98 or >=2000
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9846824
Win2K
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question