Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Horizontal scroll not working with OwnerDraw (List box)

Horizontal scroll not working with OwnerDraw (List box)

Scheduled Pinned Locked Moved C#
helpcsharpgraphicsdockerxml
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pushpi
    wrote on last edited by
    #1

    :(( 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

    A 1 Reply Last reply
    0
    • P pushpi

      :(( 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

      A Offline
      A Offline
      Aryadip
      wrote on last edited by
      #2

      hi, I guess you need to set the "listBox1.HorizontalScrollbar = true" property of the ListBox... and that will do the magic... regards, Aryadip. Cheers !! and have a Funky day !!

      P 1 Reply Last reply
      0
      • A Aryadip

        hi, I guess you need to set the "listBox1.HorizontalScrollbar = true" property of the ListBox... and that will do the magic... regards, Aryadip. Cheers !! and have a Funky day !!

        P Offline
        P Offline
        pushpi
        wrote on last edited by
        #3

        i did that !!!! for c#'s sake !!! check the code P.S. PATWAL

        A 1 Reply Last reply
        0
        • P pushpi

          i did that !!!! for c#'s sake !!! check the code P.S. PATWAL

          A Offline
          A Offline
          Aryadip
          wrote on last edited by
          #4

          hi, But your code shows that the line is commented... for your ease let me point out the line with repeated "*"s... // 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; /*********** you have commented here**********************/ //theListBox.HorizontalScrollbar = true ; /********************************************************/ } else { e.ItemHeight += 5; } e.ItemWidth +=100000 ; } and if it has still not worked... then try declaring the same when you are instantiating or rather creating the listbox... regards, Aryadip. Cheers !! and have a Funky day !!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups