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


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

Re: User Control Font Object

From Karl E. Peterson <karl@exmvps.org>
Newsgroups comp.lang.basic.visual.misc, microsoft.public.vb.general.discussion
Subject Re: User Control Font Object
Date 2011-08-17 13:59 -0700
Organization exMVPs.org
Message-ID <j2ha3l$kul$1@dont-email.me> (permalink)
References <j2h6hi$smr$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


Mike Williams brought next idea :
> 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?

As Nobody suggested, you need to persist the design-time choice.  
Something like this, maybe...

   Private m_Font As StdFont

   Private Sub UserControl_InitProperties()
      Set Me.Font = Ambient.Font
   End Sub

   Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
      Set Me.Font = PropBag.ReadProperty("Font", Ambient.Font)
   End Sub

   Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
      Call PropBag.WriteProperty("Font", m_Font, Ambient.Font)
   End Sub

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

   Public Property Set Font(ByVal New_Font As StdFont)
      Set m_Font = New_Font
      Set UserControl.Font = m_Font
      PropertyChanged "Font"
   End Property

-- 
.NET: It's About Trust!
http://vfred.mvps.org

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next 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