3

I'm developing a Tray application with Borderless Form which runs in the background. if user wants to perform different operations, they can open context menu by right clicking on the tray icon(NotifyIcon).

so my requirements are :

1.Application always starts in minimized mode and trayicon willbe displayed.
2.Application should not be appeared from the Taskbar.
3.Application should not be visible from ALT+TAB menu.

I have implemented above two requirements but while trying to hide the application from ALT+Tab menu it is working (not visible from ALT+TAB) but its creating small edged window with application title at left side corner on top of Taskbar as shown in below image: enter image description here

I want to remove that small edged window.

Here is my code:

    public Form1()
    {
        InitializeComponent();
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        HideThisForm();
    }

    protected override CreateParams CreateParams
    {
        get
        {
            // Turn on WS_EX_TOOLWINDOW style bit
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x80;
            return cp;
        }
    }

    private void HideThisForm()
    {

        this.ShowInTaskbar = false;
        this.WindowState = FormWindowState.Minimized;
        this.Hide();

        notifyApp.Visible = true;
        notifyApp.ShowBalloonTip(2000, "BackgroundApp", 
                    "This APP is running @ Background", ToolTipIcon.Info);
    }

P.S: i have gone through few similar posts in StackOverflow but none of them facing similar issue.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67

2 Answers2

2

I've accomplished this before using this.Opacity=0;. Kind of hackish, but with WinForms, it might be the only way.

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • yes by setting the `this.Opacity=0;` will make edged window invisible but when should i change the Opacity to make it visible. – Sudhakar Tillapudi Dec 09 '14 at 12:36
  • @SudhakarTillapudi -- I was under the impression you never needed to see your form, that you just needed a tray menu. – rory.ap Dec 09 '14 at 12:38
  • valid point , but as one of the context menu option i have to open the Window.i think by changing the Opacity(setting to 100) in contextmenuitem_click event solves the issue, let me try.thank you – Sudhakar Tillapudi Dec 09 '14 at 12:46
0

if you have a borderless form, i.e., FormBorderStyle.None then ShowInTaskbar = False doesn't work. So, we should set the WS_EX_TOOLWINDOW to true in addition to Me.ShowInTaskbar = False.

This is not from me, but from this one: http://www.codeproject.com/Tips/135076/Hiding-the-form-from-alt-tab-menu

You could always try to set the borderstyle to something you want when the form becomes visible (and turning it back when you loose focus)

Leon
  • 919
  • 6
  • 21
  • Thanks for your answer, i'm turning on the `WS_EX_TOOLWINDOW` by ORing the `cp.ExStyle` with `0x80`. your second suggestion i tried but still its creating the edged window. – Sudhakar Tillapudi Dec 09 '14 at 12:28