There are code in the project that implements simple "animation" - slide. There is pictureBox as content unit, and two buttons to slide to next pictureBox, or to previous. This code uses winforms.
To implement this "slide", location for both pictureboxes changes in cycle. But the control that slides to the screen (its start location out of the screen), does not redraw properly. So we tried to add refresh of content panel to the cycle (like this.contentPanel.Refresh()). And it worked fine. But problems occured when QAs tested this application on very slow VM. This animation took ages, because of that refsresh in cycle.
As quickfix we refactored code to perform this animation for constant time. So slow machine can animatie it for same time, but not so smoothly.
The question is, how can we optimize this? How can we redraw this controls more optimal?
Related
I have a WinForms Application. I need it to run also in Mono.
I have a problem with form repainting. There are many controls in the form. When I resize the form or when I try to update it (it needs to be updated on timer tick), the repainting does not work . Sometimes the controls are placed right, but it flickers, sometimes the the controls do not move or resize at all, some of the controls (buttons) seem to be disabled, some of them even disappear or are displayed twice.
In .NET I had similar problems, but enabling double-buffering on form solved them. But it seems that it does not work in Mono at all and I really don't know what to do.
On resize I need to move and resize the controls and redraw pictures in PictureBoxes.
I also have a problem with the above mentioned timer - the tick event fires only once and then almost everything on the form stops working, but I think it may be connected with the repainting problem.
If someone had an advice on how to correctly repaint a WinForms form in Mono, I would appreciate it.
I'm trying to code a picture book. For this I am scanning every subfolder of the MyPictures Folder and add every picture I find to an observableCollection. I dont want to limit the amount of pictures, in this view.
In function it should work the same way, the normal Windows explorer window with extra big symbols does.
I have tried a lot of things, but every solution I found always had the problem that I lost smooth scrolling (I tried virtualizing stackpanel. Aside from the worse looks compared to a grid it also had the scrolling problems).
If I understood correctly, the smooth scrolling doesn't work anymore, because pictures are loaded, and the scrollviewer has to be updatet, regardless if it is a virtualizing stackpanel or not.
In the windows explorer this is worked around by displaying placeholders, I think.
Do you have any idea how I could implement something like that myself?
Edit: At the moment, I am preloading chunks of the pictures. When the view was scrolled down, I update that chunk with the new pictures. But while the update is running, the scrolling gets laggy again.
I have some troubles with redrawing images on c# Windows forms. I have some images to be drawn on panel. Everytime a panel_Paint event is raised, i draw my images. Everything was nice, untill I started to scroll my panel. The "redrawing" is for some reason noticeble to human eye. I mean, you can watch how the place, where image takes place, is for a very small time empty and image is drawn upon that place a bit later. This effect appeares each time I redraw my images. This effect reminds me the same as, when a Person scrolls something in folder on a PC without Graphic Card drivers installed.
Can i get rid of these visible "redrawings"?
I wish i could scroll my images without any lag.
I invalidate my panel with images, each time i move my mouse over other panel(this panel is some sort of scrollbar, that i am trying to implement).
EDIT: Problem resolved
I'm pretty much out of ideas here... for everything else, setting the background color to Color.Transparent or setting the TransparencyKey works fine...
I have an mp4 Video which I need to play as a "background" of my form. To do this, I'm currently using the WMP control. My problem: I can't add any controls on top of it, since they always render a background. Which looks ** on the video...
Any suggestions?
A hack I've used successfully in a similar situation:
Create a separate, borderless, transparent form (transparency works best at the Form level)
Host button controls on that form
Launch the control form when your video form launches
Wire event handling such that the floating form always moves, resizes etc. whenever the main form changes
Calculate position of the floating for based on parent form's specs
Always push the floating form to the top, above the parent form
Told you it was a hack. But if you get all the events and calculations wired up it should work fine.
P.S. I also recall having to do a poll timer with a function that made sure every 250 millis or so that the Z-order of the two forms was what you wanted. (Switching apps and windows changed the z-order unexpectedly and w/o events, thus the polling solution.)
P.S. II It is very easy to prototype the feasibility of this solution. Just create a separate app with the above-mentioned specs and move it over your video. (You will need to retain the Form border to be able to move/resize the window easily.)
Try rendering your labels using GDI+:
You can see sample here: (the Using GDI+ for drawing images with transparency part):
http://www.broculos.net/en/article/how-use-transparent-images-and-labels-windows-forms
I've created a WPF application which has a Canvas on which I place UserControls which are moveable and resizeable by the user (just like a Windows-Window). Now I have detected that this can be very slow on older PC's which is a problem.
As a solution I thought about generating a graphic showing the UserControl and show this while resizing/dragging the Control, to prevent WPF from recalculating all Elements permanently. The only problem is that I have no idea how to generate this image.
Is there perhaps something like a function which does this in .Net? Or how could I do this on my own?
You can render a WPF control to a bitmap using RenderTargetBitmap, then this image can be copied to the clipboard, saved to a file, or used as part of your GUI
Check out Get a bitmap image from a Control view
Beware with this that you can hit problems when parts of the control you are trying to render are not visible (within a scroll viewer perhaps)
WPF applications really do require some fairly serious grunt; particularly in the graphics department and benefit greatly from having a decent video card present in the system. Even then the performance of WPF apps (if not carefully constructed) can leave much to be desired...
That said, you could feasibly use FixedDocument to rasterise a UserControl, and then convert this into a GIF/JPG/PNG and put this in place of the control being resized... however I would expect that process itself to be as slow or slower than your current observed performance issues.