Solved

Change EditBox color

Posted on 2003-11-28
13
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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