Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.visual.misc > #377
| From | "Nobody" <nobody@nobody.com> |
|---|---|
| Newsgroups | comp.lang.basic.visual.misc, microsoft.public.vb.general.discussion |
| Subject | Re: User Control Font Object |
| Date | 2011-08-17 16:37 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <j2h8q7$i6v$1@speranza.aioe.org> (permalink) |
| References | <j2h6hi$smr$1@dont-email.me> |
Cross-posted to 2 groups.
"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:j2h6hi$smr$1@dont-email.me...
>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.
You need to supply these events:
UserControl_InitProperties
UserControl_ReadProperties
UserControl_WriteProperties
There is an easy way to do that without writing code. Use "VB6 ActiveX Ctrl
Interface Wizard" Add-in, which generates the code for you and without
deleting your UserControl code. Just start the Wizard, and click Next(You
can keep clicking on Next till the end if you wish). If you don't like what
it generated, and want to try again, just press Ctrl+Z several times. It
adds the most common properties and methods for you so you don't have to add
them one by one. The right list includes the properties and methods that you
want to add. Add or remove what you want. By default "Font" property is
included. In "Set Mapping" stage, you can map some of these properties and
method to a control inside the UserControl. For example, if you have added a
Label control inside the UserControl, you can tell the wizard to map the
UserControl BackColor to the Label's BackColor, and it will generate the
necessary code. By default it maps to the UserControl properties, so you
don't have to select anything. You can run the wizard again and add more
properties later if you want. Here is what it generates if I just select the
Font property:
Option Explicit
'Property Variables:
Dim m_Font As Font
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=6,0,0,0
Public Property Get Font() As Font
Set Font = m_Font
End Property
Public Property Set Font(ByVal New_Font As Font)
Set m_Font = New_Font
PropertyChanged "Font"
End Property
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
Set m_Font = Ambient.Font
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Set m_Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Font", m_Font, Ambient.Font)
End Sub
Back to comp.lang.basic.visual.misc | Previous | Next — Previous in thread | Next in thread | Find similar
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