Form screenshot at specific form size - c#

I need to make a C# Form screenshot, but there is a catch.
I need it to be a form at certain resolution AND form itself must not flicker to a user, so somehow in background it need to make an screenshot at certain form dimension.
I tried various things but i cannot make form resized without actually resize a window and than take a screenshot. It's anoying since, to user a window will flicker in mean time -> go to resolution -> make screen shot -> go back to old resolution.
Making a deep-copy of form is a more or less no go since it would needed a lot of rewriting things.
I tried things like: Attempt 1 | Attempt 2 | Attempt 3
But still problem with resizing window and flicker from one size to other.
I have dotnet 2.0 (don't ask why).

This is a very specific problem, and I'm sure there are no real code solutions for that. This is a design-technical issue, and some possible ways to avoid this are
1. You don't resize the form back,
2. You make screenshots only possible in your specific size,
3. You disable the resizing in general and set your size to the default size.

Used solution was to paint seperate picture boxes to the memory and than merge all this seperate images to one big image.

Related

How to set a maximize limit for windows form

I have a project which has several forms which are connected to a SQL database (read and write). Apart from the parent form, each form starts in center position and in the size I set for it in the properties (which apparently it is considered by the system as the minimum size). When I click the maximize button it goes full screen and that is my problem.
I want the child form to be just a little smaller than the main form (so that I can see the header from behind). When I write my preferred maximum size in properties field it just doesn't work.
I used the first solution written here: Is it possible to set the Maximum Width for a Form but leave the Maximum Height Unrestricted?. It gave me a restriction for the maximized size. However, it not only makes the form get out of center, but as soon as I click on the form it goes back to minimum size.
The other issue is that my project is suppose to run on more than one computer with different resolutions. So, i don't think giving it a specific size would help.
Bottom line is, I want the size of my child form to maximize to a limit just a little smaller than the parent form which is full screen.
Can anyone help me?
It seems you're trying to create a Multiple Document Interface (MDI) style application. This style isn't very common any more, but here are some examples on how to do so.
The StackOverflow example you gave uses the MaximumSize property. That property doesn't apply when the user clicks the 'maximize' button at the top right. It is used for when the form is configured to allow resizing (by grabbing the handle at bottom right). Maximize functionality will either fill the full screen, or for MDI applications, the entire MDI parent window -- and it's always been that way.

Getting Pixel Values "Under" Current Window

I'm trying to make, essentially, a screen capture program, that captures the pixel values under the current window. (I'm working in C#, in Visual Studio 2015.) However, for various reasons, the window itself needs to be opaque (for filters and such). How can I best achieve this?
It is possible to find the window below yours and get a screenshot of it even if it is hidden with the method: PrintWindow (see PInvoke.net as well)
See Copying content from a hidden or clipped window in XP?
It is very simple to do in Winforms. Just set the form's Opacity value to 99%. Now Graphics.CopyFromScreen() will not see your window anymore.
Except when the window underneath yours is also a layered window, then it also won't be visible to CopyFromScreen() for the same reason. Then you have to set Opacity to 0, copy and set it back to 0.99. Very quick, probably good enough for what you want to do.

Program Size Problem made in C#

I have made a program within C# which i have now published from it but a problem occuyrs when i try to install it on different machines to mine. On my computer the program window size is fine but on other computers its sometimes too small and sometimes too big so the user can not properly look at the main screen of the program. I don't know what to do to change this problem, either within the computer settings or possibly in C# in the code of my project. Please Help,
Thanks,
Chris.
Use Dock and Anchor
It sounds like different users have different screen resolutions. Thats just part of developing software for a variety of users, with differing screen options. You should test your app is usable with different settings and possibly adjust font sizes, layout and dimensions accordingly.
If I'm guessing correctly the problem here isn't the screen resolution but that the actual program window changes size, either hiding parts of the program or showing too much? In that case you should take a look in your WPF editor (if you're using WPF, that is) and check the different Layout/Size options.
You need to use the Anchor properties and Dock properties of your controls (inside the form) to allow your program to be resized. If you can successfully resize it on your computer it should work on others too.
Part from that you may want to set the form to fixed size so that users can't resize it.
You can use the Screen class to get the bounds of the available screens, and from there you should be able to tell if your initial window size is too small and adjust it accordingly. You should probably take care to do this once on the initial launch of the application, just in case the user explicitly and intentionally moves/resizes the window so it doesn't completely cover the screen -- you wouldn't want to accidentally obliterate their changes the next time you run (assuming you even save window positions).

Prevent controls from being redrawn in C#?

I have a form that contains a lot of runtime generated controls (image, button, panel,...), about 100 controls (I'm making a card matching game so there is a lot of controls in the form).
I place the generating code into the constructor and each time the app starts, it took about 3-5s to load all the controls completely.
If I bring another window on top and then back to my app, the controls will be redrawn again.
How can I prevent the controls from being redrawn? If you don't mind, please give me a simple example in C#.
Any help is appreciated!
I found this article that explains how to do this in .NET by calling the WIN API SET_MESSAGE function to set the WM_SETREDRAW flag for the control you do not want updated. Although you can stop certain controls from updating, are you sure you can't approach this issue by reducing the number of controls on the page? 100 Controls seems like a lot and may be an indication that you need to have multiple views.
Enjoy!
My suggestion is to use the form as a drawing surface and draw your card bitmaps directly onto the form. Its not hard to do.
You can add a handler to the form Paint event which will give you parameters with a Graphics object. Use graphics.DrawImageUnscaled to draw each card at the location you want.
This will make the app much much faster.
Preventing a control from redrawing is fairly pointless. You'll get a hole where a control was supposed to appear, your user won't have any use for that hole.
It redraws slowly simply because you have too many controls. You can only get it to redraw faster by using less controls. Or by using controls that can display multiple items in one window, like ListBox, ListView, TreeView, DataGridView.
Note that your specific issue is fixed in Vista and Windows 7. The Aero theme uses off-screen buffering for windows. Which means that windows don't need to repaint themselves anymore when they are obscured by another window. You will however still get slow redraws when the user minimizes the window and restores it.
You might want to consider using a single data table control. A ListView (or something like ObjectListView) may be a good option.
If your data isn't really a list/table, you should split the controls into separate tab pages, which would improve both performance and usability.

GDI handles with icons . l

i have a winforms application. i have a user control with a lot of icons. the user can load this control on a form many times (in a tabbed layout). right now i am loading the icons each time the control is created (could be up to 50 times in teh app). is there any way to cache these icons in the application. if i did this, would that decrease the number of gdi handles that i am using as this is becoming an issue.
You can make a singleton class for each icon. The first reference it creates the handle. Subsequent calls uses the existing handle.
Without knowing more about your user control my next suggestion can be only be very general. But you could have a single bitmap layer on which you draw all your icons. The remaining elements of your user control would exists above and around this bitmap.
Unfortunately this idea may be problematic performance wise. Require you to refactor the code you all ready use for arranging icons. Finally it is non-institutive from how frameworks with a control-form structure ideally works.
We ran into a resource problem with entry forms for the parameteric shape we ship with our CAM software. Too many text entries caused various forms of strangeness and leaks. So we instead created labels with borders that looked like text entries and had ONE text entry (and a combo box entry too). When the user tabs, enters, or clicked the single text entry moved to the new entry and the label was setup for the previous entry.
This is totally a non-intuitive setup than how you would normally code this but it was the only way to deal with our resource problem.
In my experience it seems that GUI Frameworks have issues when you have to deal with dozens or hundreds of entries and that you have to approach the problem using a different design.
If the issue is the number of "icons" (not sure what you mean here) you can use Image-Lists. For example, a Listview control can reference icons in an image-list, instead of keeping a full copy for each item (not sure if this applies to your case though).

Categories