Just nu i M3-nätverket
Gå till innehåll

Fonter C#


Leon Radley

Rekommendera Poster

Jag försöker skriva ett program som listar upp alla fonter som finns installerade på datorn,

jag har lyckats få det att fungera men nu skulle jag vilja skriva ut fonterna i fontens utseende också.

så här ser koden ut. ge gärna tips om hemsidor med tutorials och så vidare.

 

FontFamily fontFamily = new FontFamily("Verdana");

Font font = new Font(

fontFamily,

8,

FontStyle.Regular,

GraphicsUnit.Point);

SolidBrush solidBrush = new SolidBrush(Color.Black);

 

FontFamily[] fontFamilies;

 

InstalledFontCollection installedFontCollection = new InstalledFontCollection();

 

// Get the array of FontFamily objects.

fontFamilies = installedFontCollection.Families;

 

int count = fontFamilies.Length;

for(int j = 0; j < count; ++j)

{

listView1.Items.Add(fontFamilies[j].Name);

}

Länk till kommentar
Dela på andra webbplatser

Hmm, jag hittar inte frågan i tråden...

Vill du använda fonter i controls, så har de flesta en egenskap Font som du kan sätta till fonten du vill använda.

Vill du rita på med GDI+ drawstring, så tar även den Font som argument.

Borde bara vara atttuta och köra ;)

 

Länk till kommentar
Dela på andra webbplatser

Det är så att jag vet inte hur man gör det? det här är mitt första c# program... eller rättare sagt mitt första program. Är helt grön på ämnet.

 

skulle du kunna visa hur du menade Junk Junk?

 

Länk till kommentar
Dela på andra webbplatser

Här kommer ett exempel på hur du använder fonter i forms i C#. (Eforum dödar min intendering. Hoppas det går att läsa ändå.)

-----Snipp----

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

 

namespace WindowsApplication1

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.ListView listView1;

private System.Windows.Forms.ColumnHeader columnHeader1;

private System.Windows.Forms.Panel panel1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

 

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

 

 

}

 

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

 

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {

new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "Verdana", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))))}, -1);

System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {

new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "Courier New", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))))}, -1);

this.listView1 = new System.Windows.Forms.ListView();

this.columnHeader1 = new System.Windows.Forms.ColumnHeader();

this.panel1 = new System.Windows.Forms.Panel();

this.SuspendLayout();

//

// listView1

//

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {

this.columnHeader1});

this.listView1.Dock = System.Windows.Forms.DockStyle.Top;

this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {

listViewItem1,

listViewItem2});

this.listView1.Name = "listView1";

this.listView1.Size = new System.Drawing.Size(368, 56);

this.listView1.TabIndex = 0;

this.listView1.View = System.Windows.Forms.View.Details;

//

// columnHeader1

//

this.columnHeader1.Width = 226;

//

// panel1

//

this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;

this.panel1.Location = new System.Drawing.Point(0, 56);

this.panel1.Name = "panel1";

this.panel1.Size = new System.Drawing.Size(368, 245);

this.panel1.TabIndex = 1;

this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(368, 301);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.panel1,

this.listView1});

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

 

}

#endregion

 

/// <summary>

/// The main entry point for the application.

/// </summary>

[sTAThread]

static void Main()

{

Application.Run(new Form1());

}

 

private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

{

// Draw on panel using GDI+

Graphics g = this.panel1.CreateGraphics();

g.DrawString(

"Verdana",

new Font("Verdana", 14.0f),

new SolidBrush(Color.Black),

new PointF(10.0f, 10.0f));

}

 

 

}

}

----End snipp---

Lycka till. ;)

 

[inlägget ändrat 2002-10-17 16:51:43 av Junk Junk]

Länk till kommentar
Dela på andra webbplatser

Arkiverat

Det här ämnet är nu arkiverat och är stängt för ytterligare svar.

×
×
  • Skapa nytt...