søndag 26. april 2009

Test Drawing Text from file

<--------------------------->
this code gets a text form a file on c:\ then draws it on the form
<--------------------------->

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace test_drawing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string teXt;
private void timer1_Tick(object sender, EventArgs e)
{
string file_name = "c:\\test.txt";
if (System.IO.File.Exists(file_name) == true)
{
System.IO.StreamReader objReader;
objReader = new System.IO.StreamReader(file_name);
//textBox1.Text = objReader.ReadToEnd();
teXt = objReader.ReadToEnd();
objReader.Close();
}
else
{
MessageBox.Show("ingen slik fil" + file_name);
}
}
public void Form1_Load(object sender, EventArgs e)
{
//string file_name = "c:\\test.txt";
//if (System.IO.File.Exists(file_name) == true)
//{
// System.IO.StreamReader objReader;
// objReader = new System.IO.StreamReader(file_name);
// //textBox1.Text = objReader.ReadToEnd();
// teXt = objReader.ReadToEnd();
// objReader.Close();
//}
//else
//{
// MessageBox.Show("ingen slik fil" + file_name);
//}
}
public void Form1_Paint(object sender, PaintEventArgs e)
{
//Graphics surface;
Graphics surface = this.CreateGraphics();
Font drawFont = new Font("Arial", 20);
SolidBrush drawBrush = new SolidBrush(Color.Black);
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
surface.DrawString(teXt , drawFont, drawBrush, 220.0f, 50.0f, drawFormat);
}

}
}

Ingen kommentarer:

Legg inn en kommentar