Click here to Skip to main content
15,917,591 members
Home / Discussions / C#
   

C#

 
AnswerRe: unsupported key version of Licensing.Net Pin
OriginalGriff22-Sep-15 20:28
mveOriginalGriff22-Sep-15 20:28 
QuestionQuery a DataSet C# - Array Throwing Null Error Pin
Member 1195658922-Sep-15 10:50
Member 1195658922-Sep-15 10:50 
AnswerRe: Query a DataSet C# - Array Throwing Null Error Pin
Garth J Lancaster22-Sep-15 13:58
professionalGarth J Lancaster22-Sep-15 13:58 
AnswerRe: Query a DataSet C# - Array Throwing Null Error Pin
Agent__00722-Sep-15 17:11
professionalAgent__00722-Sep-15 17:11 
AnswerRe: Query a DataSet C# - Array Throwing Null Error Pin
Winner7823-Sep-15 22:52
Winner7823-Sep-15 22:52 
QuestionInheritage with multiple abstract classes Pin
TMattC22-Sep-15 8:57
TMattC22-Sep-15 8:57 
AnswerRe: Inheritage with multiple abstract classes Pin
TMattC22-Sep-15 9:24
TMattC22-Sep-15 9:24 
AnswerRe: Inheritage with multiple abstract classes Pin
BillWoodruff22-Sep-15 9:42
professionalBillWoodruff22-Sep-15 9:42 
Questionfonts are Changing alone in a strange way - Windows CE , i update my first question Pin
goldsoft22-Sep-15 2:53
goldsoft22-Sep-15 2:53 
AnswerRe: fonts are Changing alone in a strange way - Windows CE , i update my first question Pin
OriginalGriff22-Sep-15 3:00
mveOriginalGriff22-Sep-15 3:00 
GeneralRe: fonts are Changing alone in a strange way - Windows CE , i update my first question Pin
goldsoft22-Sep-15 4:15
goldsoft22-Sep-15 4:15 
GeneralRe: fonts are Changing alone in a strange way - Windows CE , i update my first question Pin
OriginalGriff22-Sep-15 4:24
mveOriginalGriff22-Sep-15 4:24 
AnswerRe: fonts are Changing alone in a strange way - Windows CE , i update my first question Pin
Pete O'Hanlon22-Sep-15 4:49
mvePete O'Hanlon22-Sep-15 4:49 
QuestionHow to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr22-Sep-15 1:06
Benjamin.Buhr22-Sep-15 1:06 
AnswerRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen22-Sep-15 1:15
professionalEddy Vluggen22-Sep-15 1:15 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr22-Sep-15 1:36
Benjamin.Buhr22-Sep-15 1:36 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen22-Sep-15 2:12
professionalEddy Vluggen22-Sep-15 2:12 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr24-Sep-15 1:09
Benjamin.Buhr24-Sep-15 1:09 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen24-Sep-15 1:20
professionalEddy Vluggen24-Sep-15 1:20 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr24-Sep-15 2:23
Benjamin.Buhr24-Sep-15 2:23 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen24-Sep-15 3:46
professionalEddy Vluggen24-Sep-15 3:46 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr25-Sep-15 0:08
Benjamin.Buhr25-Sep-15 0:08 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr28-Sep-15 1:39
Benjamin.Buhr28-Sep-15 1:39 
My corrections didn't work Frown | :( ...

So I will now try this way:

Now my MainWindow.xaml.cs is coded this way:
C#
using System;
using System.Diagnostics;
using System.Windows;
using System.Runtime.InteropServices;

namespace Technewlogic.Samples.WpfModalDialog
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    public partial class MainWindow : Window
	{
        // 28.09.2015: C# Check If Application Is Already Running Then Set Focus
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll")]
        private static extern bool IsIconic(IntPtr hWnd);
            /*
            const int SW_HIDE = 0;
            const int SW_SHOWNORMAL = 1;
            const int SW_SHOWMINIMIZED = 2;
            const int SW_SHOWMAXIMIZED = 3;
            const int SW_SHOWNOACTIVATE = 4;
            const int SW_RESTORE = 9;
            const int SW_SHOWDEFAULT = 10;
            */
        const int swRestore = 9;

        // 25.09.2015: Timer fiering
        System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            //MessageBox.Show("Popup: MainWindow_TimerTick");
            // 28.09.2015: C# Check If Application Is Already Running Then Set Focus
            var me = Process.GetCurrentProcess();
            var arrProcesses = Process.GetProcessesByName(me.ProcessName);

            if (arrProcesses.Length > 1)
            {
                for (var i = 0; i < arrProcesses.Length; i++)
                {
                    if (arrProcesses[i].Id != me.Id && arrProcesses[i].SessionId == me.SessionId)
                    {
                        // get the window handle
                        IntPtr hWnd = arrProcesses[i].MainWindowHandle;
                        // if iconic, we need to restore the window
                        if (IsIconic(hWnd))
                        {
                            ShowWindowAsync(hWnd, swRestore);
                        }
                        // bring it to the foreground
                        SetForegroundWindow(hWnd);
                        break;
                    }
                }
            }
        }

        // Main Window
        public MainWindow()
		{
			
			//Alt-Tab preventing
			Window w = new Window(); // Create helper window
        	w.Top = -100; // Location of new window is outside of visible part of screen
        	w.Left = -100;
        	w.Width = 1; // size of window is enough small to avoid its appearance at the beginning
        	w.Height = 1;
        	w.WindowStyle = WindowStyle.ToolWindow; // Set window style as ToolWindow to avoid its icon in AltTab 
        	w.Show(); // We need to show window before set is as owner to our main window
        	this.Owner = w; // Okey, this will result to disappear icon for main window.
        	w.Hide(); // Hide helper window just in case

            // 25.09.2015: Timer settings
            dispatcherTimer.Tick += dispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
            dispatcherTimer.Start();
            //Initialisierung der Komponenten
            InitializeComponent();
			ModalDialog.SetParent(ModalDialogParent);
		}

        // ModalDialog
        private void ShowModalDialog_Click(object sender, RoutedEventArgs e)
    	{
            var res = ModalDialog.ShowHandlerDialog(MessageTextBox.Text);
			var resultMessagePrefix = "Result: ";
			if (res)
				ResultText.Text = resultMessagePrefix + "OK";
			else
				ResultText.Text = resultMessagePrefix + "Break";
		}
	}
	
}

GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen28-Sep-15 5:38
professionalEddy Vluggen28-Sep-15 5:38 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr28-Sep-15 22:49
Benjamin.Buhr28-Sep-15 22:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.