Click here to Skip to main content
15,915,733 members
Home / Discussions / C#
   

C#

 
AnswerMessage Removed Pin
19-May-04 1:05
wibblewibblewibble19-May-04 1:05 
GeneralRe: combine bitmaps ?? Pin
azusakt19-May-04 15:20
azusakt19-May-04 15:20 
AnswerRe: combine bitmaps ?? Pin
pedery19-May-04 6:24
pedery19-May-04 6:24 
Generalreturning a datareader Pin
_Searcher_19-May-04 0:39
_Searcher_19-May-04 0:39 
GeneralRe: returning a datareader Pin
Colin Angus Mackay19-May-04 0:47
Colin Angus Mackay19-May-04 0:47 
GeneralRe: returning a datareader Pin
Aryadip19-May-04 0:54
Aryadip19-May-04 0:54 
GeneralRe: returning a datareader Pin
_Searcher_19-May-04 4:19
_Searcher_19-May-04 4:19 
GeneralHorizontal scroll not working with OwnerDraw (List box) Pin
pushpi19-May-04 0:35
pushpi19-May-04 0:35 
Cry | :((
hi
friends i am working with listbox
The problem :Horizontal scroll is not working as expected when i use

OwnerDraw mode
MeasureItemEventHandler
please help

regards
and thank you in advance

/**************** code ************/

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


namespace WindowsApplication1
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

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

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

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
InitializeOwnerDrawnListBox();
}

internal System.Windows.Forms.ListBox ListBox1;

private void InitializeOwnerDrawnListBox()
{
this.ListBox1 = new System.Windows.Forms.ListBox();

// Set the location and size.
ListBox1.Location = new Point(20, 20);
ListBox1.Size = new Size(100, 100);

// Populate the ListBox.ObjectCollection property
// with several strings, using the AddRange method.
this.ListBox1.Items.AddRange(new object[]{"System.Windows.Forms",
"System.Drawing", "System.Xml", "System.Net", "System.Runtime.Remoting",
"System.Web"});

// Turn off the scrollbar.
ListBox1.ScrollAlwaysVisible = true;

// Set the border style to a single, flat border.
//ListBox1.BorderStyle = BorderStyle.FixedSingle;

// Set the DrawMode property to the OwnerDrawVariable value.
// This means the MeasureItem and DrawItem events must be
// handled.
ListBox1.DrawMode = DrawMode.OwnerDrawVariable;
ListBox1.MeasureItem +=
new MeasureItemEventHandler(ListBox1_MeasureItem);
ListBox1.DrawItem += new DrawItemEventHandler(ListBox1_DrawItem);
this.Controls.Add(this.ListBox1);

}


// Handle the DrawItem event for an owner-drawn ListBox.
private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
{

// If the item is the selected item, then draw the rectangle
// filled in blue. The item is selected when a bitwise And
// of the State property and the DrawItemState.Selected
// property is true.
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(Brushes.CornflowerBlue, e.Bounds);
}
else
{
// Otherwise, draw the rectangle filled in beige.
e.Graphics.FillRectangle(Brushes.Beige, e.Bounds);
}

// Draw a rectangle in blue around each item.
e.Graphics.DrawRectangle(Pens.Blue, e.Bounds);

// Draw the text in the item.
e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(),
this.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);

// Draw the focus rectangle around the selected item.
e.DrawFocusRectangle();
}
// Handle the MeasureItem event for an owner-drawn ListBox.
private void ListBox1_MeasureItem(object sender,
MeasureItemEventArgs e)
{

// Cast the sender object back to ListBox type.
ListBox theListBox = (ListBox) sender;
// Get the string contained in each item.
string itemString = (string) theListBox.Items[e.Index];

// Split the string at the " . " character.
string[] resultStrings = itemString.Split('.');

// If the string contains more than one period, increase the
// height by ten pixels; otherwise, increase the height by
// five pixels.
if (resultStrings.Length>2)
{
e.ItemHeight += 10;
//theListBox.HorizontalScrollbar = true ;
}
else
{
e.ItemHeight += 5;
}
e.ItemWidth +=100000 ;

}

}
}


P.S. PATWAL
GeneralRe: Horizontal scroll not working with OwnerDraw (List box) Pin
Aryadip19-May-04 0:46
Aryadip19-May-04 0:46 
GeneralRe: Horizontal scroll not working with OwnerDraw (List box) Pin
pushpi19-May-04 1:12
pushpi19-May-04 1:12 
GeneralRe: Horizontal scroll not working with OwnerDraw (List box) Pin
Aryadip19-May-04 2:18
Aryadip19-May-04 2:18 
QuestionHow to check Maximize button click event of a Form or how to check whether present size of form is maximum available size. Pin
sachinkalse18-May-04 23:13
sachinkalse18-May-04 23:13 
AnswerRe: How to check Maximize button click event of a Form or how to check whether present size of form is maximum available size. Pin
Aryadip19-May-04 0:19
Aryadip19-May-04 0:19 
AnswerRe: How to check Maximize button click event of a Form or how to check whether present size of form is maximum available size. Pin
Heath Stewart19-May-04 4:20
protectorHeath Stewart19-May-04 4:20 
Generalretrieving the value of XML parent problem Pin
dhananjayav18-May-04 23:09
dhananjayav18-May-04 23:09 
GeneralRe: retrieving the value of XML parent problem Pin
Heath Stewart19-May-04 4:18
protectorHeath Stewart19-May-04 4:18 
GeneralDisplaying data from database into a checkbox list Pin
M3L18-May-04 22:47
M3L18-May-04 22:47 
GeneralRe: Displaying data from database into a checkbox list Pin
Heath Stewart19-May-04 4:13
protectorHeath Stewart19-May-04 4:13 
GeneralNetwork listener Pin
mhmoud rawas18-May-04 22:26
mhmoud rawas18-May-04 22:26 
QuestionDisposing Collection of IDisposable? Pin
Dr Herbie18-May-04 22:26
Dr Herbie18-May-04 22:26 
AnswerRe: Disposing Collection of IDisposable? Pin
Daniel Turini18-May-04 22:43
Daniel Turini18-May-04 22:43 
GeneralDesign Time Property Window Pin
acidcrush18-May-04 22:19
acidcrush18-May-04 22:19 
GeneralRe: Design Time Property Window Pin
Heath Stewart19-May-04 4:08
protectorHeath Stewart19-May-04 4:08 
Generalproblem with using VNC hooking Pin
fu018-May-04 22:03
fu018-May-04 22:03 
GeneralRe: problem with using VNC hooking Pin
Dave Kreskowiak19-May-04 3:24
mveDave Kreskowiak19-May-04 3:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.