Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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 :)

  • *Experts*
Posted
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.
Posted

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.

Posted

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?

Posted

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?

Posted

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...

  • *Experts*
Posted
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?
  • *Experts*
Posted

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

:)

Posted

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....

Posted (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 by Audax321

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...