C# launch form when images fully loaded - c#

I'm making C# application design with images, but when I launch it, I see loading images (~1sec), so how to make simple loader, when images (background, logo, etc..) fully loads, to show my app? I know it's possible but I don't know how to. Thanks so much!

This sounds like standard behaviour. The controls get painted one by one in z-order and if one is slow the rest may appear to flicker.
You could try double buffering the whole form as shown here:
How to fix the flickering in User controls
Alternatively you could suspend the layout while everything is drawn and resume it afterwards:
How do I suspend painting for a control and its children?

Related

Drag and drop the application to another monitor screen

I have an application which fits to full screen mode in my monitor (1920 X 1080) resolution on loading of the form. Once it loads, I will drag the application to another monitor having (1600 X 900) resolution (2 monitors connected to same PC). All the controls will be loosing their location and will be like hidden. Please anybody provide solution for this?
This problem may be more efficiently solved depends on how your format look like.
But generally, you need:
Good way to format your Form, such that it is "robust" against changeable screen size.
you can check the Container on Windows Form like Panel, FlowLayoutPanel, or TableLayoutPanel as well as SplitContainer and Splitter.
All those tools help you to format how your app look.
Flexible way to put and to size your control.
You can learn more about WinForm Control property called Dock and Size to help you put and size your control. And lastly,
Event handler for the Resize event of the Form (and in more complex case, Resize of the Container
There is a limit on what the automatic formatting can do to you. This event handler is to handle whatever you think it cannot be properly handled by all the built-in properties.
You can also learn about BootStrapping. It may help you to format your app.

WPF SplashScreen using external image

I need to make my SplashScreen show image from hard drive (since i will use several images, which may be changed outside of project). But WPF SplashScreen accepts only resource files, present in this or another assembly.
So, how can i solve it? Maybe, there is some way to create temporary resource file during runtime?
The best way to accomplish this goal is to not use the splash screen feature at all.
Create a new XAML window and size it to the size you want your splash screen to be. You can then use to reference the image you'd like to. This can also be done from code-behind now when loading.
When you're ready, have your main window launch the splash screen as the first thing it does. Let it load everything you need, and then show the main window and close the splash screen window.
This way you have full control over your "splash screen" because it's just another window that you're loading.
The one downside of this is that it might have a very small (.5 second or so) delay because WPF has to load before the window can show. An actual splashscreen is not WPF so it will show immediately. This has never been an issue for me.
I don't think this can be done as you want, however, it could be possible to create a separate assembly, which can be changed out whenever you want, which would contain the resource, using:
SpashScreen(Assembly, string);

WinForms control takes too long to load

In a WPF application I have a user control that hosts a win forms RichTextBox control using the WindowsFormsHost. The user control is used in a panel that is made visible at a certain time. The problem is that the forms control is displayed a few moments before the containing panel. I tried delaying the display of the RTB until the panel is shown, but then the UI freezes for 2-4 seconds when the forms control is loaded. Please help if you know a solution to make the control load faster. Thanks!
You should use a profiler to see where most of the time is consumed, have a look here: What Are Some Good .NET Profilers?
I managed to find a solution for this :) Actually, the WindowsFormsHost had a Transparent background set, and just removing the transparency solved the performance problem.

Adding components to a transparent form

I used this code from the code project in order to display a .png image (with transparency). At line 87 I tried to add a label in which I succeeded but somehow It won't appear on the form. I tried Refresh, Invalidate but none of them worked. Maybe someone can point me into the right direction.
I think, since you're using UpdateLayeredWindow the "normal" painting mechanism is disabled, i.e. no WM_PAINT messages are sent to the window, and the WinForms library has no chance to render the Label Controls.
I found this article about using layered windows on MSDN stating:
Note that when using UpdateLayeredWindow the application doesn't need to respond to WM_PAINT or other painting messages, because it has already provided the visual representation for the window and the system will take care of storing that image, composing it, and rendering it on the screen. UpdateLayeredWindow is quite powerful, but it often requires modifying the way an existing Win32 application draws.
So I'm afraid that WinForms isn't able to work together with your approach. Even if it would, you would likely get unpleasant results since "real" transparency is not easily done with winforms (i.e. the labels wouldn't show up transparently but would be drawn the parent forms background color)

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.

Categories