Is it possible to hide winform in TaskManager application tab? - c#

I'm writing a transparent WinForms app and I want to hide the app from showing in Task Manager's applications tab. I'm OK with the fact that it will show in Processes (in fact it should).
If I set:
this.ShowInTaskbar = false;
it only hides from taskbar.
Full code i have i have a timer made from labels
public Form1()
{
InitializeComponent();
this.BackColor = Color.LimeGreen;
this.TransparencyKey = Color.LimeGreen;
Timer time = new Timer();
time.Interval = 1000;
time.Tick += new EventHandler(time_Tick);
time.Start();
this.ShowInTaskbar = false;
}
void time_Tick(object sender, EventArgs e)
{
label1_hour.Text = DateTime.Now.Hour.ToString() ;
label_minute.Text = DateTime.Now.Minute.ToString();
label_second.Text = DateTime.Now.Second.ToString();
}

Try something like this
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.ShowInTaskbar = false;
}
protected override CreateParams CreateParams {
get {
var cp = base.CreateParams;
cp.ExStyle |= 0x80; // Turn on WS_EX_TOOLWINDOW
return cp;
}
}
}

Simply setting the form property FormBorderStyle to FixedToolWindow worked for me. On Win 10 it removes it from "Apps" in Task Manager and puts it in "Background processes"...which the OP specified (and was what I wanted also.)
In addition, it removes the form from showing in "Windows Key + Tab" listing of windows...which is what I wanted as well.

Related

Is there a way to toggle/fix a menu while scrolling?

I want to build a Windows Forms App that has a menu (several labels) on it's left side which is toggled. On the right side there should be some columns i can scroll through. Jst like Excel with it's fixed rownumbers.
Is there a way to do this? Preferably an easy one.
I think you can use two panels to make the form like the picture you provided.
The following code is a code example and you can refer to it.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ScrollBar hScrollBar1 = new HScrollBar();
private void Form1_Load(object sender, EventArgs e)
{
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Dock = DockStyle.Left;
panel2.BorderStyle = BorderStyle.FixedSingle;
panel2.Dock = DockStyle.Fill;
hScrollBar1.Dock = DockStyle.Bottom;
hScrollBar1.Scroll += new ScrollEventHandler(hScroller_Scroll);
panel2.Controls.Add(hScrollBar1);
panel2.HorizontalScroll.Visible = false;
panel2.HorizontalScroll.Enabled = true;
}
private void hScroller_Scroll(object sender, ScrollEventArgs e)
{
panel2.HorizontalScroll.Value = e.NewValue;
}
}
The specific result:

Cannot show MainWindow after minimization

I try to avoid the XY Problem by saying immediately what I want and then what I get. 😛
So, first of all, I minimize my MainWindow and thoroguh its NotifyIcon ContextMenu I want that my MainWindow reappears.
The problem: the MainWindow doesn't appear/show as Window, but it appears as Icon in the toolbar (see figure 2).
The code:
This is the TrayIcon initializer:
private void InitializeTrayIcon()
{
KyactusTrayIcon = new NotifyIcon();
KyactusTrayIcon.Icon = AppIcon;
KyactusTrayIcon.Visible = true;
KyactusTrayIcon.ContextMenu = new ContextMenu(new []
{
new MenuItem("Chiudi", ExitApplication),
new MenuItem("Mostra", ShowMainWindow),
});
ShowNotification(#"Ciao " + Globals.CurrentUser.Name + #"!", #"Benvenuto su Kyactus");
}
This is the delegate responsible to show the minimized MainWindow (not working at all):
private void ShowMainWindow(object sender, EventArgs e)
{
WindowState = WindowState.Normal;
Topmost = true;
Show();
Activate();
}
This is what happens when the MainWindow is minimized by clicking the [-] button (ie the Hide() method):
private void MainWindow_OnStateChanged(object sender, EventArgs e)
{
switch (this.WindowState)
{
case WindowState.Maximized:
ShowNotification("Bleah!", "Questo è proprio brutto! :(");
break;
case WindowState.Minimized:
Hide();
ShowNotification("Avviso", "L'applicazione è ora minimizzata qui");
break;
case WindowState.Normal:
break;
}
}
Step one. The method MainWindow_OnStateChanged will be invoked when click on [-]:
Step two. The window disappears (ok) and the Tray icon appears (ok). Then I click on 'Mostra' (translated as 'Show') and the ShowMainWindow delegate will be invoked
Step three. This is the final step, that is, what I do not expect. The MainWindos 'lives' as an Icon in the toolbar. But I can't see it as a Window.
Please note that I have not this problem when I close the window by clicking [X] instead of [-]. So, my suspect is the MainWindow's Window.State. I tried to restore it implementing the WindowState.Normal into the ShowMainWindow, but nothing.
Update: if is use WindowState.Maximized in the ShowMainWindow method,
I can see the window again, but it is maximized and this is bad and ugly.
Just change the order of operation when showing the window
private void ShowMainWindow(object sender, EventArgs e)
{
Show();
WindowState = WindowState.Normal;
Topmost = true;
Activate();
}
Simply,create some class-level integer variables and store the height,width and positioning values there.Then use them to get back the size of your window :
int height;
int width;
double left;
double top;
private void MainWindow_SizeChanged
{
height = this.Height;
width = this.Widthl
left = this.Left;
top = this.Top;
}
private void ShowMainWindow(object sender, EventArgs e)
{
this.Height = height;
this.Width = width;
this.Left = left;
this.Top = top;
}

Fading the background while modal dialog is shown

When shutting down a Windows XP system, it displays a modal dialog box while the background fades to a grayscale. I will like to achieve the same effect in any of the programming languages in the tag list. Can anyone help?
This is pretty easy to do with Winforms. You need a borderless maximized window with a gray background whose Opacity you change with a timer. When the fade is done, you can display a dialog that is borderless and uses the TransparencyKey to make its background transparent. Here's a sample main form that implements this:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.BackColor = Color.FromArgb(50, 50, 50);
this.Opacity = 0;
fadeTimer = new Timer { Interval = 15, Enabled = true };
fadeTimer.Tick += new EventHandler(fadeTimer_Tick);
}
void fadeTimer_Tick(object sender, EventArgs e) {
this.Opacity += 0.02;
if (this.Opacity >= 0.70) {
fadeTimer.Enabled = false;
// Fade done, display the overlay
using (var overlay = new Form2()) {
overlay.ShowDialog(this);
this.Close();
}
}
}
Timer fadeTimer;
}
And the dialog:
public partial class Form2 : Form {
public Form2() {
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
this.TransparencyKey = this.BackColor = Color.Fuchsia;
this.StartPosition = FormStartPosition.Manual;
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
this.Location = new Point((this.Owner.Width - this.Width) / 2, (this.Owner.Height - this.Height) / 2);
}
private void button1_Click(object sender, EventArgs e) {
this.DialogResult = DialogResult.OK;
}
}

WPF full screen on maximize

I basically want to have my WPF window to go in full screen mode, when F11 is pressed or the maximize button in the right top corner of the window is pressed.
While the following works like a charm for pressing F11:
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F11)
{
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
ResizeMode = ResizeMode.NoResize;
}
}
This will still displays the Windows taskbar (tested with Windows 7):
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Maximized)
{
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
ResizeMode = ResizeMode.NoResize;
}
base.OnStateChanged(e);
}
What am I missing here? Or can I do it even more elegant?
WPF seems to be making the decision about whether to go full-screen or respect the taskbar based on the WindowStyle at the time of maximisation. So a kludgy but effective solution is to switch the window back to non-maximised, set the WindowStyle, and then set the window back to maximised again:
private bool _inStateChange;
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Maximized && !_inStateChange)
{
_inStateChange = true;
WindowState = WindowState.Normal;
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
ResizeMode = ResizeMode.NoResize;
_inStateChange = false;
}
base.OnStateChanged(e);
}
Although the code is obviously ugly, the transition to Normal and then back to Maximized doesn't seem to make the user experience any worse. On my display, I noticed flicker with both the F11 code and the kludge maximise, but not noticeably worse on the kludge maximise. But your mileage may vary!
try this
Topmost="True" and WindowState="Maximized"
you can see your window will cover all screen and hide all with windows taskbar
You need to set the Window.Topmost property.
Edit
Check this blog post Maximizing window (with WindowStyle=None) considering Taskbar
Another solution that worked for me:
You can set the MaxHeight property of that window to
SystemParameters.MaximizedPrimaryScreenHeight using the constructor.
public MainWindow()
{
InitializeComponent();
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
}
Warning: This might not work on extended desktop.
Source: Maximize window with WindowState Problem (application will hide windows taskbar)
If you happen to be using WindowChrome to create a custom chrome experience, you'll need to set the GlassFrameThickness to something other than 0 (at least that was the last thing I needed to do to get the TaskBar to be hidden behind the window). That is in addition to the steps provided in the accepted answer.
If there is still someone that need a smooth full screen of course tested only on windows 10! In windows 10 minimized do less flickering if you maintain this code order!
public bool IsFullscreen = false;
public WindowState lastWindowState;
private void player_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (IsFullscreen)
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = lastWindowState;
IsFullscreen = false;
}
else
{
lastWindowState = this.WindowState;
this.WindowStyle = WindowStyle.None;
if (this.WindowState == WindowState.Maximized)
this.WindowState = WindowState.Minimized;
this.WindowState = WindowState.Maximized;
IsFullscreen = true;
}
}
You can hide the taskbar if you import user32.dll...
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
Usage:
int hwnd = FindWindow("Shell_TrayWnd","");
ShowWindow(hwnd,SW_HIDE);
I have found easy way to achieve fullscreen in WPF:
private double LastHeight, LastWidth;
private System.Windows.WindowState LastState;
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F11)
{
if (WindowStyle != WindowStyle.None)
{
LastHeight = Height;
LastWidth = Width;
LastState = WindowState;
Topmost = true;
Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
Top = 0;
Left = 0;
WindowState = System.Windows.WindowState.Normal;
WindowStyle = WindowStyle.None;
ResizeMode = System.Windows.ResizeMode.NoResize;
}
else
{
WindowStyle = WindowStyle.SingleBorderWindow;
WindowState = LastState; ;
ResizeMode = ResizeMode.CanResizeWithGrip;
Topmost = false;
Width = LastWidth;
Height = LastHeight;
}
}
}
This works good in Windows 7 with fixed Taskbar.
In my case, minimizing and maximizing will make the fullscreen size to be a little bit bigger than the screen, so the alternative I found is to temporarily set the Visibility to Collapsed then back to Visible afterwards to force redraw.
Visibility = Visibility.Collapsed;
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
ResizeMode = ResizeMode.NoResize;
Visibility = Visibility.Visible;

Effect To Show Panel in C#.net

I Want Use a Panel in a Windows Form in C#.net. I Set Visible Property of this Control to false And When I Click on a Button, Panel is showed. I Want Show a Panel by some Effect.
Please Help me for this
You are leaving us guessing about what kind of effect you are looking for. I'll just arbitrarily pick a collapse and expand effect. It takes a Timer, you implement the effect in a Tick event handler. Here's an example, it requires a Panel, Timer and Button:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
timer1.Interval = 16;
timer1.Tick += new EventHandler(timer1_Tick);
panel1.BackColor = Color.Aqua;
mWidth = panel1.Width;
}
int mDir = 0;
int mWidth;
void timer1_Tick(object sender, EventArgs e) {
int width = panel1.Width + mDir;
if (width >= mWidth) {
width = mWidth;
timer1.Enabled = false;
}
else if (width < Math.Abs(mDir)) {
width = 0;
timer1.Enabled = false;
panel1.Visible = false;
}
panel1.Width = width;
}
private void button1_Click(object sender, EventArgs e) {
mDir = panel1.Visible ? -5 : 5;
panel1.Visible = true;
timer1.Enabled = true;
}
}
The only effect I can think of is to expand the panel by using a timer and change the size of the panel step-by-step.
I would recommend you to use WPF instead of Winforms that is very good at doing this kind of stuff. You can animate all properties of the control like location, size, alpha. Please, check these articles on WPF animation
WPF Animation overview
Walkthroughs: Create a Custom Animated Button

Categories

Resources