iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Shaped PicBox (Picture Box Shape)


Reply
 
Thread Tools Display Modes
  #1  
Old 01-27-2004, 01:08 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default Shaped PicBox (Picture Box Shape)

Thie was a code snippet for making round pictureboxes presented in this thread from "sugared":

http://www.xtremevbtalk.com/t137176.html

I wanted to see if it would actually work so I tried it in a project and of course it doesn't.

I tried different AutoRedraw settings combinations (none worked):
picObject.AutoRedraw = True, Form1.AutoRedraw = True
picObject.AutoRedraw = True, Form1.AutoRedraw = False
picObject.AutoRedraw = False, Form1.AutoRedraw = False
picObject.AutoRedraw = False, Form1.AutoRedraw = True

Here's the code
Code:
'DOESN'T WORK Private Sub cmdMakeRound_Click() Dim i As Long Dim intD As Integer Dim hRgn As Long intD = 1000 BeginPath picObject.hdc picObject.Circle (intD / 2, intD / 2), intD / 2 EndPath picObject.hdc hRgn = PathToRegion(picObject.hdc) SetWindowRgn picObject.hWnd, hRgn, False picObject.Circle (intD / 2, intD / 2), intD / 2, vbBlack End Sub
Here's the code from the modPicBoxShape that I used:
Code:
Public Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long Public Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long Public Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

However I did find some working code that did the same thing with using text as the region shaper:
(I used the same modPicBoxShape.bas code as above):

Code:
'DOES WORK Private Sub Form_Load() Const TXT = "Hello!" Dim i As Long Dim hRgn As Long Picture1.AutoRedraw = True ' Select a big font. Picture1.Font.Name = "Times New Roman" Picture1.Font.Bold = True Picture1.Font.Size = 50 ' Make the PictureBox big enough. Picture1.Width = Picture1.TextWidth(TXT) Picture1.Height = Picture1.TextHeight(TXT) ' Make the clipping path. BeginPath Picture1.hdc Picture1.CurrentX = 0 Picture1.CurrentY = 0 Picture1.Print TXT EndPath Picture1.hdc ' Convert the path into a region. hRgn = PathToRegion(Picture1.hdc) ' Constrain the PictureBox to the region. SetWindowRgn Picture1.hWnd, hRgn, False ' Draw some lines on the form. AutoRedraw = True For i = 0 To ScaleHeight Step 60 Line (0, i)-Step(ScaleWidth, 0), RGB(0, 128, 255) Next i End Sub

The "hRGN" variable shows "O" in the "Private Sub cmdMakeRound_Clic"
when I set a breakpoint at the following line:
SetWindowRgn Picture1.hWnd, hRgn, False

But in the textshape code above it shows a number other than O, so (I guess) in first set of code the line that starts with
"hRgn = PathToRegion " doesn't work and in the second set of code it does. Very curious...

I thought maybe it was the "obj" code so I tried this:

Code:
Private Sub cmdMakeRound_Click() Dim i As Long Dim intD As Integer Dim hRgn As Long intD = 1000 picObject.AutoRedraw = True picObject.CurrentX = 0 picObject.CurrentY = 0 BeginPath picObject.hdc picObject.Circle (intD / 2, intD / 2), intD / 2 EndPath picObject.hdc hRgn = PathToRegion(picObject.hdc) SetWindowRgn picObject.hWnd, hRgn, False picObject.Circle (intD / 2, intD / 2), intD / 2, vbBlack ' Draw some lines on the form. AutoRedraw = True For i = 0 To ScaleHeight Step 60 Line (0, i)-Step(ScaleWidth, 0), RGB(0, 128, 255) Next i End Sub

But it also didn't work...does anyone know why? I'm scratching my head (and probably missing something very obvious...)
Attached Images
File Type: gif picCircleShape_Screenshot-Not_Working.gif (8.1 KB, 18 views)
File Type: gif picTextShape-Working.gif (13.0 KB, 20 views)
Attached Files
File Type: zip PicCircleShape-NotWorking.zip (1.9 KB, 23 views)
File Type: zip PicTextShape-Works.zip (1.8 KB, 36 views)

Last edited by rpgnewbie; 01-27-2004 at 01:18 PM.
Reply With Quote
  #2  
Old 01-27-2004, 01:25 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default

Could it be that the drawn circle isn't considered a path?
Reply With Quote
  #3  
Old 01-27-2004, 02:38 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Preferred language:
Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 6,746
Default

Maybe it depends on the machine?
I loaded the circle code you provided, ran it, clicked the button, and the
green rectangle turned into a green circle (with a black outline). I added
a timer, to move it, and it moved as a circle, with the blue lines being
visible around the periphery of the circle. I didn't modify the code
from your zip file at all (until after seeing it work, I added the timer).

If I set the FillColor of the picturebox to Red, and the FillStyle to Solid,
then when I click the MakeRound button, then I get a Red, Round picturebox
without any rectangular area around it.

So I don't know what your problem is, but I know that graphics do work
differently on some computers, and controls will work differently at times
on different machines.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 01-27-2004 at 02:44 PM.
Reply With Quote
  #4  
Old 01-27-2004, 05:14 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default Thanks Passel!

Quote:
Originally Posted by passel

So I don't know what your problem is, but I know that graphics do work
differently on some computers, and controls will work differently at times
on different machines.



Thanks passel. It was driving me nuts. At least I know the code works on some machines. I am running Win98SE on an old Pentium. What win O/S are you running Win2000/XP?

I think I may just use a font circle (maybe WingDings font) and see if I can get a circle that way.
Reply With Quote
  #5  
Old 01-27-2004, 05:36 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Preferred language:
Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 6,746
Default

I'm at work at the moment, so am running VB5 CCE (the one available
for free, but can't create executables), on a NT 4.0 system. I think it's
probably a Pentium III about 800-900 Mhz. I'm not sure which video
card it has, which would be the most likely thing (it's drivers) to cause
a difference like this.

Interestingly, I noted yesterday, that code I had written at home that
picked a color, set the .forecolor, and used pset to plot random pixels in
that color worked fine at home, but on this machine the pixels all came
up black, regardless of what the .forecolor was set to. I had to specify
the color on the pset line, in order for it to work.

Since it's a work, controlled machine, I don't have priviledges to
change the resolution, or color depth. The current setting is 16 bit color.

And, not graphic related but we had that situation last week, where two
people, both running Windows XP, and VB6 SP5 had a difference in how
a locked textbox acted. On one machine, if the textbox was locked, you
could not paste into the textbox, whereas on the other machine you
could still paste into the box, just not type into it. Who knows what
differences can cause these anomalies. There was some other case, I
can't remember now the specifics, but where the same code worked
differently on two different user's machines, and was causing quite a bit
of frustration between the two parties involved, thinking one was not
understanding the other, when it was really some quirk in the hardware/software.

I guess I'll try it when I get home. I have an older Win98 pentium 200mhz
system that I can try it on, as well as the 2Ghz P4.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #6  
Old 01-27-2004, 09:43 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Preferred language:
Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 6,746
Default

Tried it at home.
Worked fine on the P4 XP machine.
It looked the same as your attachment on my old 200 Mhz, Win 98 system.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #7  
Old 01-28-2004, 05:52 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default Thanks for the follow-up...

Quote:
Originally Posted by passel
Tried it at home.
Worked fine on the P4 XP machine.
It looked the same as your attachment on my old 200 Mhz, Win 98 system.


Thanks for the follow-up. I think the problem is this onboard video chip for a Packard Bell computer. I tried an older driver and got it to work, but had to switch back because the older driver crashes to much on low memory (motherboard is maxed at 256MB). I only use this computer for an internet terminal and to test backward compatibility. It used to be a POS terminal for a used software store that went out of business.

It's interesting to see someone else document this kind of weirdness. I've run into it for years. That's why when I built a computer for someone else I always use ATI video cards. I've found they have the least amount of compatibility issues (but I know some would say the same of NVidia).
Reply With Quote
  #8  
Old 03-03-2004, 05:54 AM
CARL_SIY CARL_SIY is offline
Newcomer
 
Join Date: Feb 2004
Posts: 2
Default

try this code to create ellipse

BAS declaration
Declare Function CreateEllipticRgn Lib "gdi32" Alias "CreateEllipticRgn" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long


Form Declaration
Private Sub Form_Load()

Dim ReturnVal As Long
Me.Show
ReturnVal = SetWindowRgn(Me.hWnd, CreateEllipticRgn(10, 25, 100, _
200), True)

End Sub

reply your question to killing_angel_1@yahoo.com
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
how to save a picture in picbox? bullfrog General 3 09-18-2003 04:06 PM
How to create some hexagonal shape inside picture box meggy_e General 1 07-27-2003 10:26 AM
move shape in picture box jirrah Game Programming 2 03-24-2003 02:03 PM
Form takes the shape of the Picture SoLoGHoST General 17 02-14-2003 11:23 AM

Advertisement: