[PopUp menu] setting the current System Font

  • Thread starter Thread starter teo
  • Start date Start date
T

teo

hallo,

for a pop-up menu (it's a 'ContextMenuStrip' control)
I 'd like to set the current System font

Currently the ContextMenuStrip has the MS San Sarif font and the 8,25 size
but
I'd like it to assume the current System font
(that obviously it isn't MS San Sarif) and the current System font Size

note:
if it was a color I know that we have the so called "KnownColor" group
that represent the current System color, but for the font?
 
hallo,

for a pop-up menu (it's a 'ContextMenuStrip' control)
I 'd like to set the current System font

Currently the ContextMenuStrip has the MS San Sarif font and the 8,25 size
but
I'd like it to assume the current System font
(that obviously it isn't MS San Sarif) and the current System font Size

note:
if it was a color I know that we have the so called "KnownColor" group
that represent the current System color, but for the font?

If I'm not mistaken, doesn't .Net 2.0 have a SystemFonts class?

Thanks,

Seth Rowe
 
If I'm not mistaken, doesn't .Net 2.0 have a SystemFonts class?

Good, but...
because I have a Theme (and many users have) it doesn't work, indeed.

I tried with a testing Theme, all with 'Comic Sans' font
(Active bar, Inactive bar, 3D object, Messages, Menu, Icons...)

then I used this:

Dim myFont As New Font(SystemFonts.MenuFont.FontFamily.Name,
SystemFonts.MenuFont.Size)
ContextMenuStrip1.Font = myFont

and unfortunately ContextMenuStrip1 nevere appeared with the 'Comic Sans'
 
Good, but...
because I have a Theme (and many users have) it doesn't work, indeed.

I tried with a testing Theme, all with 'Comic Sans' font
(Active bar, Inactive bar, 3D object, Messages, Menu, Icons...)

then I used this:

Dim myFont As New Font(SystemFonts.MenuFont.FontFamily.Name,
SystemFonts.MenuFont.Size)
ContextMenuStrip1.Font = myFont

and unfortunately ContextMenuStrip1 nevere appeared with the 'Comic Sans'

Hmm... I don't know what to tell you. The font information has to be
stored someplace (perhaps the registry?) but as to where I am not
sure. You might browse the API documentation to see if you can find
any about user preferences - perhaps you'll find a p/invoke way of
retrieving the font.

Thanks,

Seth Rowe
 
Hmm... I don't know what to tell you. The font information has to be
stored someplace (perhaps the registry?) but as to where I am not
sure. You might browse the API documentation to see if you can find
any about user preferences - perhaps you'll find a p/invoke way of
retrieving the font.

Another question, if you have time.

In your opinion a new Declared Font, has to be 'disposed' ?

I declared it and set it to the ContextMenuStrip control
in the Load event and I never disposed it.

To optimize memory, when should I have to declare it
and when dispose it.

Maybe I should have to declare it just a row
before using the
ContextMenuStrip.Show()
row,
but when to dispose it?
 
Yes. The documentation on the Font Class clearly states that explicit
disposal is required.

However, if you inspect the 'generated' code for the form you not find an
explicit dispose for the font object that is assigned to the
ConTextMenu1.Font property in the InitializeComponent method. Therefore the
disposal of that Font object must be implicit in the disposal of the
ContextMenu1 object which, in turn, is implicit on the closing of the form.

Therefore I would not worry about disposing of the Font object, BUT, I would
assign it directly to the Font property of the ContextMenu1 object in the
Load event handler for the form, thus:

Private Sub Form_Load(...) Handles Me.Load

ContextMenuStrip1.Font = New Font(SystemFonts.MenuFont.FontFamily,
SystemFonts.MenuFont.Size)

End Sub
 
Back
Top