1

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

Ace
  • 1,437
  • 6
  • 28
  • 46

2 Answers2

3

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());
        }
    }
}
txtechhelp
  • 6,625
  • 1
  • 30
  • 39
  • what exactly is GDI+ ? and what can i do with this ? would it be a performance diference if i would make the ( game i want to implement later into the ) client programm as a WPF window application instead of ceep it as a winform application ? ( the game is D3D based and will be aded into a winform window with a framework ) – Ace Oct 29 '12 at 18:29
  • and do you have an axample or step by step instruction for making those dll's ? – Ace Oct 29 '12 at 18:30
  • isn't that a image manipulating api ? i just need to make my splashscreen look like the one of Adobe PS cs6, where the mouse can click THROUGH the blank parts of the image that represents the splash screen – Ace Oct 29 '12 at 18:42
  • You have a lot of different technologies intermixed, WPF, WinForms, D3D. What specifically are you trying to accomplish? If you're using the winforms app to merely load a game you created in D3D, stick with the D3D and just create a new main splash screen in that. What will your C# application be doing specifically to interact with the game? – txtechhelp Oct 29 '12 at 18:43
  • Sorry, I posted my previous comment before I got to read the other, but yes, GDI+ is essentially an image manipulation API (Graphic Device Interface), it allows C/C++ programs to mess with vector (2D) graphics, which gives the capability of what you want, but if all you want is simple splash screen reference this: http://stackoverflow.com/questions/9666910/semi-transparent-png-as-splash-screen – txtechhelp Oct 29 '12 at 18:50
  • so in C# i did a clientForm.cs - in this form, there will be D3D embedet later on. but for now i want to make a "loading screen" while the programm is starting / connecting to the server, and because i want the bg-image of this loading screen to be dynamic ( will be loaded from server each time ) and also have transparent parts and an abstract shape, i thought of making that loading screen as a WPF application, because if i use transparency key in a WinForm, it causes come issues with smooth endges and it looks creepy. – Ace Oct 29 '12 at 18:54
  • the link you've just postet is one of MY older questions, and it doesnt ansers my question , HOW CAN I CALL THAT WPF WINDOW FROM THE MAIN WIN FORM and also interact wich it., so i just need to know how to make these dll of that WPF... – Ace Oct 29 '12 at 18:56
  • Window w = new Window1(); System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(w); w.Show(); – Bizhan Oct 29 '12 at 19:05
0
  1. Create a Windows Form
  2. set its FormBorderStyle to None
  3. set its TransparencyKey to #00FF00
  4. set its BackgroundImage to a png image with unwanted area colors set to #00FF00
  5. done!

when 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.

Bizhan
  • 16,157
  • 9
  • 63
  • 101
  • nice try, but as i've commented down there, using the transparency key causes terrible looking pixels with smooth and oundet images – Ace Oct 29 '12 at 18:58