Click here to Skip to main content
15,889,858 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to start a form without being activated? Pin
OriginalGriff21-Oct-17 0:03
mveOriginalGriff21-Oct-17 0:03 
GeneralRe: How to start a form without being activated? Pin
BillWoodruff21-Oct-17 0:27
professionalBillWoodruff21-Oct-17 0:27 
GeneralRe: How to start a form without being activated? Pin
OriginalGriff21-Oct-17 0:41
mveOriginalGriff21-Oct-17 0:41 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 7:04
alin121-Oct-17 7:04 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 7:00
alin121-Oct-17 7:00 
AnswerRe: How to start a form without being activated? Pin
Sascha Lefèvre21-Oct-17 7:20
professionalSascha Lefèvre21-Oct-17 7:20 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 11:40
alin121-Oct-17 11:40 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre21-Oct-17 12:28
professionalSascha Lefèvre21-Oct-17 12:28 
The "override ShowWithoutActivation"-method works for me - on Windows 7.

For testing I made two projects, one Forms-Project, one Console-Project. The Console-Project is basically mimicking XnView starting your app.

Essentials of the Forms-Project:
C#
static class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        bool withoutActivation = false;
        if (args.Length > 0 && !String.IsNullOrWhiteSpace(args[0]))
            withoutActivation = args[0] == "1";

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1(withoutActivation));
    }
}

public partial class Form1 : Form
{
    private bool WithoutActivation;

    public Form1(bool withoutActivation)
    {
        WithoutActivation = withoutActivation;

        InitializeComponent();

        // I placed a lone label on the form:
        label1.Text = WithoutActivation ? "without activation" : "with activation";
    }

    protected override bool ShowWithoutActivation
    {
        get
        {
            return WithoutActivation;
        }
    }
}


Essentials of the Console-Project:
C#
class Program
{
    static void Main(string[] args)
    {
        bool withoutActivation = false;
        while (!Console.KeyAvailable)
        {
            Thread.Sleep(3000);
            Process.Start("[path to forms-app.exe goes here]", withoutActivation ? "1" : "0");
            withoutActivation = !withoutActivation;
        }
    }
}


Every second "invocation" of the forms-app steals the focus from the currently active app, every other one does not.

Edit: Just realized that I didn't do the "start minimized" part (it's late here..). When I do show it minimized (by inserting WindowState = FormWindowState.Minimized; after InitializeComponent();) then neither "invocation" steals the focus, regardless whether WithoutActivation is true or false. So either Windows 10 behaves differently there or you're doing something not quite right.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 13:54
alin121-Oct-17 13:54 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre21-Oct-17 20:59
professionalSascha Lefèvre21-Oct-17 20:59 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 1:57
alin122-Oct-17 1:57 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 2:07
professionalSascha Lefèvre22-Oct-17 2:07 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 2:17
alin122-Oct-17 2:17 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 2:51
professionalSascha Lefèvre22-Oct-17 2:51 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 3:22
alin122-Oct-17 3:22 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 3:33
professionalSascha Lefèvre22-Oct-17 3:33 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 3:35
professionalSascha Lefèvre22-Oct-17 3:35 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 4:14
alin122-Oct-17 4:14 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 4:19
professionalSascha Lefèvre22-Oct-17 4:19 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 5:11
professionalSascha Lefèvre22-Oct-17 5:11 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 5:53
alin122-Oct-17 5:53 
AnswerRe: How to start a form without being activated? Pin
Eddy Vluggen21-Oct-17 12:56
professionalEddy Vluggen21-Oct-17 12:56 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 14:22
alin121-Oct-17 14:22 
GeneralRe: How to start a form without being activated? Pin
Dave Kreskowiak22-Oct-17 2:03
mveDave Kreskowiak22-Oct-17 2:03 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 2:12
alin122-Oct-17 2:12 

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.