Click here to Skip to main content
12,748,373 members (40,318 online)
Click here to Skip to main content

Stats

410.3K views
14.4K downloads
240 bookmarked
Posted 30 Dec 2004

Embedding Controls in a ListView

, 30 Dec 2004 CPOL
How to use arbitrary controls in ListView cells.
ListViewEmbeddedControls
App.ico
ListViewEmbeddedControls.csproj.user
bin
Release
ListViewEmbeddedControls.exe
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

namespace ListViewEmbeddedControls
{
	/// <summary>
	/// Zusammenfassung f�r ReadOnlyRichTextBox.
	/// </summary>
	public class ReadOnlyRichTextBox : RichTextBox
	{
		public ReadOnlyRichTextBox()
		{
			ReadOnly=true;
			TabStop=false;

			SetStyle(ControlStyles.Selectable, false);
		}

		// Font is overridden because assigning the RichTextBox to a new parent sets
		// its Font to the parent's Font and thus loses all formatting of existing RTF content.
		protected Font _font = new Font("Arial", 10);
		public override Font Font
		{
			get 
			{
				return _font;
			}
			set 
			{
				_font = value;
			}
		}

		[ Browsable(false) ]
		public new bool ReadOnly
		{
			get { return true; }
			set { }
		}
		
		[ Browsable(false) ]
		public new bool TabStop
		{
			get { return false; }
			set {  }
		}

		const int WM_SETFOCUS = 0x0007;
		protected override void WndProc(ref Message m)
		{
			switch (m.Msg)
			{
				case WM_SETFOCUS:
					// We don't want the RichTextBox to be able to receive focus, so just
					// pass the focus back to the control it came from.
					IntPtr prevCtl = m.WParam;
					Control c = Control.FromHandle(prevCtl);
					c.Select();
					return;
			}
			base.WndProc (ref m);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

mav.northwind
Software Developer (Senior) 4voice AG
Germany Germany
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 31 Dec 2004
Article Copyright 2004 by mav.northwind
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid