how to stop a progress bar control from well progressing - winforms

I have a marquee style progress bar
at some point I want it to stop well marqueeing I guess
How do I ?
this is on win7 .NET 3.5

Set the Style property to a value other than Marquee:
progressBar.Style = ProgressBarStyle.Marquee; // marquee animation starts
progressBar.Style = ProgressBarStyle.Continuous; // marquee animation stops

Related

How to know when a WPF Window has snapped/unsnapped in Windows?

Im using a WPF Window in the WindowsStyle='none';
With this I create my own custom window by giving the 'root' grid (the highest in the XAML-tree) a Margin of 20px and a DropShadow. The window itself is transparant, the grid has a white background.
When I set the WindowsStyle.Maximized, I remove the extra Margin and the DropShadow . When I set WindowsStyle.Normal I add the extra Margin and the DropShadow again.
But when I snap my WPF window in Windows 10 to a corner or side of my screen. It snaps but I dont get an Window.StateChanged event.
My question is: Is there anyway to figure out when my Window has snapped in Windows and when it Unsnapped?

wpf notifyicon context menu not centered on tray icon at 100% dpi

I'm using the wpf notifyicon (http://www.hardcodet.net/wpf-notifyicon)
When my laptop is at 100% dpi scaling, the left side of the context menu is centred on the tray icon, as expected.
When the laptop isn't at 100%, the context menu is pushed to the far right.
On high resolution laptop displays, 100% scaling is not the default.
Wherever my tray icon is positioned, that is, however far from the clock, the menu always pops up over the clock, as far to the bottom-right of the screen as is possible while remaining visible.
Note: I'm testing on a default installation of Windows 8.1. Also, the NotifyIcon that I'm using is the one that is generally recommended for anyone attempting tray functionality in WPF.
To reproduce: the problem exists in the windowless sample provided by hardcodet. I'm using wpf NotifyIcon without a window, and can reproduce easily in code or xaml. In fact, I cannot stop reproducing it. It occurs when dpi scaling is turned on, i.e. when a 1080p display is actually showing a lesser resolution, which is what windows does to stop applications having text too tiny to read.
Any ideas about how I can make the context menu appear in the expected place regardless of dpi?
Screen shots as suggested by kennyzx:
good behaviour. the m on red background (MEGAsync) has just been right-clicked
bad behaviour. the green tick, my notifyicon, has just been right-clicked and the menu appears over the clock
!good behaviour. the m on red background (MEGAsync) has just been right-clicked
!bad behaviour. the green tick, my notifyicon, has just been right-clicked and the menu appears over the clock
and some code:
var n = new TaskbarIcon();
n.Icon=new System.Drawing.Icon(#"C:\window - 64 - tick.ico");
n.ContextMenu = new System.Windows.Controls.ContextMenu();
n.ContextMenu.Items.Add(new System.Windows.Controls.MenuItem {Header="E_xit" });
Found the solution here: http://www.codeproject.com/Messages/4929452/Problem-with-context-menu-position.aspx
It is, with thanks to codeproject user Igorious:
Get the code for Wpf Notifyicon (http://www.hardcodet.net/wpf-notifyicon)).
In Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ShowContextMenu()
replace
ContextMenu.HorizontalOffset = cursorPosition.X;
ContextMenu.VerticalOffset = cursorPosition.Y;
with
var g = Graphics.FromHwnd(IntPtr.Zero);
var scaleX = g.DpiX / 96.0;
var scaleY = g.DpiY / 96.0;
ContextMenu.HorizontalOffset = cursorPosition.X / scaleX;
ContextMenu.VerticalOffset = cursorPosition.Y / scaleY;
Explanation (thanks to codeproject user yachting):
It's needed because WinApi.GetPhysicalCursorPos return the mouse position in pixel,
but WPF's measurement unit is device independent pixel (by definition, it's 1/96 inch)
You need to adjust the return value of GetPhysicalCursorPos by DPI (dots per inch) setting,
otherwise the position of the context menu will be incorrect if users set DPI other than the default 96.

Remove black flicker on first show of Winform with TransparencyKey set

The following code produces a black flicker on the screen right before the form is displayed (transparently), I'm wondering what my options are for removing that flicker?
Form f = new Form();
f.BackColor = Color.Lime;
f.TransparencyKey = f.BackColor;
f.StartPosition = FormStartPosition.Manual;
f.Bounds = Screen.PrimaryScreen.WorkingArea;
f.Show();
I get the same results if I create a new project, set the background of the form to Lime and the TransparencyKey to Lime, then click Run.
Things I've tried:
Set Opacity to 99% -- same flicker
Force WS_EX_COMPOSITED in OnCreateParams or using SetWindowLong -- same flicker
Show the window smaller, or 0 width, or off screen, then move to desired location -- causes bad display issues where the windows behind my form do not redraw correctly.
Setting ControlStyles.Opaque, ControlStyles.UserPaint, and several other ControlStyles combos and overriding different paint/background-paint events -- various results, either same flicker, worse flicker, or form not transparent.
Moving to WPF might be an option, but not really looking for "use WPF" as an answer.
Set the Opacity to 0.01.
If you need the form (or parts of it) visible - then re-set the Opacity once the form creation is complete:
Form f = new Form { Opacity = 0.01 };
f.Show();
f.BeginInvoke( new Action(() => f.Opacity = 0.99 ));
EDIT: Updated cleaner as Tergiver suggested

How to accelerate WPF fade in/out animation

I implemented lightbox effect with window's opacity change whilst fading in/out. When I have my window maximized this effect has big delay or when I use duration property then opacity change is not smooth.
I manage this eg. with like here:
DoubleAnimation animate = new DoubleAnimation();
animate.From = 1.0;
animate.To = 0.5;
animate.Duration = new Duration(TimeSpan.FromSeconds(0));
this.BeginAnimation(Window.OpacityProperty, animate); // main window
Window1 win = new Window1(); // new window to get focus
win.ShowDialog();
Tell me please, if you know, does this effect works on GPU by default? If not, can I manage this somehow?
The maximization issue sounds like the computer might have performance issues, and the Duration issue exists because you set it to 0, a zero second animation is instant, of course it is not smooth.

Silverlight OOB-Application - set backgroundcolor of main window to transparent

I create a Silverlight OOB application in which I try to change the background color of the window transparent. I would like to use as wallpaper its own image. This is not square and therefore interferes with the white background color of the main window.
In the OutOfBrowserSettings I can put as the "Window Style" to "none ".
In WPF there are the two following window properties:
AllowsTransparency = "True"
Background = "Transparent"
Unfortunately, this does not seem to know about Silverlight, though! Does anyone know how I get the background color of the main window transparent?
Have you tried to set beackground to {x:Null}? Or maybe to set the alpha in color to 0 which means transparent. For example #00FFFFFF or #00000000.
This is not possible with the current version (4) of Silverlight.

Resources