WPF Window resizing in a different direction - c#

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

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.

Keep form and controls proportion deployng a c# application for any screen size

I know this is an "already heard" problem: I have searched a lot but I did not find anything that cleared my mind.
I am developing a c# application with a GUI containing some controls like buttons (made with images) and text.
I developed it setting the main form size to 800x600 but now I need the application to work also on a 1920x1080 screen.
Two problems:
If I position a button near the top-right corner of the main form and set AnchorStyles to Top-Right, when I switch to the big screen, the button is (in proportion) much more close to top-left corner than in the little screen (because the anchor keeps the distance from the border). Is there a way to set a proportional distance from the border?
How can I scale the dimensions of the controls proportionally to the screen size? Shall I use AutoScaleMode like suggested here?
There is a way to add a capability to a form at design time - the ToolTip control does it, that makes properties available to every control on a form. These are called "Extender Providers"
http://msdn.microsoft.com/en-us/library/ms171836
You would want to look at the controls, and cache their sizes and fonts at design time, and the size of the form.
The provider would hang off the form.SizeChanged event at run time. When the size changes, you use the new and original (design time) sizes of the form to calculate and X and Y ratio. You then go through each control and use it's design time size and the ratios to determine its new size and font size. This can get flaky if you allow the user to select sizes that are not the same aspect ratio as your original.
Anyway, that is how it was done in Delphi, and everyone knows if you can do it in Delphi, you can do it in C# :)

Changing Resolution in OpenTK

I've been searching around for this, I've managed to find out out to change the size of our window, and how to change the resolution of the monitor.
But I can't seem to find how to tell OpenGL where and how big my viewport is.
Example: the game starts up in 400x300, and I expand the window to 800x600. I now have a 800x600 window, but only a 400x300 box in the corner is being rendered to.
I get the same problem when switching to fullscreen, the gray area covers the entire screen, but I only have a small box in the corner being rendered to.
Any OpenTK people out there that know how to do this?
You need to refresh your viewport:
GL.Viewport(gameWindow.ClientRectangle);

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.

How to prevent fullscreen form covering the taskbar?

Does anyone know how I can prevent my C# winform covering/going on top of the taskbar? My form's border style has been set to "FixedToolWindow" which seems to cause this. I thought about reducing the height of the form, when the user makes the form maximized, but that wouldn't work as people may have different size taskbars.
The Screen class will give you both screen bounds and working area. The working area is the bounds minus the taskbar, so just set your form to be the same location as the Screen's WorkingArea
The working area is the desktop area
of the display, excluding taskbars,
docked windows, and docked tool bars.

Categories