how to draw a string to a picturebox in XOR mode

as the question title says, I want to know how I can draw a string to a picturebox in XOR mode so that I can easily erase it later by drawing it in the same position again.
thanks for ur attention.

wyldsj
wyldsjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rosborn051498Commented:
Instead of "drawing" the string, put a label control in the picture box with the label's Backstyle property = 0 (transparent).  You can put a bitmap in the picture box, and just update the caption of the label.  The picture box will take care of XORing.
0
wyldsjAuthor Commented:
sorry rosborn, but my label has to be drawn upon a PictureBox and I didn't seem to be able to bring the label to front by ZOrder() method(the label is hidden behind the picturebox)

wyldsj
0
bin_huwairibCommented:
wyldsj,

It seems that you place the label control outside the picture control boundaries that is why it is hidden behind the picture box.
Label control must be in the picture box in order to solve your problem, and to do select the label control and use Edit/Cut command from VB main menu then select the picture box and use Edit/Paste command. Now the label control becomes a child in the picture box.

Best regards
Bin Huwairib
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

wyldsjAuthor Commented:
thanks, bin_huwairib. I am able to put a label control on the picture box now. The problem now is that because I have to update the label's position very frequently(it traces the mousemove message), my windows's client area has strong flickering. I think I still have to use the XOR method...Is there any windows api can do this?
0
swiltCommented:
I have not used xor mode, instead I set the ForeColor to the BackColor.  Take out the me.Show if the form is already loaded  


    Dim nFore As Long
   
    Me.Show 'use this line if in Form_Load
   
    Picture1.CurrentX = 100
    Picture1.CurrentY = 300
    Picture1.Print "Hello"
   
    nFore = Picture1.ForeColor
    Picture1.ForeColor = Picture1.BackColor
   
    MsgBox ""
   
    Picture1.CurrentX = 100
    Picture1.CurrentY = 300
    Picture1.Print "Hello"
   
    Picture1.ForeColor = nFore
   
    Picture1.CurrentX = 100
    Picture1.CurrentY = 600
    Picture1.Print "Goodbye"

0
wyldsjAuthor Commented:
thanks swilt but:

  I have actually used my picturebox as a canvas to do 2-D function plot. So I have used the Line function heaviliy. Although my picturebox's background color is gray, my line color is not(red instread). When I use ur method, my drawings are corrupted by the output string...

wyldsj
0
rosborn051498Commented:
Does the text actually move around?  Or does it remain in the same place and just update the mouse position?  If it remains still, you can reduce flicker by only updating the part that changes.  For example, one label says "X position: " , and another label has the current X position.  Only the second label needs to be updated.

If the text moves around, all you have to do is change the Left and Top properties of the label control (I'm sure you already knew this) to get it to move around.  

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Label1.Left = X
    Label1.Top = Y

End Sub

This does create some flicker, but MouseMoves happen very rapidly.  I'm not sure that using an API would be that much better.


0
wyldsjAuthor Commented:
hi rosborn,

  Thanks for your help all the way. Unfortunately my label needs to move around and the flickering is just too much...
0
zsiCommented:
wyldsj,

You do not want to use a label at all.  What you need to do is create a copy of the picturebox without the label and store it in memory.  Draw your text on the picture box wherever you need it.  When it is time to erase the text, simply copy the saved copy of the picture back into the screen.

You can do this one of two ways.  

The easiest is to create a picture object and store the picture there.  Then, when you need to refresh the screen, just set the picture property of the PictureBox control to the PIcture object.

The other way of doing this is through the API.  However, for your needs, the Picture object should suffice.

When you need to update your picture (such as plotting new data), do your drawing onto  the picture object, and then copy the object into the PictureBox as described above.

Essentially, the picture object is being used as a buffer, which is the proper way to render graphics anyway.  It is always faster to do it offscreen.

Hope this helps!
zsi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wyldsjAuthor Commented:
Hello zsi,

  I did as you said but it still gives me flickering(strong flickering). However, I suspect whether there is something wrong with my own settings. Last time when I tried to do some simple animation by changing the picture of a picturebox in sequence, it also gave me flickering. I would like to do whether you have encountered this problem, and whether there is any idea of what is going wrong...
  Thanks a lot for your help.

Sun Jian
0
zsiCommented:
You have to use a technizue known as "double buffering", which I described above.  If you do it correctly, drawing offscreen, you should not have any flickering.  If you would like me to look at your code, you can send it to expert@zs.com
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.