techpreparation-homepage

Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog


Technical Interview Questions

Visual Basic Interview Question
ASP .NET Interview Questions
C++ Interview Questions
C Interview Questions
                              .........More

Programming Source Codes
C/C++ Source Codes
C# Source Codes
                              .........More

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions
                              .........More

Tutorials
C Tutorial
C++ Tutorial
                              .........More

Soft Skills
Communication Skills
Leadership Skills
                              .........More

 

 

  

C# Source Codes

marquee text

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Text;

namespace MovingText
{
public class TextMoverForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label;
private System.Windows.Forms.Button button1;
private Thread thread;
public TextMoverForm()
{
InitializeComponent();
thread = new Thread( new ThreadStart( DrawMovingText ) );
}
private void InitializeComponent()
{
this.label = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.label.Location = new System.Drawing.Point(0, 0);
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(325, 16);
this.label.TabIndex = 0;
this.label.Text = "Click Anywhere Or Resize the Form to Restart The Moving Text";
this.label.Click += new System.EventHandler(this.label_Click);
this.button1.Location = new System.Drawing.Point(192, 352);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Close Window";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(492, 466);
this.Controls.Add(this.button1);
this.Controls.Add(this.label);
this.Name = "TextMoverForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Moving Text";
this.Resize += new System.EventHandler(this.Form_Resize);
this.Load += new System.EventHandler(this.Form_Load);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form_MouseUp);
this.ResumeLayout(false);

}
static void Main()
{
Application.Run( new TextMoverForm() );
}

private void Form_Load( object sender, System.EventArgs e )
{
StartThread();
}
private void Form_MouseUp( object sender, System.Windows.Forms.MouseEventArgs e )
{
StartThread();
}
private void Form_Resize( object sender, System.EventArgs e )
{
StartThread();
}
private void label_Click( object sender, System.EventArgs e )
{
StartThread();
}
private void StartThread()
{
thread.Abort();
Thread.Sleep( 100 );
Invalidate();
thread = new Thread( new ThreadStart( DrawMovingText ) );
thread.Start();
}

private void DrawMovingText()
{
Graphics grfx = CreateGraphics();
Font font = new Font( "Courier New", 20, FontStyle.Bold );
string spaces = " ";
StringBuilder str = new StringBuilder( "hello friend how r u............." + spaces );

Rectangle rect = CreateRect( grfx, str, font );

int numCycles = str.Length * 3 + 1;
for( int i = 0; i < numCycles; ++i )
{
grfx.FillRectangle( Brushes.White, rect );
grfx.DrawString( str.ToString(), font, Brushes.Red, rect );
str.Append( str[0] );
str.Remove( 0, 1 );
Thread.Sleep( 150 );
}
grfx.Dispose();
}

private Rectangle CreateRect( Graphics grfx, StringBuilder str, Font font )
{
int w = (int)grfx.MeasureString( str.ToString(), font ).Width + 5;
int h = (int)grfx.MeasureString( str.ToString(), font ).Height;
int x = (int)this.Width / 2 - w / 2;
int y = (int)this.Height / 2 - h;
return new Rectangle( x, y, w, h );
}

private void button1_Click(object sender, System.EventArgs e)
{
Close();
}
}
}


<<<----- Return to C# Source Code Questions Page.

Have a Question ? post your questions here. It will be answered as soon as possible.

Check Object Oriented Interview Questions for more Object Oriented Interview Questions with answers

Check Data Structure Interview Questions for more data structure interview questions with answers