i am new here, actually i am working on project which is in c#, and in that project i want to display my form in the center of the screen… So for that i have written the following code..
public class CenterForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components;
public CenterForm()
{
InitializeComponent();
CenterToScreen();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(107, 177);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Ok";
this.button1.UseVisualStyleBackColor = true;
//
// CenterForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "CenterForm";
this.Text = "DataGridExample";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.CenterForm_Paint);
this.Resize += new System.EventHandler(this.CenterForm_Resize);
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new CenterForm());
}
private void CenterForm_Resize(object sender, System.EventArgs e)
{
Invalidate();
Console.WriteLine("Resize");
}
private void CenterForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("Text",
new Font("Times New Roman", 20),
new SolidBrush(Color.Black),
this.DisplayRectangle);
}
private Button button1;
}
but it is giving some errors,that are
1)Error 1 ‘center.Form1.Dispose(bool)’: no suitable method found to override C:\Users\logicwaves\Documents\Visual Studio 2005\Projects\center\center\Form1.Designer.cs 14 33 center
2)Error 2 Program ‘C:\Users\logicwaves\Documents\Visual Studio 2005\Projects\center\center\obj\Debug\center.exe’ has more than one entry point defined: ‘center.Program.Main()’ C:\Users\logicwaves\Documents\Visual Studio 2005\Projects\center\center\Program.cs 13 21 center
3)Error 3 Program ‘C:\Users\logicwaves\Documents\Visual Studio 2005\Projects\center\center\obj\Debug\center.exe’ has more than one entry point defined: ‘CenterForm.Main()’ C:\Users\logicwaves\Documents\Visual Studio 2005\Projects\center\center\Form1.cs 58 17 center
what should i do, to overcome from these errors?
no need for that
CenterForm.StartPosition = FormStartPosition.CenterScreen;