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
Related
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 once wrote an app that could display photographs. I am trying to re-write it in Visual Studio with C# and give it new features. The application I am writing now does use scroll bars to facilitate viewing an over-sized image. The previous app would fill the form area with the image and you could drag and hold the mouse to move it about on the screen. If the image was bigger than the screen you'd simply move it about to view previously hidden areas. By making the form the same size as the image it was very elegant way of dealing with the 'problem' of viewing an image that is bigger than your screen dimensions.
The advantage of this over putting the image inside a statically re-sizable form with scroll-bars was that the image would fill the available screen space, and if the next image in the sequence (it is a browser that allows you to cycle through images) was small, the image app would only take up as much space as the image. You could easily move it to one side. You didn't have to manually resize the form that was displaying it to make room for other applications.
I am unable to implement the same feature in the new app because Visual Studio won't let me dynamically re-size the form to be taller or wider than the screen.
Does anyone know of a plugin or workaround to override this limitation?
I am open to suggestions to achieve the same goal, but I would still like to know if this limitation can be turned off, perhaps with a plugin or in code somehow. Below is a link to a video of the previous incarnation of the app, demonstrating the behavior I want to acheive by being able to set the form size larger than the screen dimensions...
Edit: A demo of the the previous application - and the behavior I want to implement...
http://youtu.be/J16EwuozvbQ
I think having a form bigger than the screen is not what you should search for. You can play with the position (top/left) coordination of the image on the form. You can have coordinates with minus values, so you will give the impression to the end user that he browse the image boundaries that's outside of the screen dimension.
Simply, you can create a Form with a PictureBox.
Then change the AutoScroll property of the Form (or the container of the PictureBox, if applicable) to true.
And then change the SizeMode property of the PictureBox to AutoSize.
You should end up with something like this:
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?
I have a desktop application built on MONO. The Application has a button and a drawing area, on-click of the button it draws a house in the drawing area.. till here i don't have any problem but once i re size the window or minimize the window the drawing disappears.
Please let me know if any one came across this problem or if any one knows about it.
Thanks,
Best Regards,
Veeresh
This is a common "issue". It's not really an issue though, it's just the way things work. When you draw something to the screen it's just there in video card ram. When you minimise or move another window over it, something needs to redraw the image. In your case you have nothing to redraw it. You probably need to move your code to draw it to the paint event so that it paints it every time the window needs painting.
Another option would be to draw to a bitmap and display the bitmap in a image control but this is wasteful of memory. It can be the right choice in the correct situation.
I am experiencing a little problem with DWM extended glassframe in a windows form.
I have extended the glass frame of my winform and added a custom control that draws a tab onto it with a white background, pretty much like google chrome tabs. Then I have added some text in the tab region and up to here, everything work fine.
Now, I have another control (PictureBox) that has a transparent png as image, and, I'd like to allow this control to be dragged and dropped somewhere onto the tab. The result is that half of my PictureBox can be on the tab (white background with text) and the other half on the glass frame.
If my PictureBox has a transparent BackColor, everything is ok as long as I stay on the glass frame but when I get onto the tab, the DWM considers it as transparent and draws the glass instead of the tab background, and as I said, the png is not supposed to be specifically on the tab, or on the glass, it could be dropped across both of them.
Is there a way to handle this ?
Thanks for your help, much much much appreciated ;-))
Ps: I've already considered making a CopyFromScreen of the PictureBox region and set it as BackgroundImage, but it doesn't help that much as the part that would be on the glass wouldn't refresh if I move my WinForm.