Audax321 Posted August 21, 2003 Posted August 21, 2003 Hello, I have an owner drawn listbox with internal item dragging and dropping already coded. All I want to do know is underline the item that is being dragged over in the listbox. As an example, try draggin someting in WinAmp's (v3.0) Playlist Editor and noticing the thick yellow bar that appears. How can I get this effect? Thanks... Quote
*Gurus* divil Posted August 21, 2003 *Gurus* Posted August 21, 2003 If you're already drawing it yourself, presumably you can keep an integer field in the control of an item to draw specially - i.e., to draw a line underneath. When you need to display such a line you could then set the field and call Invalidate() on the control. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Audax321 Posted August 21, 2003 Author Posted August 21, 2003 I tried that method, and it works, but it created a lot of bugs in the program because my program depends heavily on it and I'd have to go through all my code. Instead I just drew a rectangle around the item the mouse is over which serves the same purpose well. Now, Is there a way to prevent the listbox from flashing so much whenever listbox.invalidate() is called? Kind of like when you use listbox.beginupdate and listbox.endupdate you don't see the listbox refresh??? Thanks :) Quote
*Experts* mutant Posted August 21, 2003 *Experts* Posted August 21, 2003 Control class lets you use the SetStyle method of the control to set Double Buffering, AllPaintingInWMPaint and UserPaint to true. Those will make drawing faster and eliminate most of the flicker. And if you are using AllPaintingInWMPaint remeber to draw only in the paint event. Double buffering will cause all the painting to be first done in memory so the flicker is lowered. Quote
Audax321 Posted August 21, 2003 Author Posted August 21, 2003 Hello, I'm not sure if I'm using setstyle right.. I just put this in the the Form Load event: setstyle(ControlStyles.DoubleBuffer, True) But, when the program goes to load all the items into the listbox I get the following error: An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in system.windows.forms.dll Additional information: External component has thrown an exception. Quote
*Experts* Volte Posted August 21, 2003 *Experts* Posted August 21, 2003 Put it in the constructor. Quote
Audax321 Posted August 21, 2003 Author Posted August 21, 2003 I added Me.SetStyle(ControlStyles.DoubleBuffer, True) Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) Me.SetStyle(ControlStyles.UserPaint, True) to the Public Sub New() event after the InitializeComponent() call and still got flicker. I am drawing lines, rectangles, and filling rectangles in the drawitem event for the listbox because this is an ownerdrawn listbox. If this is the reason how do I use the paint event to achieve the same result? Quote
*Experts* mutant Posted August 21, 2003 *Experts* Posted August 21, 2003 Put in the control's constructor. Quote
Audax321 Posted August 21, 2003 Author Posted August 21, 2003 Okay, now I'm confused. :( I'm new to all this owner drawing and trying to learn it. Everywhere I look, it says constructor is Public Sub New() and that is where you change SetStyle. Where is the listbox's constructor? Quote
*Experts* mutant Posted August 22, 2003 *Experts* Posted August 22, 2003 If your control class doesnt have a Sub New then simply create one and the code in it. Quote
Audax321 Posted August 22, 2003 Author Posted August 22, 2003 That is what I'm confused about... If I create a Sub New and put code in it, I can't compile and run because there is already a Public Sub New() present at the top of the code window. Then if I put the setstyle code in that event nothing happens as far as removing flicker... Quote
*Experts* mutant Posted August 22, 2003 *Experts* Posted August 22, 2003 If you didnt create a Sub New in your class with the control, there shouldnt be already one. Are you by any chance looking at your form class? Quote
Audax321 Posted August 22, 2003 Author Posted August 22, 2003 I think I am, but I'm not sure how to create the sub new in the class with the contrlol. Quote
*Experts* mutant Posted August 22, 2003 *Experts* Posted August 22, 2003 Go to your class which is the control, and insert this code: Public Sub New() SetStyle(ControlStyles.DoubleBuffer, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.UserPaint, True) End Sub :) Quote
Audax321 Posted August 22, 2003 Author Posted August 22, 2003 I guess what I should be asking is how do I access the class??? I must be getting a tad annoying by now :) .. thanks... Quote
*Experts* mutant Posted August 22, 2003 *Experts* Posted August 22, 2003 (edited) You dont have an inherited class for the ListBox? Edited August 22, 2003 by mutant Quote
Audax321 Posted August 22, 2003 Author Posted August 22, 2003 All I have is a Form1 class and thats it The listbox is being ownerdrawn by settings its draw mode property to OwnerDraw Fixed and then the drawitem event is handling all the drawing. I have no class for the listbox.... Quote
*Experts* mutant Posted August 22, 2003 *Experts* Posted August 22, 2003 In that case you wont have access to the SetStyle method of the ListBox. Quote
Audax321 Posted August 22, 2003 Author Posted August 22, 2003 Hmm, well do you know of an example I could read to see how to do it so I can have access to setstyle? The way I did it is shown here: http://www.devx.com/dotnet/Article/8014/0/page/2 Thanks.. :) Quote
Audax321 Posted August 22, 2003 Author Posted August 22, 2003 (edited) Is this kind of like what you mean? http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/Samples/WinForms/OwnerDrawListBox/OwnerDrawListBox.src and how do I change the type of the existing listbox.. because Form1 loads it as system.windows.forms.listbox I just went into the Form1 class and changed the following lines: Friend WithEvents lstPlaylist As System.Windows.Forms.ListBox Me.lstPlaylist = New System.Windows.Forms.ListBox to Friend WithEvents lstPlaylist As OwnedBox Me.lstPlaylist = New OwnedBox The class is: Public Class OwnedBox Inherits System.Windows.Forms.ListBox Public Sub New() SetStyle(ControlStyles.DoubleBuffer, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.UserPaint, True) End Sub End Class but now the items aren't drawing correctly, because they get blacked out until you click on them or use the keyboard to scroll over them.... Edited August 22, 2003 by Audax321 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.