uwp app reposition to bottom left of screen - c#

I want to reposition a uwp app everytime it opens, to bottom left just above the taskbar, to mimic start menu like behavior.
I have tried using AppWindow class to create secondary views and resize and reposition them with the build in methods, but the problem is there is no appwindow instance for the main window.
AppWindow = await AppWindow.TryCreateAsync();
AppWindow.RequestMoveRelativeToDisplayRegion(displayRegion, new Point(xpos, ypos));
AppWindow.RequestSize(new Size(wWidth, wHeight));
In case of ApplicationView for the main window only resizing method is available.
var view = ApplicationView.GetForCurrentView();
view.TryResizeView(new Size(wWidth, wHeight));
So technically I need to do calculations based on display region (monitor) and then place the app on bottom left and also resize it to a specific size depending on monitor effective pixels, resizing isnt the problem as their is a method for it, but moving and repositioning the app window to a specific place on the screen is a problem as there is no method for it.
Thanks.

moving and repositioning the app window to a specific place on the screen is a problem as there is no method for it.
Yes, UWP doesn't have the API that could change its position in the system as mentioned here:UWP Window Placement and How to set UWP app position (x & y coordinates) . Although this is an old question, the answer doesn't change. The position of the UWP window can't be controlled from the app level.

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.

WPF Window resizing in a different direction

I am having trouble making my WPF window resize in a different direction. Currently, when I shoot an event in my application, application resizes down (I make an element visible and then WPF window automatically resizes). I would like that my application would instead resize up, so that the application would not become hidden by a taskbar. How does one do that?
Below is a picture explaining my problem. Picture 1 shows small window. Picture 2 shows the problem, where window resizes beyond the screen. Picture 3 shows what I want to do.
I can surely code this resizing in my code, where I would move the window, but is there not a nice way in WPF?
Changing the Width or Height property of your window will always change the layout of it to the right or bottom.
The Left and Top property of the window determine the X- and Y-Offset of your window relative to the top-left corner of your screen.
To achieve your goal, you have to do 2 steps:
Increase the window Height by the amount of X
Decrease the window Top by the amount of X

Show forms on separate screens when launching application

I have two form and two screens in a .Net application.
When I run the program, I want to specify where the forms are located: the main form must run on first screen and second form must run on second screen.
How can I specify the screen location for forms?
All you need to setup form.Location = new Point(X,Y);
All screens are located on the same coordinate grid with 0,0 point on the top left corner of the primary screen.
You can use System.Windows.Forms.Screen.AllScreens to get positions and sizes (in Bounds property of a screen) to decide where to put your form. Note that screen on the left or above the main screen has negative coordinates of top-left corner.

How take screenshot of scrolling window in C#

What is the easiest way in C# to take a screenshot of a complete scrolling Window?
I have sceen examples on here using a web browser, but in this case the window is a Windows desktop application.
You can get windows to redirect a WM_PAINT to an offscreen buffer with WM_PRINT and WM_PRINTCLIENT. This is better than screenscraping because it makes sure that obscured parts of a window(behind other windows) is painted anyway. If your target window scrolls by scrolling a child window position, WM_PRINT should apply. Just maybe it also helps your scenario.
Just 3 lines of code is enough
Bitmap b = new Bitmap(pnlOuter.Width, pnlOuter.Height);
pnlOuter.DrawToBitmap(b, new Rectangle(0, 0, pnlOuter.Width, pnlOuter.Height));
b.Save("D:\\bitmapImage.jpg");
pnlOuter is a panel that contains all the controls to be shown in image with extended height to contain all the inner controls. The containing form may have scroll bars enabled.
I solved this by using Win API and taking multiple screenshots, scrolling between each then joining them together.

How can I develop scale like measure it add on in Firefox

I want measuring tool in project that will be same as measure it in Firefox (add-on). How to do this?
To get such a think to work you'll need an application that runs as a tray icon or something like that. Then you open your application and tell him, that you'd like to measure.
Now, you'll go and put a transparent window onto the whole screen(s) and wait for a mouse move event. Within the mouse move event, you'll check the mouse button state. If it is going to be hit you know the starting position and you can draw some kind of user-control at this position and if the user releases the mouse button, you're going to stop the resizing of your user-control.
The user-control itself should be semi-transparent and checking for the resizing and/or paint events, to draw the ruler lines around the border.
Last but not least you can show some kind of tooltip or labelcontrol in relation to the position and size of your user-control and screen bounds to give some status informations.
To get a good starting point about how to get the transparent overlay part done, you can take a look into ObjectListView Overlay.
--EDIT--
One solution could be:
Create a separate transparent windows form
Upon certain key press, for instance Ctrl+Shift+R, show your app with lower transparency level; so that user can see the background.
Draw ruler upon form load
You may allow user to move the ruler window with mouse click.

Categories