Click here to Skip to main content
15,914,642 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help - PlaySound only plays default sound in C# Pin
Christian Graus9-May-05 15:27
protectorChristian Graus9-May-05 15:27 
GeneralRe: Help - PlaySound only plays default sound in C# Pin
Heath Stewart9-May-05 21:34
protectorHeath Stewart9-May-05 21:34 
GeneralSelectable SubItem in a Listview Pin
Anonymous9-May-05 12:06
Anonymous9-May-05 12:06 
GeneralRe: Selectable SubItem in a Listview Pin
MoustafaS9-May-05 12:35
MoustafaS9-May-05 12:35 
GeneralRe: Selectable SubItem in a Listview Pin
rudy.net9-May-05 18:15
rudy.net9-May-05 18:15 
GeneralRe: Selectable SubItem in a Listview Pin
mav.northwind9-May-05 19:57
mav.northwind9-May-05 19:57 
GeneralRe: Selectable SubItem in a Listview Pin
Anonymous10-May-05 4:47
Anonymous10-May-05 4:47 
GeneralSelection colors in an extended RichTextBox Pin
methodincharge9-May-05 11:35
methodincharge9-May-05 11:35 
I recently discovered code for extending the RichTextBox to allow for a Background color on a selection, which is exactly what I neeed. However I am having some problems dealing with the Select/Selection properties. It seems that as soon as I append text to the RichTextBox the entire thing inherits the colors of the last SelectionBackColor given. Here is some sample code:

public class ExtendedRichTextBox : RichTextBox<br />
		{<br />
			#region Fields<br />
			private const int EM_SETCHARFORMAT = 1092;<br />
			private const int EM_GETCHARFORMAT = 1082;<br />
			private const int CFM_BACKCOLOR = 67108864;<br />
			private const int SCF_SELECTION = 1;<br />
<br />
			[StructLayout( LayoutKind.Sequential )]<br />
				private struct CHARFORMAT<br />
			{<br />
				public int cbSize;<br />
				public uint dwMask;<br />
				public uint dwEffects;<br />
				public int yHeight;<br />
				public int yOffset;<br />
				public int crTextColor;<br />
				public byte bCharSet;<br />
				public byte bPitchAndFamily;<br />
				[MarshalAs( UnmanagedType.ByValArray, SizeConst = 32 )]<br />
				public char[] szFaceName;<br />
    <br />
				// CHARFORMAT2 from here onwards.<br />
				public short wWeight;<br />
				public short sSpacing;<br />
				public int crBackColor;<br />
				public int LCID;<br />
				public uint dwReserved;<br />
				public short sStyle;<br />
				public short wKerning;<br />
				public byte bUnderlineType;<br />
				public byte bAnimation;<br />
				public byte bRevAuthor;<br />
			}<br />
<br />
			[DllImport( "user32", CharSet = CharSet.Auto )]<br />
			private static extern int SendMessage( HandleRef hWnd, int msg,<br />
				int wParam, ref CHARFORMAT lp );<br />
			#endregion<br />
<br />
			#region Constructors<br />
			public ExtendedRichTextBox() <br />
			{<br />
			}<br />
			#endregion<br />
<br />
			public Color SelectionBackColor<br />
			{<br />
				get<br />
				{<br />
					CHARFORMAT fmt = new CHARFORMAT();<br />
					fmt.cbSize = Marshal.SizeOf( fmt );<br />
        <br />
					// Get the background color.<br />
					SendMessage( new HandleRef( this, Handle ), EM_GETCHARFORMAT,<br />
						SCF_SELECTION, ref fmt );<br />
        <br />
					// Default to Color.Empty as there could be<br />
					// several colors present in this selection.<br />
					if ( ( fmt.dwMask & CFM_BACKCOLOR ) == 0 )<br />
						return Color.Empty;<br />
        <br />
					// Deal with the weird Windows color format.<br />
					int backCol = fmt.crBackColor;<br />
					Color ret = ColorTranslator.FromWin32( backCol );<br />
        <br />
					return ret;<br />
				}<br />
    <br />
				set<br />
				{<br />
					CHARFORMAT fmt = new CHARFORMAT();<br />
					fmt.cbSize = Marshal.SizeOf( fmt );<br />
					fmt.dwMask = CFM_BACKCOLOR;<br />
        <br />
					// Deal with the weird Windows color format.<br />
					fmt.crBackColor = ColorTranslator.ToWin32( value );<br />
        <br />
					// Set the background color.<br />
					SendMessage( new HandleRef( this, Handle ), EM_SETCHARFORMAT,<br />
						SCF_SELECTION, ref fmt );<br />
				}<br />
			}<br />
			public void AppendText(String text,Color backcolor,Color color,Font font) <br />
			{<br />
				int len = this.Text.Length;<br />
				this.Text += text;<br />
				this.Select(len,text.Length-1);<br />
				this.SelectionBackColor = backcolor;<br />
				this.SelectionColor = color;<br />
				this.SelectionFont = font;<br />
			}<br />
		}


I don't quite know what the problem is and moreover how the Selection properties really work. Anyone have any insight? Thanks.
GeneralRe: Selection colors in an extended RichTextBox Pin
leppie9-May-05 14:40
leppie9-May-05 14:40 
GeneralAutomate Microsoft Access Pin
sinnen9-May-05 10:36
sinnen9-May-05 10:36 
GeneralMarshalling structs with two different char sets Pin
Anonymous9-May-05 9:13
Anonymous9-May-05 9:13 
GeneralDetecting a FileDrop event on an external program Pin
TofuBug249-May-05 7:40
TofuBug249-May-05 7:40 
GeneralRe: Detecting a FileDrop event on an external program Pin
Christian Graus9-May-05 12:31
protectorChristian Graus9-May-05 12:31 
GeneralPassing command line options to msi installer created as .NET deployment project Pin
StormShearon9-May-05 7:00
StormShearon9-May-05 7:00 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
mav.northwind9-May-05 20:01
mav.northwind9-May-05 20:01 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
StormShearon10-May-05 5:09
StormShearon10-May-05 5:09 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
mav.northwind10-May-05 20:14
mav.northwind10-May-05 20:14 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
StormShearon12-May-05 4:56
StormShearon12-May-05 4:56 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
StormShearon12-May-05 4:56
StormShearon12-May-05 4:56 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
StormShearon13-May-05 10:17
StormShearon13-May-05 10:17 
GeneralRe: Passing command line options to msi installer created as .NET deployment project Pin
OBRon16-Dec-08 11:37
OBRon16-Dec-08 11:37 
GeneralLive Communications Server Pin
Scott Serl9-May-05 5:19
Scott Serl9-May-05 5:19 
GeneralNon-Compiled Files in Solution Pin
C_Simpkins9-May-05 5:15
C_Simpkins9-May-05 5:15 
GeneralRe: Non-Compiled Files in Solution Pin
Christian Graus9-May-05 12:29
protectorChristian Graus9-May-05 12:29 
GeneralRe: Non-Compiled Files in Solution Pin
C_Simpkins9-May-05 17:01
C_Simpkins9-May-05 17:01 

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.