Hack Forums
[C#] Images behind a form, transparent - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Images behind a form, transparent (/showthread.php?tid=5895058)



Images behind a form, transparent - StaticCG - Oct 13, 2018

I want to accomplish something like this:
[Image: n0Iuin9.jpg]
In a winform. Any ideas?


RE: Images behind a form, transparent - 0xBB - Oct 13, 2018

You could use a layered window to get the main layout form and then use GDI to replicate the rest. But, the best option would be to ditch winforms and go for wpf as that handle transparency very well. Its a decent learning curve if you tackle wpf, but it's worth it, good luck.  🤝


RE: Images behind a form, transparent - itcorp - Oct 14, 2018

(Oct 13, 2018 07:44 PM)StaticC Wrote:  I want to accomplish something like this:
[Image: n0Iuin9.jpg]
In a winform. Any ideas?

I do not see the reason why you do not do this in wpf...but here is one solution at speed in wpf which should be upgraded and improve for your needs.

[Image: RhLy92J.gif]

Code
<Style TargetType="Window" x:Key="StandardWindow">            
           <Setter Property="WindowStyle" Value="None"/>            
           <Setter Property="BorderThickness" Value="0" />
           <Setter Property="Margin" Value="0" />
           <Setter Property="AllowsTransparency" Value="true"/>
           <Setter Property="WindowChrome.WindowChrome">


               <Setter.Value>


                   <WindowChrome
                            CaptionHeight="0"
                            NonClientFrameEdges="None"
                            ResizeBorderThickness="5"
                            GlassFrameThickness="0"
                            CornerRadius="0"
                   
                             />


               </Setter.Value>


           </Setter>

           <Setter Property="Template">
               <Setter.Value>
                   
                       <ControlTemplate TargetType="{x:Type Window}">
                       <Grid>
                           
                           <Grid.RowDefinitions>
                               <RowDefinition Height="60"/>
                               <RowDefinition Height="*"/>
                           </Grid.RowDefinitions>
                           <Grid.ColumnDefinitions>
                               <ColumnDefinition Width="Auto"/>
                               <ColumnDefinition Width="*"/>
                           </Grid.ColumnDefinitions>
                           <Image Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Source="pack://application:,,/Resources/logoass.png"/>

                           <Grid Margin="52,11,0,0"   Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
                               <Grid.Background>

                                   <ImageBrush   ImageSource="pack://application:,,/Resources/ass.png" Opacity="09"  />

                               </Grid.Background>
                               <Grid Margin="-15,-15,-15,-15">
                                   <Grid.Background>

                                       <ImageBrush   ImageSource="pack://application:,,/Resources/diploma-frame-png-3.png"   />

                                   </Grid.Background>
                               </Grid>
                           </Grid>
                           <Image Grid.Row="0" Grid.RowSpan="2" Source="pack://application:,,/Resources/game.png"/>
                           <Grid Margin="150,40,40,35"  Grid.Row="1"  Grid.Column="0" Grid.ColumnSpan="2">
                               <AdornerDecorator >
                                   <ContentPresenter />
                               </AdornerDecorator>
                           </Grid>
                       </Grid>
                   </ControlTemplate>
                 
               </Setter.Value>
           </Setter>
           <Setter Property="WindowStyle" Value="None"/>
       </Style>

Code
       Title="MainWindow" Height="460" Width="800" WindowStartupLocation="CenterScreen" MouseDown="Window_MouseDown"  Style="{StaticResource StandardWindow}">

Code
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
       {
           if (Mouse.LeftButton == MouseButtonState.Pressed)
               this.DragMove();
       }



RE: Images behind a form, transparent - StaticCG - Oct 14, 2018

(Oct 14, 2018 06:38 AM)itcorp Wrote:  I do not see the reason why you do not do this in wpf...but here is one solution at speed in wpf which should be upgraded and improve for your needs.

[Image: RhLy92J.gif]

Code
<Style TargetType="Window" x:Key="StandardWindow">            
           <Setter Property="WindowStyle" Value="None"/>            
           <Setter Property="BorderThickness" Value="0" />
           <Setter Property="Margin" Value="0" />
           <Setter Property="AllowsTransparency" Value="true"/>
           <Setter Property="WindowChrome.WindowChrome">


               <Setter.Value>


                   <WindowChrome
                            CaptionHeight="0"
                            NonClientFrameEdges="None"
                            ResizeBorderThickness="5"
                            GlassFrameThickness="0"
                            CornerRadius="0"
                   
                             />


               </Setter.Value>


           </Setter>

           <Setter Property="Template">
               <Setter.Value>
                   
                       <ControlTemplate TargetType="{x:Type Window}">
                       <Grid>
                           
                           <Grid.RowDefinitions>
                               <RowDefinition Height="60"/>
                               <RowDefinition Height="*"/>
                           </Grid.RowDefinitions>
                           <Grid.ColumnDefinitions>
                               <ColumnDefinition Width="Auto"/>
                               <ColumnDefinition Width="*"/>
                           </Grid.ColumnDefinitions>
                           <Image Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Source="pack://application:,,/Resources/logoass.png"/>

                           <Grid Margin="52,11,0,0"   Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
                               <Grid.Background>

                                   <ImageBrush   ImageSource="pack://application:,,/Resources/ass.png" Opacity="09"  />

                               </Grid.Background>
                               <Grid Margin="-15,-15,-15,-15">
                                   <Grid.Background>

                                       <ImageBrush   ImageSource="pack://application:,,/Resources/diploma-frame-png-3.png"   />

                                   </Grid.Background>
                               </Grid>
                           </Grid>
                           <Image Grid.Row="0" Grid.RowSpan="2" Source="pack://application:,,/Resources/game.png"/>
                           <Grid Margin="150,40,40,35"  Grid.Row="1"  Grid.Column="0" Grid.ColumnSpan="2">
                               <AdornerDecorator >
                                   <ContentPresenter />
                               </AdornerDecorator>
                           </Grid>
                       </Grid>
                   </ControlTemplate>
                 
               </Setter.Value>
           </Setter>
           <Setter Property="WindowStyle" Value="None"/>
       </Style>

Code
       Title="MainWindow" Height="460" Width="800" WindowStartupLocation="CenterScreen" MouseDown="Window_MouseDown"  Style="{StaticResource StandardWindow}">

Code
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
       {
           if (Mouse.LeftButton == MouseButtonState.Pressed)
               this.DragMove();
       }

Thanks!


RE: Images behind a form, transparent - itcorp - Oct 14, 2018

(Oct 14, 2018 08:48 AM)StaticC Wrote:  Thanks!

You are welcome, anytime.