Advertisement
Guest User

Snippet By Elektro (Subido por Ikillnukes)

a guest
Jun 29th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 3.59 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <SnippetTypes>
  6.         <SnippetType>Expansion</SnippetType>
  7.       </SnippetTypes>
  8.       <Title>
  9.          Use Custom Text-Font
  10.       </Title>
  11.       <Author>Elektro H@cker</Author>
  12.       <Description>
  13.          Utiliza una fuente de texto personalizada
  14.       </Description>
  15.       <HelpUrl>
  16.       </HelpUrl>
  17.       <Shortcut>
  18.       </Shortcut>
  19.     </Header>
  20.     <Snippet>
  21.       <Declarations>
  22.         <Literal Editable="true">
  23.           <ID>aaaaaaaaa</ID>
  24.           <ToolTip>sfsdf</ToolTip>
  25.           <Default>
  26.           </Default>
  27.           <Function>sdfsdf</Function>
  28.         </Literal>
  29.       </Declarations>
  30.       <Code Language="vb"><![CDATA[
  31.      
  32.    #Region " Use Custom Text-Font "
  33.    
  34.       ' [ Use Custom Text-Font ]
  35.       '
  36.       ' Instructions :
  37.       ' 1. Add a .TTF font to the resources
  38.       ' 2. Add the class
  39.       ' 3. Use it
  40.       '
  41.       ' Examples:
  42.       ' Label1.Font = New Font(MyFont.Font, 10.0!)
  43.       ' Label1.Text = "This is your custom font !!"
  44.    
  45.       Dim MyFont As New CustomFont(My.Resources.kakakaka)
  46.    
  47.       Private Sub Main_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
  48.           MyFont.Dispose()
  49.       End Sub
  50.    
  51.       ' CustomFont.vb
  52.    #Region " CustomFont Class "
  53.    
  54.    Imports System.Drawing
  55.    Imports System.Drawing.Text
  56.    Imports System.Runtime.InteropServices
  57.    
  58.       ''' <summary>
  59.       ''' Represents a custom font not installed on the user's system.
  60.       ''' </summary>
  61.       Public NotInheritable Class CustomFont
  62.           Implements IDisposable
  63.    
  64.           Private fontCollection As New PrivateFontCollection()
  65.           Private fontPtr As IntPtr
  66.    
  67.    #Region "Constructor"
  68.           ''' <summary>
  69.           ''' Creates a new custom font using the specified font data.
  70.           ''' </summary>
  71.           ''' <param name="fontData">The font data representing the font.</param>
  72.           Public Sub New(ByVal fontData() As Byte)
  73.               'Create a pointer to the font data and copy the
  74.               'font data into the location in memory pointed to
  75.               fontPtr = Marshal.AllocHGlobal(fontData.Length)
  76.               Marshal.Copy(fontData, 0, fontPtr, fontData.Length)
  77.    
  78.               'Add the font to the shared collection of fonts:
  79.               fontCollection.AddMemoryFont(fontPtr, fontData.Length)
  80.           End Sub
  81.    #End Region
  82.    
  83.    #Region "Destructor"
  84.           'Free the font in unmanaged memory, dispose of
  85.           'the font collection and suppress finalization
  86.           Public Sub Dispose() Implements IDisposable.Dispose
  87.               Marshal.FreeHGlobal(fontPtr)
  88.               fontCollection.Dispose()
  89.    
  90.               GC.SuppressFinalize(Me)
  91.           End Sub
  92.    
  93.           'Free the font in unmanaged memory
  94.           Protected Overrides Sub Finalize()
  95.               Marshal.FreeHGlobal(fontPtr)
  96.           End Sub
  97.    #End Region
  98.    
  99.    #Region "Properties"
  100.           ''' <summary>
  101.           ''' Gets the font family of the custom font.
  102.           ''' </summary>
  103.           Public ReadOnly Property Font() As FontFamily
  104.               Get
  105.                   Return fontCollection.Families(0)
  106.               End Get
  107.           End Property
  108.    #End Region
  109.    
  110.       End Class
  111.    
  112.    #End Region
  113.    
  114.    #End Region
  115.  
  116. ]]></Code>
  117.     </Snippet>
  118.   </CodeSnippet>
  119. </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement