Reputation: 1467
i want to make Form loading a splash screen with transparent background and a non rectangular shape with is click-through-able. is this possible ? how it's made ?
i was wondering if there is a way of making the Form1 calling a WPF window ( as a kind of splash screen ) within the same vs project.
i've tryed to rightclick the project in the project-explorer in VS -> add and then i was searching for WPF window. but the only thing that i am able to add is a "wpf User Controll".
so far so good, but if i start the application then, it gives me an error saying i should ad a reference to System.Windows.markup.IQueryAmbient, but i cant find it in the list ( .NET )
what am i doing wrong ? what is the propper way to implement a WPF window into a Forms application project ?
thanks for all suggestions.
EDIT:
this is the splash screen of Adobe Flash Professional CS6, and it pretty much explains exactly what i want to have. a non rectangular image with semi-transparent and full-transparent parts in it http://webalazar.com/wp-content/uploads/2012/09/Adobe-Flash-Professional-CS6.png
Upvotes: 1
Views: 2773
Reputation: 6752
There's 3 ways to do this:
1.) go completely WPF and then reference the WinForms .NET libraries in your WPF application if you want WinForms specific stuff
2.) Create a new WPF library (a .NET dll that can be referenced in your code) that has all the WPF functionality you want in it (like your splash screen), then create a new WinForms .NET app and reference the WPF project in your WinForms project then call your WPF library from your WinForms app
3.) Depending on what your trying to accomplish (like special graphics windows or other 'fancy' UI stuff), and how much time/effort you're willing to put into it, you could learn DirectX, or use the 'gdi32.dll' and import it's GDI+ functionality.
EDIT:
So here's a step by step to get a WPF splash screen in a WindowForm C# app:
1.) Create a new C# Windows Forms appliction, call it whatever you want and save it wherever you want
2.) File->Add->New Project
3.) Add a new C# WPF User Control Library, call it SplashScreen and be sure to note that it will try and save it under the same file location, so if you want to save it else where be sure to choose a different location.
4.) Delete the default 'UserControl1.xaml' that's created in the SplashScreen WPF library
5.) Right click the WPF project and 'Add->Window', then name it SplashScreen.xaml
6.) Replace all of the exisiting code in SplashScreen.xaml with the following:
<Window x:Class="SplashScreen.SplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" Background="Transparent" AllowsTransparency="True"
ShowInTaskbar="False" SizeToContent="WidthAndHeight"
Title="SplashScreen" WindowStartupLocation="CenterScreen">
<Image Source="logo.png" Stretch="None" />
</Window>
7.) Right click the WPF project and 'Add->Existing Item', make sure your file filter is set to 'all files' and choose your 'logo.png'.
8.) View the properties of the newly imported 'logo.png' and make sure its 'Build Action' is set to 'Resource'
9.) In your Windows Forms project right click 'Add->New Reference', select the 'Projects' tab and select the 'SplashScreen' WPF project you just created.
10.) In your Windows Forms project right click 'Add->New Reference', select the '.NET' tab and select the 'PresentationFramework','PresentationCore', 'WindowsBase' and 'System.Xaml' libraries.
11.) In your 'Program.cs' file in your Windows Forms project, you can now do this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyGame
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Create a new 'splash screen instance
SplashScreen.SplashScreen ss = new SplashScreen.SplashScreen();
// Show it
ss.Visibility = System.Windows.Visibility.Visible;
// Forces the splash screen visible
Application.DoEvents();
// Here's where you'd your actual loading stuff, but this
// thread sleep is here to simulate 'loading'
System.Threading.Thread.Sleep(5000);
// Hide your splash screen
ss.Visibility = System.Windows.Visibility.Hidden;
// Start your main form, or whatever
Application.Run(new Form1());
}
}
}
Upvotes: 3
Reputation: 17085
FormBorderStyle
to NoneTransparencyKey
to #00FF00BackgroundImage
to a png image with unwanted area colors set to #00FF00when you load an image as background image for your form, it will compare every pixel of it with the transparency key, if it was a match, then it will render that pixel as transparent.
Upvotes: 0