Solved

vb6 textbox backcolor

Posted on 2010-08-25
23
1,352 Views
Last Modified: 2012-06-21
Dear Experts,

When changing a textbox's backcolor at runtime from white to another color, and then back to white, the prior color lingers as an outline around the textbox until I mouse over it. This happens in Windows XP but not Vista or 7.

How can this be avoided?

Thanks!
0
Comment
Question by:ttobin333
  • 6
  • 6
  • 3
  • +5
23 Comments
 
LVL 2

Expert Comment

by:eoindevery
ID: 33528210
Try calling Text1.Refresh()
0
 
LVL 17

Expert Comment

by:aiklamha
ID: 33528661
I can't reproduce this behavior on my XP machine... have you set any other property of textbox too?
0
 
LVL 3

Expert Comment

by:baffy2000
ID: 33529737
Do Textboxes have a Refresh property?

You could try Form.Repaint (where Form is an *instance* of your form. Or Me.Repaint if written in the form code)

Otherwise, you'd be into APIs. This isn't too complicated.

http://www.vbaccelerator.com/home/vb/tips/Force_An_Area_of_a_Window_To_Repaint/article.asp
0
 
LVL 3

Expert Comment

by:baffy2000
ID: 33529765
Just to clarify, the reason I highlighted *instance* of your form, is that if you have defined a form in your project called, for example, MyLovelyForm1, then:

MyLovelyForm1.Repaint

will NOT work. This is to do with Forms being declared "As New", so what you are actually doing in the above line is creating a new instance of your MyLovelyForm1 form and repainting that.

If, however, you have created an instance of your form:

Dim frmMyLovelyFormInstance as MyLovelyForm1
Set frmMyLovelyFormInstance = New MyLovelyForm1

then you can say

fromMyLovelyFormInstance.Repaint

Entire chapters have been written about this, so sorry if I'm a) confusing you, or b) telling you stuff you already know.

If you use Me.Repaint in the form code, you won't have to worry about any of this.
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 33530578
OR
You could just put a DoEvents right after you change the color each time.
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33531090
If you get really desperate, here is a work-around. Create two textboxes. Make them the same size and at the same place on your form. Set the back color of one to white, and the other to the other color. Make the other color text box invisible (set Visible property to false). Put the same text in both, then turn Visible on for the other color box and off for the white one, then reverse to return to white.
0
 

Author Comment

by:ttobin333
ID: 33539283
Thanks, guys...but textbox refresh, form refresh, and doevents did not work. I could not find form.repaint.

I haven't tried to API yet, but I will.

This is a strange problem that seems to be unique to Windoes XP. It does not occur on Win98, Vista, or Win7.

A little more info, in case it helps: the textboxes are in an array, and I first change them all to white, then change the one that the user clicked on to blue.
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33541249
<<A little more info, in case it helps: the textboxes are in an array, and I first change them all to white, then change the one that the user clicked on to blue.>>
From what you said before, it sounds liek you just flash it to blue and then to white again. Is that right, or does it stay blue until the user does something?
As I suggested, you can put additional blue text boxes on top of the white ones and switch them out, even if they are in an array. one array can be txtWhite() and the other txtBlue(). When the user clicks on txtWhite(N), set
txtBlue(N).Text = txtWhite(N).Text.
txtBlue(N).Visible = True
txtWhite(N).Visible =False
Put the same code in the txtBlue boxes as the txtWhite boxes, and the program can process it from there.
I know this soudns a bit drastic, but it all depends on how desparate you are to get rid of this color problem.
BTW, I have also been unable to duplicate the problem in XT, so it might be smething on your actual computer.
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33541264
Sorry, typo. I meant XP.
0
 
LVL 3

Expert Comment

by:baffy2000
ID: 33541413
You could try updating your graphics drivers?
0
 

Author Comment

by:ttobin333
ID: 33547528
Here's an important point I forgot to mention (because I forgot I was using it): I am using a manifest file to force an XP appearance to the form. This only happens with the manifest in effect, not in standard vb6 appearance. Nevertheless, there must be a way to fix this.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:eoindevery
ID: 33548231
Perhaps disable then re-enable the textbox. Not sure if it will repaint the control but it should repaint the contents.

'After setting the color to white
Text1.Enabled = False
Text1.Enabled = True

Another possibility is that if the Textbox is focused when the color is changed the outline isn't refreshing. Try setting the focus on another control while the color is being changed and switching back after changing back to white.

Just as a matter of interest is the textbox border FixedSingle or Fixed3D?
0
 
LVL 4

Expert Comment

by:coolcurrent4u
ID: 33549867
if it is possible to post the form, please post it, or you can post the code you are using to change the colors. Is this text box native vb6 control?
0
 

Author Comment

by:ttobin333
ID: 33560599
Disabling/enabling the textbox worked but created problems with my manual drag/drop subroutines, making it look like a drag/drop was being initiated just by clicking on the textbox.

Is there a way to programmatically simulate a mousemove over the textbox without actually moving the mouse pointer? Just moving the mouse over the textbox with the "ghost" color fixes the probem.

Responding to other questions: yes, this is a native vb textbox. I would rather not post the form, which is complex. The code used to change the textbox color is: text1.backcolor=vbblue,  text1.backcolor=vbwhite, within the text1_gotfocus and text1.lostfocus subs.
0
 
LVL 3

Expert Comment

by:baffy2000
ID: 33564983
If you want to go down that route, you could try using SendMessage (http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx) to send a WM_MOUSEMOVE (http://msdn.microsoft.com/en-us/library/ms645616(v=VS.85).aspx) to the textbox.

But without trying it, I don't know exactly how that would work. It may actually move the mouse, although I don't think it will.

Or, could you try setting the control to .Visible=False, then .Visible = True in the lostfocus event, forcing it to repaint?
0
 
LVL 3

Expert Comment

by:Genetic_Wolf
ID: 33613223

4 questions to ask...

1. have you installed Vb SP6 ?
2. have you installed all POST SP6 patch ?
3. have you check if the issue reproduce with ANTI Aliasing TURNED OFF ?
4. have you used problematic FONT (like Verdana).  if so, try with MS SANS SERIF (regular font)
0
 

Author Comment

by:ttobin333
ID: 33658304
Genetic Wolf, SP6 installed, no problematic font being used (just MS Sans Serif).

I didn't know there were post SP6 patches, will look into that. Is there a place to find them all together?

Regarding anti-aliasing, is this something that is turned on-off within VB6 or Windows?

Thanks!
0
 
LVL 3

Expert Comment

by:Genetic_Wolf
ID: 33658851
anti aliasing can be turned OFF with windows.
there is 2 place (in order) you want to turn them OFF to TRY the setting.
check the produced screen shot of the two place.  the second setting is influenced by the first, therefore it's better to turn them off in order.
first screen is reachable with computer setting, while the other is on the screen setting (right click properties on desktop)

Windows normally have it TURNED ON. and THIS IS THE NORMAL SETTING.

however, on some configuration, because some user change default font and default color or THEME, it CAN cause problem.

to ensure problem is NOT comming from that, I suggest you try turning it OFF

once that will be rules out, I'll suggest more solutions.

there is about 7 post sp6 patch, I'll list them later, once we've ryules out this problem.
001.PNG
002.PNG
0
 

Author Comment

by:ttobin333
ID: 33710132
Thanks Genetic Wolf, and sorry for the delay!

Anti-aliasing was already off and had no effect on or off.

Now that we have ruled that out, I look forward to your other suggestions.
0
 
LVL 3

Accepted Solution

by:
baffy2000 earned 500 total points
ID: 33714617
Hi ttobin.

Can you let us know which solutions you have tried? Have you tried setting Enabled ro Visible to False and true as suggested above? Have you tried the API solution?

Thinking about using the API again, it may be as simple as sending a WM_PRINT message to the control:

http://msdn.microsoft.com/en-us/library/dd145216(v=VS.85).aspx

or maybe even a WM_NCPAINT

http://msdn.microsoft.com/en-us/library/dd145212(v=VS.85).aspx
0
 
LVL 3

Expert Comment

by:Genetic_Wolf
ID: 33722899
plz post the code of the defective behavior.
send the code you'Re using that lead to that behavior as I cannot reproduce it on any of my WinXp box.

regards.
0
 

Author Closing Comment

by:ttobin333
ID: 33795143
Thanks!!!  WM_NCPAINT did the trick!
0
 
LVL 3

Expert Comment

by:baffy2000
ID: 33796362
Excellent!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now