Hey all, i tried to create a custom combobox with borders and some additional things to make it look more modern. Here is the code of the paint method i call inside OnPaint
and here is the code for de DrawItem method,Code:Public Sub CustomPaint(screenGraphics As Graphics) ' If there is body to be drawn. If Me.Width > 0 AndAlso Me.Height > 0 Then ' Clear the background image graphics If Me.m_backImage Is Nothing Then ' Cached Background Image Me.m_backImage = New Bitmap(Me.Width, Me.Height) Dim backGraphics As Graphics = Graphics.FromImage(Me.m_backImage) backGraphics.Clear(Color.Transparent) Me.PaintTransparentBackground(backGraphics, Me.ClientRectangle) End If m_BackGraphics.Clear(Color.Transparent) m_BackGraphics.DrawImageUnscaled(Me.m_backImage, 0, 0) m_ControlGraphics.Clear(Color.Transparent) m_ControlGraphics.SmoothingMode = SmoothingMode.HighQuality 'm_ControlGraphics.Clip = New Region(GetBoxBorder()) ' Begin drawing 'Calculate the current dropdown rectangle DropDownRectangle = New Rectangle(Bounds.Right - SplitSectionWidth, 0, SplitSectionWidth, Bounds.Height) Using pen As Pen = New Pen(Color.Black) m_ControlGraphics.DrawPath(pen, GetBoxBorder()) PaintArrowAndLine(m_ControlGraphics) End Using m_ControlGraphics.Flush() m_BackGraphics.DrawImage(m_ControlBuffer, New Rectangle(0, 0, m_ControlBuffer.Width, m_ControlBuffer.Height), 0, 0, m_ControlBuffer.Width, m_ControlBuffer.Height, GraphicsUnit.Pixel) m_BackGraphics.Flush() ' Now paint this to the screen screenGraphics.DrawImageUnscaled(m_BackBuffer, 0, 0) End If End Sub
My problem is that i lose the animation it makes when displaying the items. I should note that when used isolated the animation works great, but when in some other VS projects it stops working. The items appear suddenly, with no sliding.Code:Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs) Dim brush As SolidBrush = New SolidBrush(Color.LightGray) e.Graphics.SmoothingMode = SmoothingMode.HighQuality If e.Index < 0 Then Exit Sub Dim rect As Rectangle = e.Bounds Dim TextBrush As Brush Dim index As Integer = If(e.Index >= 0, e.Index, 0) If e.State And DrawItemState.Selected Then 'selection background color e.Graphics.FillRectangle(brush, rect) 'selection forecolor TextBrush = Brushes.White e.Graphics.DrawString(Me.Items(index).ToString(), e.Font, TextBrush, e.Bounds, StringFormat.GenericDefault) Else e.Graphics.FillRectangle(Brushes.White, rect) TextBrush = Brushes.Black e.Graphics.DrawString(Me.Items(index).ToString(), e.Font, TextBrush, e.Bounds, StringFormat.GenericDefault) End If MyBase.OnDrawItem(e) End Sub
Any recommendations?


Reply With Quote
