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.
Related
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.
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
I have a multi window application, which fills the entire screen, I want it to be usable on all screen sizes, so I would like to resize it according to the screen size. How can I solve this?
You can use Screen.GetWorkingArea method to return a rectangle object which represents the screen area available. You should be able to use this information to decide where to place your screen elements.
Link:
http://msdn.microsoft.com/en-us/library/1a92hss5.aspx
I saw the Cursor File in the dialog box when adding a new item. Actually what it will do and what is the use of it ?...Thanks..
It contains the Image(s) to draw a Cursor (mousepointer) on your screen.
From MSDN:
A cursor is a small picture whose
location on the screen is controlled
by a pointing device, such as a mouse,
pen, or trackball. When the user moves
the pointing device, the operating
system moves the cursor accordingly.
You can use Visual Studio to create Cursor Files (.cur) which can then be loaded using the Windows Forms Cursor class or Win32 API calls such as LoadImage.
Start a new project from the Windows Forms Application template. Project + Add New Item, select Cursor File. Draw something. Project + Properties, Resources tab. Drag and drop the cursor onto the resource window so a resource is added. Make your form constructor look like this:
public Form1() {
InitializeComponent();
this.Cursor = new Cursor(new System.IO.MemoryStream(Properties.Resources.Cursor1));
}
Press F5 and have a look-see at your new mouse cursor.
If you want to change the cursor when it hovers above an object on your user interface and you are not satisfied with the builtin cursor you can create a custom cursor. Custorm cursors is like a small image, but has some extra properties:
Transparency mask so the cursor can have a shape that is not rectangular.
Hotspot location used to determine the mouse coordinates when the cursor is moved. Some cursors have the hotspot in the upper left corner (e.g. the arrow) while other have in the middle (e.g. the cross-hair) etc.
We have an application that runs on XP64 and Vista64 multiple monitor workstations, and have a strange problem when a single form in the application is moved to certain monitors.
If the form is moved to a monitor that is to the left and above the primary monitor (it has negative coordinates in the Display Settings dialog), the users will get a diagonal resize cursor when putting the cursor in the form (I have only seen it happen when the cursor is in the window's chrome, but users have reported it happening inside the whole window).
I was able to determine that it only happens when the cursor is above the primary monitor (making the secondary monitor only partially above the primary monitor results in the problem occurring only in the part of the form that is above the primary monitor).
This only happens with one form in our entire application, and this one doesn't do anything especially fancy (doesn't override WndProc, etc.) and all the custom controls used are also used in other forms that don't display this problem.
What would cause the diagonal resize cursor to show up all the time?
This appears to be a bug in Form.WmNCHitTest. I believe the way that it is determining the x and y coordinates are incorrect (to get the y it does HIWORD((int)((long)lParam)), where the documentation says to use GET_Y_LPARAM which is defined as ((int)(short)HIWORD(lParam))).
It only uses this method if you have the size grip turned on. Turning off the size grip bypasses this code and makes the form work properly.
Additional information: I find that when setting the Form.SizeGripStyle setting to Show, that the odd behavior with the cursor becoming a diagonal resize cursor, that looks and works like you are resizing the window from the bottom-right corner, shows up when the Form window is moved to a secondary monitor. When setting the Form.SizeGripStyle to Auto, the default, that this issue goes away and the form window cursors and resizing work as they should (proper cursors etc).