Advertisement
7_2009-2012 Files/ File Controls/ Input/ Output #222803

Changing Object Fonts In Code @ RunTime

This little tutorial shows how to change the font on controls at runtime. Easy to do in the IDE, but, to do it in code at runtime in .NET (compared to VB6) it is a bit different!

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
<br><br>The reason for this tutorial:<br><br>Feeling like a newbie again after 5 years with VB, .NET poses some obsticals that I certainly was not prepared for.<br>Changing a font size was quick and easy in VB6, but in the .NET world, it proved itself to be a tedious task. My example is shown below:<br><br>
I have a solution with a blank form, and at runtime, all controls are dynamically built from a text file and placed in the window.<br><br>
The problem is that with .NET, all controls like this default to the form's font settings - And MS made the Font property of labels, etc. READ-ONLY.?<br><br>
In order to accomplish this, you need to create a new font object with your values, and assign it to your (Control).Font property.<br><br>
This will allow you to change the Font Family, the size in points, and the Bold / Italic etc. properties as well.<br>
<br>
<u>As an example, we are defining label "Label1" the Font Family "Arial", 8.25 Points in size, and BOLD.</u><br>
<b>Label1.Font = New Font("Arial", 8.25, FontStyle.Bold, GraphicsUnit.Point, 0, False)</b><br><br>
<br><u>You could also express it as:</u><br>
<b>Dim MyFont as New Font("Arial", 8.25, FontStyle.Bold, GraphicsUnit.Point, 0, False)
<br><br>
Label1.Font = MyFont<br><br>
Label2.Font = MyFont</b><br><br>
I hope this helps someone, as I was scratchin' hair out of my head over this. I 
knew it could be done.<br><br> Funny thing is, it actually was pretty simple! <i>Heh</i>.<br><br>
John.

Upload
function Redirect_Function($Page)//Function to redirect the page into destination one due to its parameter
  {
   global $HTTP_SERVER_VARS;
   $Path = "http://".$HTTP_SERVER_VARS['HTTP_HOST'].dirname($HTTP_SERVER_VARS['PHP_SELF'])."/".$Page;
   echo"<script>window.location=\"$Path\"</script>";
  }
Original Comments (3)
Recovered from Wayback Machine