Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #375

User Control Font Object

From "Mike Williams" <Mike@WhiskyAndCoke.com>
Newsgroups comp.lang.basic.visual.misc, microsoft.public.vb.general.discussion
Subject User Control Font Object
Date 2011-08-17 20:06 +0100
Organization A noiseless patient Spider
Message-ID <j2h6hi$smr$1@dont-email.me> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


I have been attempting to create a User Control in which I can expose a font 
object to use for various things in the Control and I've been following the 
procedure outlined at the following MSDN page:

http://msdn.microsoft.com/en-us/library/aa261313(v=vs.60).aspx

The code works in that if you drop such a User Control on a Form and select 
it you can see the Font in its Properties and you can set it fine, with the 
User Control immediately displaying the newly selected font. However, when 
you then run the program the font on the User Control reverts to its default 
setting. It is still possible to set its various font properties at runtime 
in code, but I really would like it to use the font that was set by the user 
at design time in the same way that other controls do. I'm obviously doing 
something wrong and I wonder if anyone knows how to solve this problem?

The code in my User Control is as shown below.

Mike

Option Explicit
Private WithEvents mFont As StdFont

Private Sub UserControl_Initialize()
   Set mFont = New StdFont
   Set UserControl.Font = mFont
End Sub

Public Property Get Font() As StdFont
   Set Font = mFont
End Property

Public Property Set Font(mnewFont As StdFont)
   With mFont
      .Bold = mnewFont.Bold
      .Italic = mnewFont.Italic
      .Name = mnewFont.Name
      .Size = mnewFont.Size
   End With
   PropertyChanged "Font"
End Property

Private Sub mFont_FontChanged(ByVal PropertyName As String)
   Set UserControl.Font = mFont
   Refresh
End Sub

Private Sub UserControl_Paint()
   Cls
   Print "Hello"
End Sub

Back to comp.lang.basic.visual.misc | Previous | NextNext in thread | Find similar


Thread

User Control Font Object "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-17 20:06 +0100
  Re: User Control Font Object "Nobody" <nobody@nobody.com> - 2011-08-17 16:37 -0400
    Re: User Control Font Object "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-18 00:22 +0100
  Re: User Control Font Object Karl E. Peterson <karl@exmvps.org> - 2011-08-17 13:59 -0700
    Re: User Control Font Object "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-17 22:36 +0100
      Re: User Control Font Object Karl E. Peterson <karl@exmvps.org> - 2011-08-17 15:00 -0700

csiph-web