472,979 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,979 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 2564

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.