iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > PictureBox / Label / BitBlt problem


Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2004, 01:31 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Exclamation PictureBox / Label / BitBlt problem

Hi, im having a problem involving a PictureBox, Label and BitBlt.

My situation is, im programming a game, and i need to have a label be placed ontop of a Picture (using the picturebox control). The reason why it has to be a picturebox, and not an image, is because i am having to use the BitBlt function (-so..i need to use a picturebox).. So, my basic problem is that i cant figure out how to place a label over a picturebox, and have the BitBlt image placed over the label.. Everytime i try to mess around with it, the picturebox always ends up ontop of the label.. Is there any alternative method to place a label ontop of a picturebox? Help would be greatly appreciated

thanks,
-nick

Last edited by nicknick; 02-29-2004 at 12:38 PM.
Reply With Quote
  #2  
Old 02-28-2004, 05:10 PM
hDC_0 hDC_0 is offline
Junior Contributor

Preferred language:
* Expert *
 
Join Date: Feb 2004
Posts: 259
Default It's all about device contexts...

Quote:
Originally Posted by nicknick
Hi, im having a problem involving a PictureBox, Label and BitBlt.

My situation is, im programming a game, and i need to have a label be placed ontop of a Picture (using the picturebox control). The reason why it has to be a picturebox, and not an image, is because i am having to use the BitBlt function (-so..i need to use a picturebox).. So, my basic problem is that i cant figure out how to place a label over a picturebox, and have the BitBlt image placed over the label.. Everytime i try to mess around with it, the picturebox always ends up ontop of the label.. Is there any alternative method to place a label ontop of a picturebox? Help would be greatly appreciated

thanks,
-nick



nick, the reason you CAN NOT do this is because the label control is a "lightweight" control that has no DC (Device Context - a special reserved memory space) of its own, whereas the picturebox DOES have a device context of its own, so it will always "trump" (or appear atop) any of the lightweight controls (Label, Shape, Image or Line). btw - you were right not to use an image control - they also tend to flicker badly...

What you may need to do is not realign your controls, but re-align your thinking.

Using Bitblt is a good thing-- so why not keep going in that direction. Why not bitblt the text as well...if it's just static text. You could also use Picturebox.Print on a hidden picbox, programmatically mask it, and Bitblt it back to your main picbox.

Another approach to text that needs to be generated on the fly is to use the Textout or Drawtext APIs:
http://www.mentalis.org/apilist/TextOut.shtml#

Textout also allows you to use brushes (like pattern brushes) to get fancy if you want...or another way to "draw' text with fancy pattern fills is to use paths with the StrokeandFillPath API. Look at the bottom of this HardcoreVB page for the code:
http://www.mvps.org/vb/hardcore/html/paths.htm

Whenever I encounter a "wall" in dealing with graphics in VB, it's usually because I need to get more creative with my approach, hopefully you will embrace this philosophy as well.

Once you learn to do things entirely using device contexts in memory you'll find you things a lot less restrictive (that being bound by the limitations inherent in the standard VB controls).

Last edited by hDC_0; 02-28-2004 at 05:18 PM.
Reply With Quote
  #3  
Old 02-28-2004, 05:38 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Default

Thank you SO much. I tried using the TextOut function like you said and it works great, i havnt tried doing all that i need to do with it yet though, so if i run into any other problems or questions, i'll post again probably within the next 2 days. Thanks again, i appreciate your help.
Reply With Quote
  #4  
Old 02-28-2004, 06:56 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Exclamation

Bad news, TextOut doesnt work properly. The text wont show up unless i turn AutoRedraw off, on the object that its printing on. The thing is, i need autoredraw on because of the BitBlt thing. is there any way around this? please, any help would be appreciated.

thank you,
-nick
Reply With Quote
  #5  
Old 02-28-2004, 09:16 PM
hDC_0 hDC_0 is offline
Junior Contributor

Preferred language:
* Expert *
 
Join Date: Feb 2004
Posts: 259
Default

Quote:
Originally Posted by nicknick
Bad news, TextOut doesnt work properly. The text wont show up unless i turn AutoRedraw off, on the object that its printing on. The thing is, i need autoredraw on because of the BitBlt thing. is there any way around this? please, any help would be appreciated.

thank you,
-nick


Actually what i was thinking was to use the Textout in a hidden backbuffer. Here's one way--take a look at Spectre's code postings (especially #9) on this thread:
http://www.xtremevbtalk.com/show...oto=nextoldest

...but here's also some code (and a downloadable sample) that shows how the Textout is used with a memoryDC backbuffer (and then would be bitblt-ed to your picturebox after all other bitblts):

http://www.vb-helper.com/howto_memory_bitmap_text.html
Reply With Quote
  #6  
Old 02-28-2004, 09:31 PM
hDC_0 hDC_0 is offline
Junior Contributor

Preferred language:
* Expert *
 
Join Date: Feb 2004
Posts: 259
Default Alt method for text atop bitblt-ed picbox picture

And if none of those works for you, you can also paste another picture box inside you main picturebox and reshape the picbox into text--check out rpgnewbie's "PicTextShape-Works.zip" demo attached to the bottom of the first post on this thread:
http://www.xtremevbtalk.com/t139212.html
Reply With Quote
  #7  
Old 02-28-2004, 10:06 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Default

Thanks,

It's the second link that you posted is what im focusing on. The first link seemed to focus just on TextOut using a backbuffer, i tried it out but it still didnt solve much, all it did was put the text in a backbuffer before it was displayed. The second link is pretty much exactly what i need, im in the middle of working with it and so far it looks like it'll do the job. I'll post again if i need any more help,

thank you
Reply With Quote
  #8  
Old 02-28-2004, 10:21 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Default

oops, looks like i posted a responce after you did. That 'second link' that i was talking about earlier looks like it wont work for my situation. It seemed like it WOULD work, but it clears the picture out of the picturebox when the code is executed. So, the text wont go ontop of the picturebox, it'll just replace the picture. Ive played around with it alot and i cant seem to get it to stop clearing the picture, so it looks like both those links didnt help. Right now im looking at the site on your last post and from what ive read, it seems that this might be the one that will do the trick. I'll post again to let ya know how it came along.

Thanks
Reply With Quote
  #9  
Old 02-29-2004, 12:11 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Exclamation

i tried the code on that last link, but im having trouble with how its being displayed. Im shrinking the font to about 10 using Arial and bold is off. When i do that, some of the pixels on the letters will become transparent and look funny.. Any suggestions?

How would i go about BitBlt'ing text in a picturebox?.. i was fooling around with it and saw if i typed Picture1.Print "blah", the word 'blah' would appear in the picturebox. I tried programming a mask for it by choosing a black forecolor, and a white backcolor, but it didnt seem to work when i bitblt'ed it. So, is there a way that i could make 2 of them, one of them being a mask, and bitblt it? This will probably be my last resort (bitblt'ing the text), but, it seems like it would be the most efficient since i use the bitblt function several times in my program. Thanks

-nick

Last edited by nicknick; 02-29-2004 at 12:27 PM.
Reply With Quote
  #10  
Old 02-29-2004, 04:38 PM
hDC_0 hDC_0 is offline
Junior Contributor

Preferred language:
* Expert *
 
Join Date: Feb 2004
Posts: 259
Default Karl Peterson's Stroke and Fill Path works

Quote:
Originally Posted by nicknick
i tried the code on that last link, but im having trouble with how its being displayed. Im shrinking the font to about 10 using Arial and bold is off. When i do that, some of the pixels on the letters will become transparent and look funny.. Any suggestions?

How would i go about BitBlt'ing text in a picturebox?.. i was fooling around with it and saw if i typed Picture1.Print "blah", the word 'blah' would appear in the picturebox. I tried programming a mask for it by choosing a black forecolor, and a white backcolor, but it didnt seem to work when i bitblt'ed it. So, is there a way that i could make 2 of them, one of them being a mask, and bitblt it? This will probably be my last resort (bitblt'ing the text), but, it seems like it would be the most efficient since i use the bitblt function several times in my program. Thanks

-nick


I downloaded TextOutline.zip from:
http://www.mvps.org/vb/index2.html?samples.htm

I really think this is what you need.

I worked up a sample using a bitblt-ed background and it worked fine. I just added a picHidden, then a command button and bitblt-ed the background from picHidden to Picture1 using SrcCopy. Then when you click on picture1 the text is inserted at the click point to draw the text (or you can paste the same Picture1_Click event code into a command button, supply your own x,y values and it would work the same).

I was going to upload it last night, but since most of the code (including the two classes) is copyrighted from Mr Peterson it wouldn't be right. The only difficulty I could see adapting the code to use bitblt-ing if you had the wrong AutoReDraw settings for the two pictureboxes.

The only other way I know to help is to just have you post your project as an attachment and I would add the textout code and I would modify the project to add the textout and re-upload it when I get home tonight (late).

Your Picture1.Print should work also. Just have two Pictureboxs, picHidden1 and picHidden2. The one that prints in black on white background would be your mask and the colored text with white background would be the bitblt that shows. You probably already know to use vbSrcAnd for the mask and vbSrcPaint for the bitblt image that shows, so i don't know what else I could tell you to get it to work except use the right AutoRedraw settings, and maybe try Picture1.Refresh or Picture1.Picture = Picture.Image to move the image from the picbox hdc backbuffer to the foreground Picture property. Good Luck
Reply With Quote
  #11  
Old 02-29-2004, 06:08 PM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Default

So far my project is almost 6mb, and im not even half way done with it, so uploading it is out of the question (me being a 56k'er). Im going to keep messing around with it but it looks like im just going to simplify what i was wanting to do, to save time and trouble. I'll be using the Picture1.Print "whatever" command, because it seems to be the most useful.

My question is, when using the Picture1.Print "whatever" command, is there a way to specify the x and y coordinates? This isnt information that i absolutely need to know, since i'll probably just end up finding a way around it, but if there is, can anyone post it, or an example of it? I'm sure i wont be the only one who will benefit from an example of an x,y specified Picture1.Print command.

Thank you
Reply With Quote
  #12  
Old 03-01-2004, 04:14 AM
hDC_0 hDC_0 is offline
Junior Contributor

Preferred language:
* Expert *
 
Join Date: Feb 2004
Posts: 259
Default Picture1.Print CurrentX CurrentY

Quote:
Originally Posted by nicknick
I'm sure i wont be the only one who will benefit from an example of an x,y specified Picture1.Print command.
Thank you



Use CurrentX and CurrentY. Here's 2 threads where Passel shows how:
setting to 0,0 relative, post#3:
http://www.xtremevbtalk.com/t92521.html

See post #5 for centering text in window using currentX and currentY:
http://www.xtremevbtalk.com/t134894.html
Reply With Quote
  #13  
Old 03-01-2004, 07:20 AM
nicknick nicknick is offline
Newcomer
 
Join Date: Feb 2004
Posts: 22
Default

Awesome! That solves everything, thank you!


Looks like i was right! http://www.xtremevbtalk.com/showthread.php?p=668877 this person can use the currentx, currenty, .print, method like i am. Thanks again hDC_0

Last edited by nicknick; 03-01-2004 at 07:32 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu / bitblt problem DeuxExeMachina Game Programming 5 01-09-2004 05:46 PM
Bitblt animation?? SockBox Game Programming 5 08-30-2003 08:03 AM
Label Control Refresh Problem eemcclure Interface and Graphics 2 03-02-2003 12:01 PM
problem with user dragging a Label crazycheetah General 5 07-13-2002 05:19 PM
Picturebox and BitBlt gimpelzack General 1 05-16-2002 05:14 AM

Advertisement: