One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man

Friday, July 1, 2011

WPF transparent form application

1) First you have to create a new WPF application project
                                           File -> New -> project
select WPF application and press OK

2) Then you have to create a circle inside the form using the Ellipse tool in the toolbox
3) After that you have to do few changes to the XAML coding


Your  coding appear like the following


<Window x:Class="MyApp.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Ellipse Margin="-1,-1,-1,1" Name="ellipse1" Stroke="Black"/>
    </Grid>
</Window>


That must change like following


<Window x:Class="MyApp.Window1" MouseLeftButtonDown="Window_MouseLeftButtonDown" WindowStyle="None" AllowsTransparency="True" Background="Transparent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Ellipse Margin="-1,-1,-1,1" Name="ellipse1" Stroke="Black" Fill="Gray" Opacity="0.5"/>
        <Button Height="23" Margin="99,28,104,0" Name="button1" VerticalAlignment="Top">Close</Button>
    </Grid>
</Window>


following picture show you the changes by underlining newly added parts
4) Then double click on the button and write the following coding part
               Close();
5) Then write the following code inside the "Window_MouseLeftButtonDown" method
               DragMove();
   You can see the above 2 steps from the picture
6) Finally build the solution and see the result. you can drag the form by draging the content of the form
This is a very basic WPF form application. You can develop any complex interfaces or application same as the normal windows form application by using this theory