I'm ownerdrawing .Net Windows Forms ListView control and see a very strange bug/behavior when I need to draw an image from the associated LargeImageList.
When the View type is a type where LargeImageList is used (Tile, LargeIcon, etc.), I draw item images from the LargeImageList. At that condition, I see a huge memory increase and when you try to scroll ListView this becomes more obvious as you see a jerky scroll as well. This same thing does not happen when the same code uses SmallImageList which is simply like this :
Image MyImage = this.LargeImageList.Images[MyIndex];
e.Graphics.DrawImage(MyImage,MyLocation);
This is reproducable under XP and 7 according to my tests. Is this a known bug, any workaround?
Regards,
Ă–zden
Although I still think this is a bug, I found a workaround. If you draw using ImageList.Draw instead of e.Graphics.DrawImage this problem seems to go away.
How are you managing the invalidated drawing area? As you are saying, looks like you are "overdrawing" the control, I mean, drawing even when it is not necessary.
Related
So I have a fairly simple Winforms app. It has a panel with a bmp image that is being updated every second, via
Graphics.DrawImage
I want to be able to draw a rectangle over the updating images. There seems to be no way to do this in Winforms, however.
First, I tried drawing on the first panel, but there seems to be no way to set the z-index of Graphics elements, so every time the image gets updated, the rectangle is deleted.
Second, I tried making a second panel and drawing in it. Yet, it seems like there is no way to make a truly transparent panel in Winforms. I looked around for some workarounds, but it seems like all they do is essentially make the second panel part of the first, so the previous issue with the rectangle getting deleted arises again.
Is there anyway to do what I am trying to do? Without switching to WPF?
Hi I am working on c# 2005 with a scrolling application.At first I use some of these
http://www.codeproject.com/KB/miscctrl/csmarquee.aspx
http://www.codeproject.com/KB/miscctrl/ScrollingTextControlArtic.aspx
but all of them cannot help me much.My application contains 7timers.At the time of running it
the scrolling panel looks so irritating(read not at all smooth).
so I finally tried with a simple panel ,a label and a timer,this also not working (i mean not smooth).
Can there be any other way rather then using timer,to scroll a text.
Hard to say what is wrong with your scrolling without any code but you will get much smotther scrolling by using Double Buffering. Read more here: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.doublebuffered
But there is limitation how much "animation" you can do with windows forms and have it smooth. Using DirectX or Silverlight will be better for graphics.
Using a timer to control the rate of scroll should be OK. It sounds like you might not be double buffering your controls which is the usual cause of jerky animation. See this article, among many, on using double buffering for controls.
But first just try and set the DoubleBuffered property to true on your form. That setting alone may fix your animation.
I have a Windows Mobile project built in C#.
I have a lot of ready made forms having various controls on it, from Listviews to Editfields.
When user changes orientation some elements are not refreshing correctly. For example the Listview's columns are same and doesn't accommodate the new screen width change (scrollbars appear or half of the screen is filled).
How do you handle these changes?
Do I need to call for each form these fixes by hand, or I can create some kind of global way to fix this? I would like to go with the simplest method if possible.
I would like to avoid the classic way, to add code to all of my forms. So I am looking for better ways, and I would like to see more ideas.
I'm assuming that most of your controls are using a DockStyle, and that will get you 90% of the way in terms of updating the GUI on orientation changes. For the ListView, you'll have to add in some code.
You can add an event handler on Form.Resize, and there put in code to resize the ListView columns. You can tell portrait vs landscape by comparing width vs height. There's also a way to add an event handler on an actual orientation change, but it's interop and I don't remember the code offhand. Form.Resize should be sufficient for most cases.
You can check out an example here
I was wondering... I have a WinForms System.Windows.Forms.ListView with a bunch of ListViewItems that I'm drawing using the View.List style. Each ListViewItem has a "SmallIcon" that I fetch from the ListView's SmallImageList.
My problem is that the icons are showing too close to the border on the left. I've tried to change the bounds and the ListViewItem's Position property to no avail.
Is there anyway to have some kind of offset to ListViewItems?
The Win32 listview control doesn't have any setting to increase the space between the icon and the label (in any view, not just List). Setting ListViewItem.Position does nothing when the ListView is in List view.
A low-tech solution would be to simply prefix every ListViewItem's Text value with a single space. Slightly ugly, but oh so easy to do.
If you really want to have pixel level control, you will have to owner draw it. As always, if you are doing anything with a .NET ListView, ObjectListView makes owner drawing your items trivial.
As mentioned already, prefixing the text of all your items with a space is a super simple way to add padding. This has a pretty significant drawback, however. Once you do this, you lose the ability to find items in the ListView by simply starting to type their name while the ListView has focus.
Try adding white space to the left of your small images.
If you're using 16x16 images change to 24x16 for example by adding 8 white (or ListView Background color) pixels to the left.
If you are in ListView View LargeIcons then you can postion the text using item.position
A screenshot would be nice for an example to see exactly what you're after.
Funny thing... the Windows Explorer uses the ListView to display files and folders. i usually run my view in Report or Detail mode. i just switched it to List view mode and see the exact problem that you're describing! Yikes. Might be a bug with the Win32 object and that particular view type!
A quick workaround might be to use a Report style for the ListView with a single column or perhaps implement something yourself. The FlowLayoutPanel in .Net would work very nicely as a starting point for a custom list view.
As you are using the View.List style, I suspect you'll either need to implement some custom drawing or consider padding your images. You could also look at overriding the ListView control and manipulating it's bounds by overriding SetBoundsCore or SetClientSizeCore (or similar).
However, if the ListView were set-up for View.Details view, this could be done using the ListViewItem.IndentCount property:
The IndentCount property can be used
only when the View property of the
containing ListView is set to Details,
and the SmallImageList property of the
ListView is set. Source:MSDN
If you set the StateImageList property you can add a space of 16 px before the icons. I think you can adjust this additional space by loading an image with matching width as first entry into the StateImageList. But I have not tested this.
This thread discusses the opposite problem.
The problem:
I have a UserControl (LightBox) which overlays a number of other controls to allow the user to see the controls it is positioned over, but not allow the users to interact with the controls under the Lightbox. Winforms is (almost notoriously as I'm finding out) bad at handling alpha-blending.
Question:
How can I get the Lighbox control to render a bmp (snapshot) of whatever it is positioned over when it is created?
Explanation:
The reason I am looking to do this is to allow the Lightbox to draw its own background from this rendered snapshot. This would (hopefully) stop the issues that I am experiencing with large quantities of flicker and undesirable rendering affects.
Is this even possible?!
Thanks for your help.
EDIT 1:
This question seems to expain some of the issues that I am facing and at least describes what I am attempting to do i.e. create a buffer of the background image. However, there are no links explaining how this might ab achieved
You can use the Control.DrawToBitmap function to draw the control to a Bitmap: