Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
TextComboBox.cs
Package: ProgressBar_src.rar [view]
Upload User: nnpulika
Upload Date: 2013-02-15
Package Size: 597k
Code Size: 7k
Category:
StatusBar
Development Platform:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Reflection;
- using UtilityLibrary.General;
- using UtilityLibrary.Win32;
- namespace UtilityLibrary.WinControls
- {
- /// <summary>
- /// Summary description for TextComboBox.
- /// </summary>
- [ToolboxItem(false)]
- public class TextComboBox : ComboBoxBase, IListViewEmbeddedControl
- {
- #region Constructors
- // For use when hosted by a toolbar
- public TextComboBox(bool toolBarUse) : base(toolBarUse)
- {
- // Override parent, we don't want to do all the painting ourselves
- // since we want to let the edit control deal with the text for editing
- // the parent class ComboBoxBase knows to do the right stuff with
- // non-editable comboboxes as well as editable comboboxes as long
- // as we change these flags below
- SetStyle(ControlStyles.AllPaintingInWmPaint
- |ControlStyles.UserPaint|ControlStyles.Opaque, false);
- }
- public TextComboBox()
- {
- // Override parent, we don't want to do all the painting ourselves
- // since we want to let the edit control deal with the text for editing
- // the parent class ComboBoxBase knows to do the right stuff with
- // non-editable comboboxes as well as editable comboboxes as long
- // as we change these flags below
- SetStyle(ControlStyles.AllPaintingInWmPaint
- |ControlStyles.UserPaint|ControlStyles.Opaque, false);
- }
- #endregion
- #region Overrides
- protected override void DrawComboBoxItem(Graphics g, Rectangle bounds, int Index, bool selected, bool editSel)
- {
- // Call base class to do the "Flat ComboBox" drawing
- base.DrawComboBoxItem(g, bounds, Index, selected, editSel);
- if ( Index != -1)
- {
- SolidBrush brush;
- brush = new SolidBrush(SystemColors.MenuText);
- Size textSize = TextUtil.GetTextSize(g, Items[Index].ToString(), Font);
- int top = bounds.Top + (bounds.Height - textSize.Height)/2;
- // Check if the combobox is bound to a Data Source
- if ( DataSource != null)
- DrawDataBoundMember(g, brush, Index, new Point(bounds.Left + 1, top));
- else
- g.DrawString(Items[Index].ToString(), Font, brush, new Point(bounds.Left + 1, top));
- brush.Dispose();
- }
- }
- protected override void DrawComboBoxItemEx(Graphics g, Rectangle bounds, int Index, bool selected, bool editSel)
- {
- // This "hack" is necessary to avoid a clipping bug that comes from the fact that sometimes
- // we are drawing using the Graphics object for the edit control in the combobox and sometimes
- // we are using the graphics object for the combobox itself. If we use the same function to do our custom
- // drawing it is hard to adjust for the clipping because of what was said about
- base.DrawComboBoxItemEx(g, bounds, Index, selected, editSel);
- if ( Index != -1)
- {
- SolidBrush brush;
- brush = new SolidBrush(SystemColors.MenuText);
- Size textSize = TextUtil.GetTextSize(g, Items[Index].ToString(), Font);
- int top = bounds.Top + (bounds.Height - textSize.Height)/2;
- // Clipping rectangle
- Rectangle clipRect = new Rectangle(bounds.Left + 4, top, bounds.Width - ARROW_WIDTH - 4, top+textSize.Height);
- Debug.WriteLine(Items[Index].ToString());
- if ( DataSource != null )
- DrawDataBoundMember(g, brush, Index, new Point(bounds.Left + 4, top));
- else
- g.DrawString(Items[Index].ToString(), Font, brush, clipRect);
- brush.Dispose();
- }
- }
- protected override void DrawDisableState()
- {
- // Draw the combobox state disable
- base.DrawDisableState();
- // Draw the specific disable state to
- // this derive class
- int index = SelectedIndex;
- if ( index == -1 ) return;
- using ( Graphics g = CreateGraphics() )
- {
- using ( Brush b = new SolidBrush(SystemColors.ControlDark) )
- {
- Rectangle rc = ClientRectangle;
- Size textSize = TextUtil.GetTextSize(g, Items[index].ToString(), Font);
- // Clipping rectangle
- int top = rc.Top + (rc.Height - textSize.Height)/2;
- Rectangle clipRect = new Rectangle(rc.Left + 4,
- top, rc.Width - 4 - ARROW_WIDTH - 4, top+textSize.Height);
- g.DrawString(Items[index].ToString(), Font, b, clipRect);
- }
- }
- }
- protected void DrawDataBoundMember(Graphics g, Brush brush, int index, Point point)
- {
- string text = string.Empty;
- if ( DataSource != null )
- {
- IList list = null;
- // We coud be bound to an array list which implement the IList interface
- // or we could be bound to a DataSet which implements the IListSource from which
- // we can get the IList interface
- if ( DataSource is IList)
- {
- // Assume this is an array object and try to get the data based
- // on this assumption
- list = (IList)DataSource;
- Debug.Assert(list != null, "ComboBox is bound to unrecognized DataSource");
- // Now extract the actual text to be displayed
- object o = list[index];
- Type objectType = o.GetType();
- // Now invoke the method that is associate with the
- // Display name property of the ComboBox
- PropertyInfo pi = objectType.GetProperty(DisplayMember);
- text = (pi!=null)?(string)pi.GetValue(o, null):o.ToString();
- }
- else
- {
- // Data set object
- if ( DataSource is IListSource )
- {
- IListSource ls = (IListSource)DataSource;
- list = ls.GetList();
- Debug.Assert(list != null, "ComboBox is bound to unrecognized DataSource");
- // This is a data set object, get the value under that assumption
- DataRowView dataRowView = (DataRowView)list[index];
- DataRow dataRow = dataRowView.Row;
- object o = dataRow[DisplayMember];
- text = o.ToString();
- }
- }
- Debug.WriteLine(text);
- g.DrawString(text, Font, brush, point);
- }
- }
- #endregion
- #region Methods
- public void FastRender(Graphics g, Rectangle bounds)
- {
- // Draw a quick representation of the combo box
- // so that it can be used as an embedded control in a list view
- // Get current text
- object selectedItem = SelectedItem;
- string text = selectedItem.ToString();
- // Draw text
- Size textSize = TextUtil.GetTextSize(g, text, Font);
- int top = bounds.Top + (bounds.Height - textSize.Height)/2;
- Debug.WriteLine("Drawing Text: " + text);
- TextUtil.DrawText(g, text, Font, new Rectangle(bounds.Left + 4, top, textSize.Width, textSize.Height));
- // Draw arrow background and arrow glyph
- Rectangle arrowRect = new Rectangle(bounds.Right-ARROW_WIDTH-1, bounds.Top+2, ARROW_WIDTH, bounds.Height-4);
- using ( Brush b = new SolidBrush(ColorUtil.VSNetControlColor) )
- {
- g.FillRectangle(b, arrowRect);
- }
- // Draw glyph
- GDIUtil.DrawArrowGlyph(g, arrowRect, ArrowGlyph.Down, SystemBrushes.ControlText);
- }
- #endregion
- }
- }