Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2006

Display text in different colors in a textbox using WndProc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
digitalshehan - 29 Jun 2006 17:19 GMT
Hi All,

I need to have a text box that displays text in different colors. I
tired overriding WndProc but I still couldn't. Below is the code
snippet I'm using.

Would appreciate if someone could help me out with this (wolud
appreciate if the solution is done using WndProc)

      const int WM_PAINT = 0xF;
       [DllImport("user32.dll")]
       public static extern IntPtr GetWindowDC(IntPtr hWnd);
       [DllImport("user32.dll")]
       public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

       protected override void WndProc(ref
System.Windows.Forms.Message m)
       {
           base.WndProc(ref m);
           switch (m.Msg)
           {
               case WM_PAINT:
                   IntPtr hDC = GetWindowDC(m.HWnd);
                   Graphics graph = Graphics.FromHdc(hDC);
                   graph.DrawString(this.Text, this.Font, new
SolidBrush(Color.Red), 1.6F, 2.5F);

                   graph.Dispose();
                   ReleaseDC(m.HWnd, hDC);

                   m.Result = IntPtr.Zero;
                   break;

           }
       }

Thanks!
Shehan

p.s. I'm using .net2.0 (if its of any help)
Alexander Ubillus - 29 Jun 2006 18:50 GMT
Hi Shehan ,
Why don't you use a RichTextBox ? it behaves exactly as the TextBox but it
lets you apply several colors and font styles to text.

Overriding a core common control functionality will cost you much time. You
would also have to override the Key pressing because it also makes the
textbox draw its text.

> Hi All,
>
[quoted text clipped - 36 lines]
>
> p.s. I'm using .net2.0 (if its of any help)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.