473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Combobox OnPaint method

1. I was trying to use a flatcombo box. I found code on codeproject
that did what I needed. They used the following code in the WndProc
overridden procedure.

Dim g As Graphics = Me.CreateGraphics
g.FillRectangle(BorderBrush, Me.ClientRectangle)

I thought using CreateGraphics was a no-no if you could avoid it. So I
changed it to

Dim g As Graphics = Graphics.FromHwnd(Me.Handle)
g.FillRectangle(Brushes.Black, Me.ClientRectangle)

Is my was a better way of doing it?

2. I thought it would be better to do this in the onpaint override of
the combobox, but it never gets called. Why not?

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As Rectangle = New Rectangle(Me.Width - 15, 3, 12,
Me.Height - 6)
e.Graphics.FillRectangle(Brushes.Black, rect)
e.Graphics.FillRectangle(Brushes.Black, Me.ClientRectangle)
End Sub

Thanks for the info.
Chris
Nov 21 '05 #1
1 5233
Hi,

Add this in sub new for your class to get the onpaint event to
work.

Me.SetStyle(ControlStyles.UserPaint, True)

Ken
---------------------
"Chris" <no@spam.com> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...
1. I was trying to use a flatcombo box. I found code on codeproject
that did what I needed. They used the following code in the WndProc
overridden procedure.

Dim g As Graphics = Me.CreateGraphics
g.FillRectangle(BorderBrush, Me.ClientRectangle)

I thought using CreateGraphics was a no-no if you could avoid it. So I
changed it to

Dim g As Graphics = Graphics.FromHwnd(Me.Handle)
g.FillRectangle(Brushes.Black, Me.ClientRectangle)

Is my was a better way of doing it?

2. I thought it would be better to do this in the onpaint override of
the combobox, but it never gets called. Why not?

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As Rectangle = New Rectangle(Me.Width - 15, 3, 12,
Me.Height - 6)
e.Graphics.FillRectangle(Brushes.Black, rect)
e.Graphics.FillRectangle(Brushes.Black, Me.ClientRectangle)
End Sub

Thanks for the info.
Chris
Nov 21 '05 #2

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

Similar topics

2
by: Richard Bateman | last post by:
I need to make a combo box that doesn't look like the standard windows controls. I thought that extending the combobox control would make the most sense, so I could draw it myself. However,...
5
by: malcolm | last post by:
I'm trying to make a combo box custom control (Windows Forms .NET 1.1 c#) that can behave like a label programatically at run time. This is actually a strong feature request by our customers. I...
20
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the...
3
by: Tim | last post by:
Dear All, I have spend a number of hours attempting to find some answers about how to remove the 3D BorderStyle within a combobox and have come to the conclusion that the simplest method is to...
4
by: RSH | last post by:
I tried an implementation of overriding a ComboBox control. I am simply trying to avoid it repainting, but I can't seem to get it to work. What am I doing wrong? Please help. Thanks, Ron
4
by: Vish | last post by:
Hi, I need to make the text on a combobox that is disabled to be drawn with a black color. I was not able to find any help on this online. The drawItem seems to apply only for the dropdpwn...
0
by: ian_jacobsen | last post by:
I have a control that is derived from the standard ComboBox. I have an override for the OnPaint method that paints a border, drop down arrow button, background, and foreground. The only problem...
6
by: ian_jacobsen | last post by:
I have a control that is derived from the standard ComboBox. I want to lock or suppress the DropDown when the arrow button is clicked without disabling the control. This is related to another...
6
by: Nathan Laff | last post by:
Why when I inherit a ComboBox and make no code changes, when I set the new control DropDownStyle to dropDownList it appears different than the standard ComboBox control on Vista? In Windows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.