Вот держи кусок рабочей проги (делает как раз то, что тебе нужно):
| Код |
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; using Microsoft.DirectX; using Microsoft.DirectX.DirectDraw;
namespace TestDirectDraw { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.IContainer components; private System.Windows.Forms.ImageList imageList1; private System.Threading.Thread DrawThread; private bool m_Terminated;
public Form1() { // // Required for Windows Form Designer support // InitializeComponent();
// // TODO: Add any constructor code after InitializeComponent call // }
/// <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() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.imageList1 = new System.Windows.Forms.ImageList(this.components); // // imageList1 // this.imageList1.ImageSize = new System.Drawing.Size(128, 128); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(640, 510); this.Name = "Form1"; this.Text = "Form1"; this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); this.Load += new System.EventHandler(this.Form1_Load);
} #endregion
/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }
private void Form1_Load(object sender, System.EventArgs e) { m_Terminated = false; DrawThread = new Thread(new ThreadStart(DrawBoxThreadBody)); DrawThread.Start(); } void DrawBoxThreadBody() { Device DirectDraw = new Device(CreateFlags.HardwareOnly); const string Text = "Текущее время 89:78"; if (DirectDraw != null) { DirectDraw.SetCooperativeLevel(this, CooperativeLevelFlags.Normal); SurfaceCaps SurfaceCapabilities = new SurfaceCaps(); SurfaceCapabilities.PrimarySurface = true; SurfaceDescription Description = new SurfaceDescription(SurfaceCapabilities); Surface PrimaryBuffer = new Surface(Description, DirectDraw); PrimaryBuffer.Clipper = new Clipper(DirectDraw); PrimaryBuffer.FillColor = System.Drawing.Color.Black; System.IntPtr PrimaryDC = PrimaryBuffer.GetDc(); System.Drawing.Graphics gr = System.Drawing.Graphics.FromHdc(PrimaryDC);
int i = 24; System.Drawing.Font TextFont = new Font("Comic Sans MS", i); System.Drawing.SizeF TextSize = gr.MeasureString(Text, TextFont); while (TextSize.Width < DirectDraw.DisplayMode.Width) { TextFont = new Font("Comic Sans MS", i); TextSize = gr.MeasureString(Text, TextFont); i++; TextFont.Dispose(); } TextFont = new Font("Comic Sans MS", i - 2);
while (!m_Terminated) { gr.DrawString(Text, TextFont, Brushes.DarkGoldenrod, 0, 0); Thread.Sleep(10); } TextFont.Dispose(); PrimaryBuffer.Dispose(); DirectDraw.Dispose(); } }
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { m_Terminated = true; DrawThread.Join(); } } }
|
Тока в референсы не забудь добавить сборки для Managed DirectX. |