I'm developing a magnifier in C# .NET (using WindowsForm) that shows a top-most click-able through form. This top-most window shows an specific part of the screen.
The problem I'm having is that to take the screenshot I need to Hide() and Show() the form (otherwise I would take a screenshot of the magnifier) and this creates an annoying flickering in which the magnifier disappears and rapidly appears again.
How could I take a screenshot of the Desktop without hiding/showing the form?
Is there another approach/workaround?
Thanks.
Use the form's Opacity property. Set it to 99% in the designer. When you are ready to take the screen shot, set it to 0, make the shot and set it back to 0.99.
The change is instant, no need to wait and no flicker or repainting. Do not restore it to 1.0, that flickers.
Do beware that you remove the "Hall of Mirrors" effect from the magnifier. Bit of a loss :)
Related
I'm using Windows 10, Visual Studio 2017 and writing a C# Windows Form Application.
I have a windows form application that I am writing (partly in an attempt to get better at writing such things). I have designed my form nicely, with everything spaced and sized properly, but when I press F5 to start the form to debug it, I find that it loads at about 75% the size of the one I see in the designer.
This resizing seems a bit hit and miss, with buttons that were previously aligned no longer being so, and text no longer fitting in its spaces (see pic - the top part shows the designer and the bottom shows the actual form being run).
I would like to have the designer accurately reflect the final look of the form - does anyone know what is going on or how to avoid the problem? Everything I have looked at on the web talks about choosing to resize the form, not this enforced resize!
Have you changed the whole form font size? By default WinForms designer set
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
try changing the AutoScaleMode and see what happens.
I've experienced similar WinForms designer issues when the default Font (in the form property) size is not 8,25pt. I dont't know why but seems related to desktop and/or screen configuration. Not sure but some weird behaviours could be bugs (WinForms is now quite old...).
AutoScaleMode.Font means that form scaling is based on font size. So trying changing different font settings can solve the problem.
hope this help
When designing the form, the form automatically sets the anchor points to Top Left. You will have to set the anchor points to your form.
The anchor style works like this. On a control if you set anchor points to:
Top/Right then the control stays in the Top Right.
Top/Left then the control stays in the Top Left. Bottom/Right then the control stays in bottom right. Bottom/Left then the control stays in bottom left.
Top then it stays at the top.
Bottom then it stays in the bottom.
Left then it stays in the Left.
Right then it stays in the right.
Top/bottom stretches top to bottom.
Left/Right stretches left to right.
Now when you anchor a control to any of those combinations they will stay in that location when form is maximized. Controls can anchor to each other as well.
I hope this helps.
Also here is a tutorial I did on this.:
https://youtu.be/wlZ6pt79v1E
accurately reflect the final look of the form
Your form's appearance is mostly decided by the end user. Font, size, colour, scale, contrast... all these things are under the users control, not yours.
Consider using split panels, and maybe some flow panels. Get used to 'randomly sizing' the form when you think you've finished designing, to see how it reacts to being the 'wrong size'. Someone will find a way to shrink or grow your form, and handling that gracefully is easier than enforcing a view.
I have a C# winforms application with a fixed-size starting dialog. After making some changes entirely unrelated to this form, the form now opens maximized, filling the entire screen with the actual content still at the regular size in upper left corner. Dragging the title bar down a bit with the mouse causes it to restore to its appropriate size.
The form has
MaximizeBox = False
StartPosition = CenterScreen
FormBorderStyle = Fixed3D
Does anyone have any suggestions what might be causing it to open maximized, and how to stop it?
Edit:
WindowState = Normal
is also set.
Edit 2:
I found the problem. My update routine was shutting down the original process so it could be updated (inappropriately, but that is a different bug), then restarting it with code I had borrowed from elsewhere, and part of that restart code was:
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
Thank you for the assistance. Though no direct answer was given (nor expected with the spotty information), it did point me in the right direction.
The Window being Maximised is normally set on the forms "WindowState", Light Reading. You need this to be set to WindowState.Normal. It's possible someone's set it to maximised in the designer? or somewhere else in the code. the 3 lines of code you have shown are not the problem.
Edit:
You need to do some investigation if you cant give us code from your form, Hook into some resize events, and see what's triggered it off. Forms dont just start up maximised unless they're told to and maximizing a window triggers a resize event.
INTRODUCTION
Using C# or VB.NET. I'm trying to make a form's background transparent; this form will be overlaped to other window, it will be a top-most window, so the transparent form (and its controls) must have the ability that they must not receive focus and they must can be clicked trough, this means if for example I perform a left-click on the transparent background, then the window on background of that (in the Z-order window) is the window that must receive the click instead.
Notes:
For avoiding the focus I'm overriding the CreateParams property as explained here.
For making my form transparent, I'm calling Win32 DwmExtendFrameIntoClientArea function and also using SharpDX library as explained here. But I think this really doesn't matter with the question itself.
PROBLEM
I'll show a demostration of what I mean using images. Here below is a image of a form (with no transparency, just to simplify understanding) overlapped to a window of a text editor program; note that my form doesn't receive focus. Well, the problem is when I do click on the form's background (or one of its controls) the window on background (the text editor window) still have focus but it can't receive the click.
Here is the same image of above but with a transparent form:
RESEARCH
I'm not really sure about what to investigate, so I'm going blind trying to find something useful in a trial-and-error stage by overriding the Window procedure (WndProc) of the transparent form to test related windows messages, like WM_NCHITEST or WM_MOUSEACTIVATE message as said here:
Windows form with a transparent background that cannot be clicked through
Make a form not focusable in C#
How do I create an "unfocusable" form in C#?
You can do this by sending click (mouse up & mouse down) messages to the window underneath the transparent window using WinAPI.
PostMessageA
You'll need to find the window underneath the point you require.
WindowFromPoint
You'll have to translate the position of the click events accordingly since messages are processed based on relative window position, not absolute screen position.
I actually did this quite successfully to automatically play a facebook game many years ago.
Check the RAD designer in Visual Studio.
Is the label docked to fill?
Where is the main form clickable?
The transparent color is click-though in the main parent, however, components will still retain clicks.
if the transparentkey property is used to make the top level form transparent,it works , but it also makes the main form click-throughable. I want the opposite of this, that the form becomes transparent, but is still able to recieve clicks. can this be done ?
Here is een solution. The form is totaly transparent and still clickable.
There is also
myform.Opacity = .75
.. which you can change as required. It may work better depending on your needs - you don't state whether its the whole form or only part of it you want transparent. Also, from MSDN on TransparencyKey:
Any mouse actions, such as the click
of the mouse, that are performed on
the transparent areas of the form will
be transferred to the windows below
the transparent area.
.. so it would seem that wont help you at all.
Ok, I have googled, but maybe I put my search in weirdly. :/
I have a VB.NET WinForms application. I have the anchor properties set for all the controls so that it will resize all the controls to look decent when the form is maximized. (Haven't gotten around to manual resizing yet however).
Anyway, the problem:
I go to set the same properties for a button (testing with a single button for now) on the main GUI form/picture. When I go to run the program via F5, it looks decent. But when I maximize the form, the entire button covers up more than it should.
I've taken screenshots of the form so you can see a visual of what I'm talking about. :/
Before: http://zack.scudstorm.com/before.png
After: http://zack.scudstorm.com/after.png
What other propert(y|ies) do I need to set for the buttons to show up correctly? :/ (The buttons go over the boxes that say, for example, "1-1", "2-3", etc.
Thanks,
-Zack
Seems like you have anchored top-left and bottom-right when what you want is just top-left.
Edit: If it's just an image that does not change when the winform changes, then don't anchor your buttons at all. Just put them where they go. If you are scaling the image, then I would either detect the clicks on the image and do the scaling math or do the scaling math and set my buttons in code in the Form.OnResize event.
As it appears that your goal is just to be able to handle clicks on the "computers"...
One option that can be useful for this sort of task is to create an "overlay" bitmap (not displayed, but which is the exact same size as your source bitmap) which uses different colors to represent all the clickable regions. (e.g. (R=0,G=0,B=0) for computer 0, (0,0,1) for computer 1, etc)
You could even generate this bitmap somewhat automatically without too much trouble (If you have a mode where you can click the top left and then bottom right corners of the image to define a new region)
When the mouse is clicked, you can check the pixel at the scaled coordinates of the mouse position in the overlay and determine what their click corresponds to. This can be a lot easier than creating loads of controls, and makes it a lot easier to have clickable regions that aren't rectangular.