473,386 Members | 1,734 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,386 software developers and data experts.

Help,ownerdrawn ListView not font-sizeable

Hello,

The code below represents a simple ownerdrawn,
Listview class in C#. Its purpose is to avoid
the flicker of the MS ListView. So I can't fall
back to their one.

Does anybody know why I cannot change the
size of the ListView's font (ListView.Font)
from e.g.
Microsoft Sans Serif; 8,25pt
to e.g.
Microsoft Sans Serif; 15,75pt ?
Can someone help ?

What I noticed is, that the text displayed is
growing as intended.
However, the rectangle returned by
ListViewItem.GetBounds(ItemBoundsPortion.Entire)
always remains fixed. That is, it remains for ever on the bounds
corresponding
to 8,25pt .

When compiled and being run, the blue rectangle around each item
displays
the entire item bounds. Pls, increase the font size, compile and run
again.
You'll then see the mess.

Regards, Martin
it follows FlickerfreeListView.cs and Form1.cs
pls watch for word-wrap
FlickerfreeListView.cs
------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace flickerfree
{
/// <summary>
/// Summary description for FlickerfreeListView.
/// </summary>
public class FlickerfreeListView : System.Windows.Forms.ListView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public FlickerfreeListView()
{
// This call is required by the Windows.Forms Form
Designer.
InitializeComponent();

// TODO: Add any initialization after the InitForm call
SetStyle( ControlStyles.DoubleBuffer
| ControlStyles.UserPaint
| ControlStyles.AllPaintingInWmPaint
, true);
}

void DrawItem( ListViewItem item, PaintEventArgs pea )
{
SolidBrush fbrush;
SolidBrush bbrush;

if( true == item.Selected )
{
if( this.Focused )
{
bbrush = new SolidBrush( SystemColors.Highlight );
fbrush = new SolidBrush(
SystemColors.HighlightText );
}
else
{
bbrush = new SolidBrush(
SystemColors.InactiveCaption );
fbrush = new SolidBrush(
SystemColors.InactiveCaptionText );
}
}
else
{
bbrush = new SolidBrush( SystemColors.Window );
fbrush = new SolidBrush( item.ForeColor );
}
pea.Graphics.FillRectangle(bbrush,item.GetBounds(I temBoundsPortion.Label));
pea.Graphics.DrawString(item.Text,item.Font,fbrush ,item.GetBounds(ItemBoundsPortion.Label).Location) ;
pea.Graphics.DrawRectangle(System.Drawing.Pens.Blu e,item.GetBounds(ItemBoundsPortion.Entire));
}

protected override void OnPaint(PaintEventArgs pea)
{
Rectangle rc = pea.ClipRectangle;
foreach( ListViewItem item in Items )
{
if( true == rc.IntersectsWith(
item.GetBounds(ItemBoundsPortion.Entire)) )
DrawItem( item, pea );
}
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

Form1.cs
-----------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace flickerfree
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private flickerfree.FlickerfreeListView flickerfreeListView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after
InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.flickerfreeListView1 = new
flickerfree.FlickerfreeListView();
this.SuspendLayout();
//
// flickerfreeListView1
//
this.flickerfreeListView1.Dock =
System.Windows.Forms.DockStyle.Fill;
this.flickerfreeListView1.Font = new
System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.flickerfreeListView1.Name = "flickerfreeListView1";
this.flickerfreeListView1.Size = new
System.Drawing.Size(512, 277);
this.flickerfreeListView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(512, 277);
this.Controls.AddRange(new System.Windows.Forms.Control[]
{

this.flickerfreeListView1});
this.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
for(int i=0; i<5; i++)
this.flickerfreeListView1.Items.Add("item#"+i.ToSt ring());
}
}
}
Nov 15 '05 #1
0 2594

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

Similar topics

5
by: hasden | last post by:
I'm working in .NET and I can't seem to get the behavior that I need from the combobox. I'm sure it's possible, I just don't have the .NET experience. Any help would be greatly appreciated. I need...
2
by: Matthias Kwiedor | last post by:
I have a Listview in Detail Mode. No i create lines with ListViewItem lvwItem = new ListViewItem(); lvwItem = new System.Windows.Forms.ListViewItem(new...
3
by: Robert Misiak | last post by:
Is it possible to have a different font in individual listView columns? When I do something like: ListViewItem lsi; .... lsi.SubItems.Font = new Font (lsi.SubItems.Font,...
1
by: Danny van Kasteel | last post by:
Hi, I'm having some trouble drawing items in controls that I've marked as ownerdrawn. I'm currently developing an application that has ownerdrawn statusbar panels, and a listbox that contains...
0
by: Larry | last post by:
Although there are font attribute properties for the items in a ListView component, the complier tells me that they are read-only. Is there any way to get access and change the font poperties of...
2
by: Terry Olsen | last post by:
Does anyone have an example of how I could print a ListView control? It'd sure be easier to do this than to try to format the output in DrawStrings... Thanks.
7
by: Dino Buljubasic | last post by:
Hi, I am using C# 2.0 (VS2005) to build my user control that contains a number of dynamically loaded ListViews. ListViewItems have their ForeColor properties set to either black or blue to...
1
by: lewisjosh2 | last post by:
I'm a newbie to windows forms and I'm having trouble finding any information about how to create a custom listview. In my app, I'm using a 'large icon' view and basically what I want to do is: ...
0
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I have a listview that when I select an item, it populates a details view. I want to show the item that was selected in the listview by changing it to yellow. Trouble is, the selected item does not...
3
by: NvrBst | last post by:
I have ListView in Detail Mode and the length of each item is cut off at 259 characters. The "listView1.Items.Text" contains the entire string, however, just the display is truncated at 259...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.