Skip to main content

Posts

Showing posts from January, 2005

Rotating text

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
string s = ".net works";

e.Graphics.TranslateTransform(this.ClientSize.Width/2,this.ClientSize.Height/2);

for(int a=0;a<10;a++)
{
e.Graphics.DrawString(s,Font,Brushes.Black,50,0,StringFormat.GenericTypographic);
e.Graphics.RotateTransform(36);
}
}

In the above code the origin has been translated to the centre of the screen, and the text is rotated by 30 degrees.

Double buffering !!!

To set up automatic double buffering for a Form, you would use the following line of code in the constructor, after the InitializeComponent method call.

c#
this.SetStyle(ControlStyles.AllPaintingInWmPaint
ControlStyles.UserPaint
ControlStyles.DoubleBuffer,true);


vb
me.SetStyle(ControlStyles.AllPaintingInWmPaint OR _
ControlStyles.UserPaint OR _
ControlStyles.DoubleBuffer,true)

User interface Tips

(1) Always create a base control for all you gui widgets.
for eg.

public class UButton : System.Windows.Forms.Button
{
//........................
}

and similiarly for other controls.
This will help you maintain consistency of gui elements across all user interfaces.

(2) Create your own base form instead of using System.Windows.Forms.Form

public class UForm : System.Windows.Forms.Form
{

}
This will help you maintain consistency across all forms.

(3) And similarly for web forms and user controls.