Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Focusing on Forms and Menus in Visual Basi...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Focusing on Forms and Menus in Visual Basic
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2007-03-01

    Table of Contents:
  • Focusing on Forms and Menus in Visual Basic
  • 4.16 Creating a Fading Form
  • 4.17 Creating a Nonrectangular Form
  • 4.18 Changing Menus at Runtime
  • 4.19 Creating Shortcut Menus

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Focusing on Forms and Menus in Visual Basic - 4.17 Creating a Nonrectangular Form
    (Page 3 of 5 )

    Problem

    You want to display a form that is nonrectangular; that is, you want some of the form to be invisible.

    Solution

    Sample code folder: Chapter 04\PartialInvisibility

    Use the form’sTransparencyKeyproperty to identify a color that will be invisible. The sample code in this recipe uses fuchsia for its “invisible color,” but you can choose any color that meets your display requirements.

    Create a new Windows Forms application. ChangeForm1’sFormBorderStyleproperty toNone, itsStartPositionproperty toCenterScreen, and itsTransparencyKeyproperty toFuchsia. Then add the following source code to the form’s code template:

      Private Sub Form1_Click(ByVal sender As Object, _
           
    ByVal e As System.EventArgs) Handles Me.Click
         ' ----- Any click closes the form.
         Me.Close()

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.PaintEventArgs) _
            Handles Me.Paint
         ' ----- Draw a nice logo form.
         e.Graphics.Clear(Color.Fuchsia)
         e.Graphics.FillRectangle(Brushes.Gold, 0.0F, _
           
    Me.ClientRectangle.Height / 3.0F, _
            CSng(Me.ClientRectangle.Width), _
            Me.ClientRectangle.Height / 3.0F)
         e.Graphics.FillPolygon(Brushes.Gold, New PointF() { _
            New Point(Me.ClientRectangle.Width / 4, 0), _
            New Point
    (Me.ClientRectangle.Width / 2, _
            Me.ClientRectangle.Height / 2), _
            New Point(Me.ClientRectangle.Width / 4, _
            Me.ClientRectangle.Height), _
            New Point(0, Me.ClientRectangle.Height / 2)})
        
    Dim largerFont = New Font(Me.Font.Name, 20)
        
    e.Graphics.DrawString("My Nice Program", _
            largerFont, Brushes.Black, 20, _
            (Me.ClientRectangle.Height / 2) - _
            (largerFont.Height / 2))
      End Sub

    When you run the program, it appears similar to the display in Figure 4-18. (We left the development environment behind the form so that you could see the invisibility.)

    Figure 4-18.  A Form with transparent portions

    Discussion

    The initial release of Visual Basic 2005 included a bug that prevented the transparency color from properly appearing as transparent in some cases. Specifically, if your form included an image that contained the transparency color, and the workstation was using more than 24 bits of color for its display, the image appeared as opaque. To get around this problem, you need to set transparency on the image manually before you draw it:

      Private Sub Form1_Paint(ByVal sender As Object,_
            ByVal e As System.Windows.Forms.PaintEventArgs) _
            Handles Me.Paint
         ' ----- This code assumes that the form's
         '       TransparencyKey property is "Fuchsia".
         Dim logoImage As Bitmap = Bitmap.FromFile( _
           
    "C:\MyLogo.bmp")
         logoImage.MakeTransparent(Color.Fuchsia)
         e.Graphics.DrawImage(logoImage, 0, 0)
      End Sub

    The Microsoft Knowledge Base number for this article is 822495.

    See Also

    Recipe 9.10 discusses invisibility colors and the TransparencyKey property in more detail.

    More Visual Basic.NET Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Visual Basic 2005 Cookbook," published by...
     

    Buy this book now. This article is excerpted from chapter four of the Visual Basic 2005 Cookbook, written by Tim Patrick and John Clark Craig (O'Reilly; ISBN: 0596101775). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway