In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how ListBox implements the display of multiple lines of Item items in C #. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. First select the ListBox control dragged to the panel, click Properties, select DrawMode, and change it to OwnerDrawFixed or OwnerDrawVariable.
2. Again in the Properties tool, switch to the event (the lightning icon) and double-click DrawItem under the behaviors menu to add an event.
3. A new event has been added to the code generated by the form designer
This.listBox1.DrawItem + = new System.Windows.Forms.DrawItemEventHandler (this.listBox1_DrawItem)
4. Friends who have learned should know that there will be a listBox1_DrawItem () method in the code, so write the code in it.
Private void listBox1_DrawItem (object sender, System.Windows.Forms.DrawItemEventArgs e) {e.DrawBackground (); Brush myBrush = Brushes.Black; / / initialize font color = black this.listBox1.ItemHeight=90 / / set item height. Set the value according to specific needs / / set the font color for each item / / you can not write this switch switch (e.Index) {case 0: myBrush = Brushes.Red; break; case 1: myBrush = Brushes.Orange if you don't need it. Break; case 2: myBrush = Brushes.Purple; break; case 4: myBrush = Brushes.White; break } e.Graphics.DrawString (listBox1.Items [e.Index] .ToString (), e.Font, myBrush,e.Bounds,null); / / if you don't need this sentence, try e.DrawFocusRectangle ();}
In fact, friends who have seen MSDN should know, there is similar code in MSDN, I just modified a few places, added item high this.listBox1.ItemHeight=90, you can enter multiple characters, it should be noted here that the height of the whole ListBox should be a little higher than the multiple of the Item item you set, otherwise ListBox will be distorted when displayed!
Thank you for reading! This is the end of this article on "how to display multiple lines of Item items in ListBox in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.