Prevent ResizeEnd event from resetting the window size - c#

I have a Window that gets resized by code upon an external event. The external event indicates that new data is available and the form needs to resize slightly to fit the new data. This works fine in the normal case BUT when holding down the mouse of the window title bar, the window is resized back to the original size after releasing the mouse. Let me explain:
Window has size X
Pressing mouse down on the window title bar
External event is received, Window is resized to Y. This works fine and the window is correctly resized and redrawn.
Releasing mouse on the window title bar causes an ResizeEnd evnet to be triggered which resizes the window back to X.
How do I prevent the window from being resized back to X in ResizeEnd event in the best way?

Related

How to snap a WPF app to the nearest screen corner by a certain threshold?

Basically I have a MouseDown event where I move the window. I want to be able to snap my WPF app to the nearest screen corner by a certain threshold (i.e. 20 pixels), not just a screen edge but the nearest corner.
Which events should I use to accomplish this? I saw some articles but they seem overkill that are subclassing the Window class, etc.
I know I will loop through every corner of the screen and every corner of my app window but I am not sure which events I need to use and which property of the WPF Window gives me the exact coordinates of the window extents.
We can get the location of the screen by SystemParameters.WorkArea.Width(x1) and SystemParameters.WorkArea.Height(y1),and you window's size are this.width(x2) and this.Height(y2).So,we get the four location of corners:(0,0),(x1-x2,0),(0,y1-y2),(x1-x2,y1-y2).
Then,we can use the MouseLeftButtonUp and down event of the window,i tried that but only I clicked in the window it worded.Moving the window when clicking the title bar of it can't trigger event.I thick maybe we can Customize the title bar and write the event in it's MouseLeftButtonUp and down.

Run code after the user has finished moving the window?

I've made a WPF application and one of my windows is required to go fullscreen, however I'm trying to get it so that if the user drags the window to another monitor it will automatically resize to suit that monitor.
I've tried the previewmouse up down events, mouse up down events to set a bool that the window is being dragged to prevent the code from executing, however this does not appear to work and the window is still trying to resize itself as its being dragged and the mouse is down (as if mousedown is being set to false)
The code that resizes the window is in the window located changed event
Is there any other ways that can effectively detect that the mouse is down and dragging the window to another monitor before executing the code to resize it to suit?
Whilst the user is dragging the window I dont want the code to resize it to be executed, once the user has finished dragging the window, the code to resize the window to the new screen should be executed.
Currently I cant get the code to run after the window has finished moving.
Upon further investigation, no mouse up events are fired after the mouse is released on the title border.
You can override OnPreviewMouseMove for any UI element.
protected override void OnPreviewMouseMove(MouseEventArgs e)
Then using the event args of that handler (of type MouseEventArgs) - you check if the left mouse button is pressed (indicating a drag).
e.LeftButton == MouseButtonState.Pressed
When you start dragging a maximized Window, the size changes. This is how Windows behaves and is natural to a user. On end of drag you can just set the state back to maximized.
Application.Current.MainWindow.WindowState = WindowState.Maximized;
Did you checked this event ? Sounds like what you need.
https://msdn.microsoft.com/en-us/library/system.windows.window.locationchanged%28v=vs.110%29.aspx

how to slide in content from outside the WPF window

In my C# WPF Form I have buttons and textboxes. When I drag a button outside the bounds of the window it responds well. But when I drag the textboxes out of the window they cease to exist. After moving them out of bounds, I have a button that, when clicked, sets their position back into the window, though they don't appear to move back.
How can I prevent the textboxes from disappearing after moving them out of the window?

C# Form code and events not running while resizing form at runtime

I have tried doublebuffering the form - but while I am dragging the form sides or corners to resize it at runtime, the controls do not update and timer events are not firing, until I stop resizing the form with the mouse.
The form consists of a datagridview contained in a tabcontrol and some sounds playing. Everything runs fine unless I am resizing the window (form) at runtime. This is not the end of the world, but just odd behaviour.
It is as though all events and handling are suspended on the form while the form is being resized, or the resizing event is using up all the processor (which it isn't). Is there a way to force event handling while the user resizes the window form?
As a simple example, the form has a sound that is played every 500ms. If at runtime I drag the bottom corner or a side of the window to resize it, the sound is not played until I stop resizing the window (by either releasing mouse click, or not moving mouse).

Win api in C#. Parent window draws on its child

I have created a window in C# by win api. And made it as child to another window. This parent window is an external program and I don't know its source code.
When i move my window inside parent window some parent's elements draw itself on my window.
For, better understanding i've made some screens.
This is before I move my window. My window is gray.
And this one is after moving my window over the "SeatOpen" button.
I have no idea how parent window can draw on my window.
So, why this is happening and how to fix?
The parent window is not drawing on your window... you are failing to draw on your window yourself -- your window is not responding to WM_PAINT messages for some reason so whatever garbage was on the screen remains there.
Try to redraw your window when location is changed and it is over Seat Open button.

Categories