Bob
Mon Jul 18 08:21:20 CDT 2005
Thanks a lot for the help, Jeffrey. I never realized you could view the
code of the framework - this is definately nice to know! Out of curiousity,
which tools did you use to view the code of the Font property?
Thanks,
Bob
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:xgQGNX2iFHA.3472@TK2MSFTNGXA01.phx.gbl...
> Hi Bob,
>
> Thanks for your post.
>
> Yes, I can reproduce out your problem on my side with your code snippet.
>
> If we use Reflector to view Control.Font property, we can see the root
> cause:
>
> public virtual void set_Font([MarshalAs(UnmanagedType.CustomMarshaler,
> MarshalType="", MarshalTypeRef=typeof(Control.ActiveXFontMarshaler),
> MarshalCookie="")] Font value)
> {
> Font font1 = (Font) this.Properties.GetObject(Control.PropFont);
> Font font2 = this.Font;
> bool flag1 = false;
> if (value == null)
> {
> if (font1 != null)
> {
> flag1 = true;
> }
> }
> else if (font1 == null)
> {
> flag1 = true;
> }
> else
> {
> flag1 = !value.Equals(font1);
> }
> if (flag1)
> {
> this.Properties.SetObject(Control.PropFont, value);
> if
> (this.Properties.ContainsObject(Control.PropFontHandleWrapper))
> {
> this.Properties.SetObject(Control.PropFontHandleWrapper,
> null);
> }
> if (!font2.Equals(value))
> {
> if
> (this.Properties.ContainsInteger(Control.PropFontHeight))
> {
> this.Properties.SetInteger(Control.PropFontHeight,
> (value == null) ? -1 : value.Height);
> }
> this.OnFontChanged(EventArgs.Empty);
> }
> else if (this.IsHandleCreated &&
> !this.GetStyle(ControlStyles.UserPaint))
> {
> this.SendMessage(0x30, this.FontHandle, 0);
> }
> }
> }
> Yes, in the last line, Winform code determines if UserPaint is enabled. If
> it is true, it will not send 0x30(WM_SETFONT) message to refresh the
> painting.
>
> For this issue, we can explicitly send a 0x30(WM_SETFONT) message to
> enable
> the font. Like this:
>
> [DllImport("user32.dll", CharSet=CharSet.Auto)]
> public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr
> wParam, IntPtr lParam);
>
> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
> {
> SendMessage(this.Handle, 0x30, this.Font.ToHfont(), IntPtr.Zero);
> 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);
> }
> }
> This works well on my side.
>
> Additionally, if you want to do the painting ourselves, please refer to
> the
> link below:
> "27.15 When I set a TextBox to Readonly or set Enabled to false, the text
> color is gray. How can I force it to be the color specified in the
> ForeColor property of the TextBox."
>
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c94c.aspx
>
> Hope this helps
> ================================================================
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>