Solved

how to draw a string to a picturebox in XOR mode

Posted on 1998-05-21
11
499 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:wyldsj
[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
  • 2
  • 2
  • +2
11 Comments
 

Expert Comment

by:rosborn051498
ID: 1456814
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
 

Author Comment

by:wyldsj
ID: 1456815
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
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1456816
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
Independent Software Vendors: 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!

 

Author Comment

by:wyldsj
ID: 1456817
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
 
LVL 2

Expert Comment

by:swilt
ID: 1456818
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
 

Author Comment

by:wyldsj
ID: 1456819
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
 

Expert Comment

by:rosborn051498
ID: 1456820
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
 

Author Comment

by:wyldsj
ID: 1456821
hi rosborn,

  Thanks for your help all the way. Unfortunately my label needs to move around and the flickering is just too much...
0
 
LVL 4

Accepted Solution

by:
zsi earned 30 total points
ID: 1456822
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
 

Author Comment

by:wyldsj
ID: 1456823
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
 
LVL 4

Expert Comment

by:zsi
ID: 1456824
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

Featured Post

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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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