Search Chirayu Software Solutions Blog

Monday, October 8, 2012

Shaped WPF Form

Step - 1 Download this  image

Step -2 

Open Visual Studio 2010 and create new project.
Under Visual C# project templates, select Windows>>WPF Application.
Use the following XAML:
               <Window x:Class="ShapedWPFForm.ShapedWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShapedWindow" Height="267" Width="620"
    Background="Transparent" WindowStyle="None" OpacityMask="White"
    AllowsTransparency="True" WindowStartupLocation="CenterScreen">
    <Grid>
        <Image Name="imgBackground" Stretch="Fill" Source="Shape.png" />
        <Label Height="26" Margin="280,55,244,0" Name="lblUserName" VerticalAlignment="Top" FontWeight="Bold" Foreground="Azure"></Label>
            
        <Label Height="26" Margin="280,83,244,0" Name="lblPassword" VerticalAlignment="Top" FontWeight="Bold" Foreground="Azure">
           
        </Label>
        <Button Height="25" HorizontalAlignment="Right" Margin="0,0,97,54" Name="btnLogin" VerticalAlignment="Bottom" Width="131" FontSize="12" >
            
        </Button>
        <TextBox Height="24" HorizontalAlignment="Right" Margin="0,55,89,0" Name="txtUserName" VerticalAlignment="Top" Width="149" />
        <TextBox Height="24" HorizontalAlignment="Right" Margin="0,85,89,0" Name="txtPassword" VerticalAlignment="Top" Width="149" />
    </Grid>
</Window>


And that's it, it's done. :)
Let me explain the XAML:
  1. allowstransparency="True" - This property makes the Form transparent.
  2. background="Transparent" - This property specifies that the background color should be transparent.
  3. windowstyle="None" - This property removes the title bar and makes the form borderless. Basically removes all the system controls from the form.
  4. opacitymask="White" - This property makes the specified background color invisible from the form.
Post a Comment