B
Bob Dankert
I am creating a custom textbox that requires me to handle the OnPaint
mechanism. Currently, I am using WM_PRINT to draw the text in the textbox
and am running into a problem. The text will never follow the font that is
specified by the textbox, it is always the same no matter what I change it
to. Is there some way to get WM_PRINT to use the font that the textbox is
set with?
I stripped down the code for my class to the following to show the issue:
using System;
using System.Windows.Forms;
namespace TransTextBox
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor,
true);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
System.IntPtr hdc = e.Graphics.GetHdc();
this.SetStyle(ControlStyles.UserPaint, false);
try
{
const Int32 WM_PRINT = 0x0317;
const long PRF_CLIENT = 0x00000004;
Message m = Message.Create(this.Handle, WM_PRINT, hdc, new
System.IntPtr(PRF_CLIENT));
this.WndProc(ref m);
}
catch { }
finally
{
e.Graphics.ReleaseHdc(hdc);
this.SetStyle(ControlStyles.UserPaint, true);
}
}
}
}
I appreciate any help - thanks.
Bob Dankert
mechanism. Currently, I am using WM_PRINT to draw the text in the textbox
and am running into a problem. The text will never follow the font that is
specified by the textbox, it is always the same no matter what I change it
to. Is there some way to get WM_PRINT to use the font that the textbox is
set with?
I stripped down the code for my class to the following to show the issue:
using System;
using System.Windows.Forms;
namespace TransTextBox
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor,
true);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
System.IntPtr hdc = e.Graphics.GetHdc();
this.SetStyle(ControlStyles.UserPaint, false);
try
{
const Int32 WM_PRINT = 0x0317;
const long PRF_CLIENT = 0x00000004;
Message m = Message.Create(this.Handle, WM_PRINT, hdc, new
System.IntPtr(PRF_CLIENT));
this.WndProc(ref m);
}
catch { }
finally
{
e.Graphics.ReleaseHdc(hdc);
this.SetStyle(ControlStyles.UserPaint, true);
}
}
}
}
I appreciate any help - thanks.
Bob Dankert