Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8
This is the forum to discuss the Wrox book Visual Basic 2008 Programmer's Reference by Rod Stephens; ISBN: 9780470182628
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 5th, 2010, 02:24 AM
Registered User
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default TransparencyKey Does Not Work on Non Development Computer

In chapter 10 "Windows Forms", one of the properties that is discussed is the TransparencyKey. I decided to write a simple program to try this out. When I run the program on my development computer, whether inside the IDE or not, it works as expected. If I copy the exe to another computer and run it, the background shows up - it is not transparent.

I downloaded the sample program from the web site and found I get the same results. Is there anything I need to do to get this to work on other computers?

Thanks,

Greg
Reply With Quote
  #2 (permalink)  
Old April 29th, 2010, 12:39 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

Sorry for the slow reply. I lost track of this in my inbox.

I don't know why this would work on one machine and not another. Perhaps there's something graphics related installed by Visual Studio, but that would be a bit weird.

I have noticed that TransparencyKey doesn't seem to work as well as it used to.

One workaround is to set the form's Region property to a region that restricts it. For example:

Code:
    Private Sub Form1_Load(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles MyBase.Load
        ' Make points to define a polygon for the form.
        Dim pts(0 To 9) As PointF
        Dim cx As Single = Me.ClientSize.Width * 0.5
        Dim cy As Single = Me.ClientSize.Height * 0.5
        Dim r1 As Single = Me.ClientSize.Height * 0.45
        Dim r2 As Single = Me.ClientSize.Height * 0.25
        Dim theta As Single = -PI / 2
        Dim dtheta As Single = 2 * PI / 10
        For i As Integer = 0 To 9 Step 2
            pts(i) = New PointF( _
                cx + r1 * Cos(theta), _
                cy + r1 * Sin(theta))
            theta += dtheta
            pts(i + 1) = New PointF( _
            cx + r2 * Cos(theta), _
            cy + r2 * Sin(theta))
            theta += dtheta
        Next i

        ' Use the polygon to define a GraphicsPath.
        Dim path As New GraphicsPath()
        path.AddPolygon(pts)

        ' Make a region from the path.
        Dim form_region As New Region(path)

        ' Restrict the form to the region.
        Me.Region = form_region
    End Sub
I'll post a complete example in the next couple days at http://www.vb-helper.com/howto_net_set_form_region.html. (No time now.)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #3 (permalink)  
Old April 29th, 2010, 02:01 AM
Registered User
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After posting my question, I went over to Microsoft's knowledgebase and discovered this is a known bug. Here's their article BUG: The TransparencyKey property is not effective...

I tried the workaround they gave but still couldn't get it working. Part of the problem is that they gave a VB2005 example and I wasn't sure where that code should go in VB2008.

Anyway, I was just playing around with this out of curiosity. So, while I wished it worked, it's not critical.

On another topic, I'm slowly reading through your book. This is mainly a review for me. I just want to make sure I'm not missing anything. I just read your discussion of AndAlso and OrElse. While the example you gave of having a time consuming function call as the second operand is a good one, I think you should also have used this example:

Code:
if x <> 0 And y/x > 1 then
vs

Code:
if x <> 0 AndAlso y/x >1 then
The "And" version looks like it should work, but will throw an exception if x is zero, while the "AndAlso" version works as expected.

Thanks for the help.


Greg
Reply With Quote
  #4 (permalink)  
Old April 29th, 2010, 09:02 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Thumbs up Good example

That's a good example. Using the first test to ensure that the second makes sense before trying the second. It's easy enough to do with nested Ifs but this is cleaner.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SendKeys do not work when computer is locked desperado1306 Excel VBA 0 June 2nd, 2006 01:41 AM
My.Computer problem sir_drinxalot BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 April 3rd, 2006 08:31 PM
how do i get computer name shankhan Javascript How-To 0 May 28th, 2005 03:43 PM
Ping another computer nvillare .NET Web Services 0 November 30th, 2003 03:05 PM



All times are GMT -4. The time now is 05:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.