Windows Forms Programming with C# by Unknown
Author:Unknown
Language: eng
Format: epub
Figure 10.8
This figure shows the various measurements used to calculate a list item’s
width and height.
The following steps implement the code required for the MeasureItem event. Fig-
ure 10.8 illustrates the various measurements used to determine the width and height
of the item.
CALCULATE THE LIST ITEM SIZE DYNAMICALLY
Action
Result
1
In the MainForm.cs window, add
private static Rectangle _drawRect
a static Rectangle to the
= new Rectangle(0,0,45,45);
MainForm class to hold the
drawing rectangle for the image.
2
Add a MeasureItem event
private void lstPhotos_MeasureItem
handler for the lstPhotos list
(object sender,
Windows.Forms.MeasureItemEventArgs e)
box.
{
3
Calculate the size of the image
Photograph p = _album[e.Index];
when scaled into the drawing
Rectangle scaledRect
= p.ScaleToFit(_drawRect);
rectangle.
4
Calculate the item’s height.
e.ItemHeight = Math.Max(scaledRect.Height,
lstPhotos.Font.Height) + 2;
5
Calculate the item’s width.
e.ItemWidth = scaledRect.Width + 2
+ (int) e.Graphics.MeasureString(
p.Caption, lstPhotos.Font).Width;
}
For the item’s height, this code uses the larger of the scaled item’s height and the
ListBox control’s font height, plus 2 pixels as padding between subsequent items in
the list.
e.ItemHeight = Math.Max(scaledRect.Height, lstPhotos.Font.Height) + 2;
For the item’s width, the width of the scaled image plus the width of the drawn string
is used, plus 2 pixels as padding between the image and the text. To do this, the
OWNER-DRAWN LISTS
347
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(27094)
Hello! Python by Anthony Briggs(25942)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(25285)
Kotlin in Action by Dmitry Jemerov(24393)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(23591)
Dependency Injection in .NET by Mark Seemann(23311)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(21942)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(20847)
Grails in Action by Glen Smith Peter Ledbrook(19869)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17072)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(16832)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(14464)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(12581)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11865)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10650)
Hit Refresh by Satya Nadella(9236)
The Kubernetes Operator Framework Book by Michael Dame(8588)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8443)
Robo-Advisor with Python by Aki Ranin(8386)