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

Home Posts Topics Members FAQ

owner drawn problem

I cant seem to remember this one... I have a list view, and im owner drawing
the items, i dont want the selection to hide when it loses focus so i have
hideselection = false, but when i owner draw this all the items come up gray
instead of just the one that is selected when focus is lost, the blue one
shows up correctly when it has focus... any help on this would be great... i
need to do most of my drawing in the sub items drawing because of how my
control is structured..

here is an example, im trying to get it to act like a list view does when
its not owner drawn, so i can customize it later after i get this working
correctly

Public Class Form1

Private Sub ListView1_DrawC olumnHeader(ByV al sender As Object, ByVal e As
System.Windows. Forms.DrawListV iewColumnHeader EventArgs) Handles
ListView1.DrawC olumnHeader

e.DrawDefault = True

End Sub

Private Sub ListView1_DrawS ubItem(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.DrawListV iewSubItemEvent Args) Handles
ListView1.DrawS ubItem

' e.Graphics.Fill Rectangle(Drawi ng.SystemBrushe s.Highlight, e.Bounds)

' ControlPaint.Dr awFocusRectangl e(e.Graphics, e.Item.Bounds,
Drawing.SystemC olors.WindowTex t, Drawing.SystemC olors.Highlight )

Debug.WriteLine (e.ItemIndex & ":" & e.ItemState.ToS tring)

If (e.ItemState And ListViewItemSta tes.Selected) =
ListViewItemSta tes.Selected Then

If (e.ItemState And ListViewItemSta tes.Focused) = ListViewItemSta tes.Focused
Then

' FOCUSED AND SELECTED

e.Graphics.Fill Rectangle(Drawi ng.SystemBrushe s.Highlight, e.Bounds)

ControlPaint.Dr awFocusRectangl e(e.Graphics, e.Item.Bounds,
Drawing.SystemC olors.WindowTex t, Drawing.SystemC olors.Highlight )

Else

' JUST SELECTED

e.Graphics.Fill Rectangle(Drawi ng.SystemBrushe s.Control, e.Bounds)

End If

' ELSE NOT SELECTED

Else

e.Graphics.Fill Rectangle(Drawi ng.SystemBrushe s.Window, e.Bounds)

End If

e.DrawText()

End Sub

End Class

<Global.Microso ft.VisualBasic. CompilerService s.DesignerGener ated()> _

Partial Class Form1

Inherits System.Windows. Forms.Form

'Form overrides dispose to clean up the component list.

<System.Diagnos tics.DebuggerNo nUserCode()> _

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing AndAlso components IsNot Nothing Then

components.Disp ose()

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnos tics.DebuggerSt epThrough()> _

Private Sub InitializeCompo nent()

Dim ListViewItem1 As System.Windows. Forms.ListViewI tem = New
System.Windows. Forms.ListViewI tem("dfhfdh")

Dim ListViewItem2 As System.Windows. Forms.ListViewI tem = New
System.Windows. Forms.ListViewI tem("56h56h")

Dim ListViewItem3 As System.Windows. Forms.ListViewI tem = New
System.Windows. Forms.ListViewI tem("54h45h")

Me.ListView1 = New System.Windows. Forms.ListView

Me.ColumnHeader 1 = New System.Windows. Forms.ColumnHea der

Me.ColumnHeader 2 = New System.Windows. Forms.ColumnHea der

Me.Button1 = New System.Windows. Forms.Button

Me.SuspendLayou t()

'

'ListView1

'

Me.ListView1.Co lumns.AddRange( New System.Windows. Forms.ColumnHea der()
{Me.ColumnHeade r1, Me.ColumnHeader 2})

Me.ListView1.Fu llRowSelect = True

Me.ListView1.Hi deSelection = False

Me.ListView1.It ems.AddRange(Ne w System.Windows. Forms.ListViewI tem()
{ListViewItem1, ListViewItem2, ListViewItem3})

Me.ListView1.Lo cation = New System.Drawing. Point(0, 0)

Me.ListView1.Na me = "ListView1"

Me.ListView1.Ow nerDraw = True

Me.ListView1.Si ze = New System.Drawing. Size(241, 168)

Me.ListView1.Ta bIndex = 0

Me.ListView1.Us eCompatibleStat eImageBehavior = False

Me.ListView1.Vi ew = System.Windows. Forms.View.Deta ils

'

'Button1

'

Me.Button1.Loca tion = New System.Drawing. Point(94, 211)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing. Size(75, 23)

Me.Button1.TabI ndex = 1

Me.Button1.Text = "Button1"

Me.Button1.UseV isualStyleBackC olor = True

'

'Form1

'

Me.AutoScaleDim ensions = New System.Drawing. SizeF(6.0!, 13.0!)

Me.AutoScaleMod e = System.Windows. Forms.AutoScale Mode.Font

Me.ClientSize = New System.Drawing. Size(292, 273)

Me.Controls.Add (Me.Button1)

Me.Controls.Add (Me.ListView1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

End Sub

Friend WithEvents ListView1 As System.Windows. Forms.ListView

Friend WithEvents ColumnHeader1 As System.Windows. Forms.ColumnHea der

Friend WithEvents ColumnHeader2 As System.Windows. Forms.ColumnHea der

Friend WithEvents Button1 As System.Windows. Forms.Button

End Class
Apr 25 '06 #1
0 1413

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

Similar topics

0
1804
by: James | last post by:
Is there a way to Owner drawn tray context menu ? - I know that there is a bug with the custom drawing of a context menu assigned to a tray icon - but I was hoping someone could advise me as to how to create one from scratch - I have tried using the current cursor position to pop up a context menu that is not assigned to a tray icon - but with no joy.. Any advice please... -- James
1
2825
by: boxim | last post by:
hi all, i need to develop a control to show contact details for companies, in a similar fashion to the way outlook shows contacts. at the moment, i'm cheating using HTML fed from a web server, however i need to now make it use it's own control. what's the best way of doing this? tia
2
2511
by: Eric | last post by:
I implemented owner drawing on the main and context menus of my main form. It works fine. There is also a notify icon control that has a context menu. When the icon is in the status bar, it works perfectly fine when it is double-clicked. However, when I try to initialize the notify icon's context menu as an owner-drawn menu, all the text in that menu disappears. Is owner drawing a notify icon's context menu possible? I saw someone...
1
2089
by: Michael C | last post by:
Anyone know if there are some code samples out there of owner-drawn buttons? Specifically I'm trying to create .NET IDE style buttons for a form. Thanks, Michael C.
1
2874
by: Patty O'Dors | last post by:
Hi I have some code to create an ownerdrawn listbox (derived), and when I add an item to it, the bold text of the first item (the title, 'Collections and Maturities') mysteriously seems to get bunched up at the right, i.e. squashed up! any idea why? The main bit of the code is as such // (in progressReporter.cs) protected struct LBRow //a row of the listbox, whether it be the title or a
2
3122
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I get all kinds of screen artifacts and weirdness. My general goal is: list item with a few areas for text, every other item shaded a light color for readability, font color changes with selection. The listbox is populated with custom structurs...
0
1628
by: Brian Henry | last post by:
Ok whats going on here... got a couple problems... this is relevant now to this group since .NET 2.0 is finally RTM 1) draws really slow when making it a large form (resizing speed is jerky) to a res from 100x100 to 1280x1024 once it gets above 500x500 it starts jerking you can see the screen refreshing as it paints 2) sometimes the background selection when you select multiple items then move the mouse around on the screen dissapear...
0
953
by: Steve Marshall | last post by:
Hi All, I'm working on an owner-drawn combo box which will display multiple columns in the list, either from a table in an associated DataSourse or from delimited strings in the Items collection. It's all going quite well, and was actually easier to achieve than I had expected. But I am seeing one peculiar anomaly when I make a selection from the list. Eveything works perfectly if the list is populated from a DataSource. But if the...
0
2677
by: LostInMd | last post by:
Hi All, I've got an owner drawn listBox where I draw and measure the items that I add to the listBox. For example, I have a listBox that can only display 10 characters on each horizontal line. The majority of my items contain much more than 10 characters and thus the reason for my use of owner drawn listBoxes - I do not want to use a horizontal scrollbar, instead I want the text of each item to wrap onto multiple lines. I do use a...
0
8303
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
8821
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...
0
8602
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...
0
7316
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4150
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.