473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OwnerDraw ComboBox problem.

Hi!

In VB.NET want to draw my own items in a ComboBox

I have added a ComboBox to the Form with this.
-----------------------------------------------------------------------------------
'ComboBox1

'

Me.ComboBox1.Dr awMode = System.Windows. Forms.DrawMode. OwnerDrawFixed

Me.ComboBox1.Lo cation = New System.Drawing. Point(16, 232)

Me.ComboBox1.Na me = "ComboBox1"

Me.ComboBox1.Si ze = New System.Drawing. Size(121, 21)

Me.ComboBox1.Ta bIndex = 13

Me.ComboBox1.Te xt = "ComboBox1"

AddHandler Me.ComboBox1.Dr awItem, AddressOf ComboBox1_DrawI tem

---------------------------------

Private Sub FSMmain_Load(By Val sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

ComboBox1.Items .Add("Item1")

ComboBox1.Items .Add("Item2")

ComboBox1.Items .Add("Item3")

End Sub

-------------------------------

'And then the Draw item Sub

Private Sub ComboBox1_DrawI tem(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs)

Dim g As Graphics = e.Graphics

Dim r As Rectangle = e.Bounds

Dim fn As New Font("Verdana", 8, FontStyle.Regul ar)

If e.Index >= 0 Then

Dim s As String = sender.Items(e. Index)

Dim sf As New StringFormat

sf.Alignment = StringAlignment .Near

Console.WriteLi ne(e.State.ToSt ring())

e.Graphics.Draw Rectangle(New Pen(New SolidBrush(Colo r.Black), 2), r)

If e.State = DrawItemState.N oAccelerator Or e.State = DrawItemState.N oFocusRect Then

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.White), r)

e.Graphics.Draw String(s, fn, New SolidBrush(Colo r.Black), r.X, r.Y)

e.DrawFocusRect angle()

Else

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.LightBlue), r)

e.Graphics.Draw String(s, fn, New SolidBrush(Colo r.White), r.X, r.Y)

e.DrawFocusRect angle()

End If

End If

End Sub

----------------------------------------------------------

My Problem is this, When I Click the ComboBox it drops down with a white aream big enough for the 3 items but it's empty and then after 2 seconds the Items show with LightBlue Background and Black text and then when I move away from it the Black border of the Combobox staty painted. There's no crash or anything, just feels like it's really "well".

Any ideas what might be wrong?

I have Based this on the C# examples found here. http://www.csharphelp.com/archives2/archive316.html

The Examples works fine for me.. but I want to translate this into VB and I can't figure out what I'm missing.. or is there a Differance in the C# and VB languages for this kind of work?

Best Regards

/Lars Netzel



Nov 21 '05 #1
1 8151
Okay.. it actually did work fine but the Rectangle...

e.Graphics.Draw Rectangle(New Pen(New SolidBrush(Colo r.Black), 2), r)

... took a very long time to be drawn... so I took that one away (wasn't really nessessary) and now it works fine. Also the IF statement was wrong for checking the state of the Item, it should not be "OR" but "+" instead.

Thank you for reading though...

/Lars Netzel
"Lars Netzel" <ui****@adf.s e> wrote in message news:O0******** ******@tk2msftn gp13.phx.gbl...
Hi!

In VB.NET want to draw my own items in a ComboBox

I have added a ComboBox to the Form with this.
-----------------------------------------------------------------------------------
'ComboBox1

'

Me.ComboBox1.Dr awMode = System.Windows. Forms.DrawMode. OwnerDrawFixed

Me.ComboBox1.Lo cation = New System.Drawing. Point(16, 232)

Me.ComboBox1.Na me = "ComboBox1"

Me.ComboBox1.Si ze = New System.Drawing. Size(121, 21)

Me.ComboBox1.Ta bIndex = 13

Me.ComboBox1.Te xt = "ComboBox1"

AddHandler Me.ComboBox1.Dr awItem, AddressOf ComboBox1_DrawI tem

---------------------------------

Private Sub FSMmain_Load(By Val sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

ComboBox1.Items .Add("Item1")

ComboBox1.Items .Add("Item2")

ComboBox1.Items .Add("Item3")

End Sub

-------------------------------

'And then the Draw item Sub

Private Sub ComboBox1_DrawI tem(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs)

Dim g As Graphics = e.Graphics

Dim r As Rectangle = e.Bounds

Dim fn As New Font("Verdana", 8, FontStyle.Regul ar)

If e.Index >= 0 Then

Dim s As String = sender.Items(e. Index)

Dim sf As New StringFormat

sf.Alignment = StringAlignment .Near

Console.WriteLi ne(e.State.ToSt ring())

e.Graphics.Draw Rectangle(New Pen(New SolidBrush(Colo r.Black), 2), r)

If e.State = DrawItemState.N oAccelerator Or e.State = DrawItemState.N oFocusRect Then

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.White), r)

e.Graphics.Draw String(s, fn, New SolidBrush(Colo r.Black), r.X, r.Y)

e.DrawFocusRect angle()

Else

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.LightBlue), r)

e.Graphics.Draw String(s, fn, New SolidBrush(Colo r.White), r.X, r.Y)

e.DrawFocusRect angle()

End If

End If

End Sub

----------------------------------------------------------

My Problem is this, When I Click the ComboBox it drops down with a white aream big enough for the 3 items but it's empty and then after 2 seconds the Items show with LightBlue Background and Black text and then when I move away from it the Black border of the Combobox staty painted. There's no crash or anything, just feels like it's really "well".

Any ideas what might be wrong?

I have Based this on the C# examples found here. http://www.csharphelp.com/archives2/archive316.html

The Examples works fine for me.. but I want to translate this into VB and I can't figure out what I'm missing.. or is there a Differance in the C# and VB languages for this kind of work?

Best Regards

/Lars Netzel



Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2958
by: anand | last post by:
Hi All, Are ownerdraw buttons supported in C# ? I have an active X control which I would like to use in CSharp. Buttons have a style BS_OWNERDRAW, and to do custom drawing you have to handle WM_DRAWITEM message. It works greate in all languages except CSharp and VB.net.
0
1090
by: Apollo440 | last post by:
If MenuItem.OwnerDraw Property is true,.NET framework does not recognize the overlapped accelerator keys. Is there a workaround? eg) +------+ |&Test | <- |&Tea | <- MenuItems has overlapped accelerator keys "T" & OwnerDraw = true
2
2838
by: Stuart Norris | last post by:
Dear Group, I am new to c# and windows form designer - coming from a Motif background. I am attempting to develop an application for a touch screen and I need to have a menu system with a larger font to allow ease of selection. I have used OwnerDraw menus implementing the DrawItemEventHandler and
2
1257
by: Peter Proost | last post by:
Hi group, I've got this ownerdraw menu module which I got from a site and modified to my personal needs, but the only problem I'm having is with the lines in a menu, when you type - as text, it normaly becomes a full line and the height of the menuitem is reduced but when you set a menu to ownerdraw and use my draw and measure item handlers this doesn't work anymore, has anyone worked out a good sloution for this before? Greetz Peter
0
1040
by: genojoe | last post by:
This code is derived from: ms-help://MS.VSCC.2003/MS.MSDNQTR.2005JUL.1033/cpref/html/frlrfSystemWindowsFormsMenuItemClassOwnerDrawTopic.htm The sample works as presented but does not contain a click event. Here is my abridged version of the code. In this code, if I use MenuItem2.OwnerDraw = False, it behaves as expected: no ownerdraw and when clicked, I see the message. If MenuItem2.OwnerDraw = True, I see the colored text but when...
1
5080
by: tmda | last post by:
I'm using OwnerDraw for some customization in my ListView - adding color to item backgrounds. I'm using the ListView specifically for it's OwnerDraw capability. I originally was using the CheckedListBox control but it has no OwnerDraw. I have not found a way to draw the checkboxes while using OwnerDraw (the checkboxes appear correctly when not using OwnerDraw). How can this be done? It would be nice if there were something similar to...
0
1468
by: =?Utf-8?B?QnJpYW4gS2l0dA==?= | last post by:
I wrote a class that inherits ComboBox to create a dropdown that contains both an image and a text description. This is for an IE browser toolbar. I use the OwnerDrawFixed method to do this. The first time click the arrow for the drop down, and shows an empty dropdown, and immediately closes it. The second time I click the arrow, it works perfectly. It does this same behavior on Vista, XP, IE6 and IE7. I'm stumped, I'm sure there...
2
2324
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i know how to work with the owner draw mode in the ListView-Class, but how do i draw the last three dots in a column if the text exceeds the columns width? To make it clear, i am talking about a ListViewItem's Subitem and the case, the text in the Subitems is longer than the columns width. This is the standard beahviour in the non-ownerdraw mode, but you have to implement it in the ownerdraw mode by yourself. How can i do that?
7
8879
by: prpradip | last post by:
I have used ListView in my Form. I have set OwnerDraw = true. And I have the DrawItem Function as private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { if (e.Item.Checked) ControlPaint.DrawCheckBox(e.Graphics, 0, e.Bounds.Top + 1, 15, 15, ButtonState.Flat | ButtonState.Checked); else ...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.