English 中文(简体)
c#显示中心的形式
原标题:Displaying the form in center in c#
  • 时间:2011-05-18 04:43:15
  •  标签:
  • c#

i 在这里是新的,实际上,我正在着手进行正处在正文的项目,而在该项目中,我想要在屏幕中心展示我的形式。 因此,我撰写了以下法典。

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:UserslogicwavesDocumentsVisual Studio 2005ProjectscentercenterForm1.Designer.cs 14 33 center

2)不可逆转2方案 C:UserslogicwavesDocumentsVisualroom 2005 ProjectscentercenterobjDebugcenter.exe 有一个以上的切入点:中心。 Program.Main() C:UserslogicwavesDocumentsVisualroom 2005 Projectscentercenter Programram.cs 13 21 Centre

3) 不可逆转方案 C:UserslogicwavesDocumentsVisualroom 2005 ProjectscentercenterobjDebugcenter.exe 有一个以上入境点:Main()中心 C:UserslogicwavesDocumentsVisualroom 2005 ProjectscentercenterForm1.cs 58 17 Center

应当做些什么来克服这些错误?

最佳回答

不需要<代码>CenterForm.StartPosition = FormStartPosition.CenterScreen;。

问题回答

错误是因为你在表格c中界定了<代码>Main(方法”。 通常,如果是使用视觉演播室,则会进入节目组。 您可以确定StartPosition property to FormStartPosition.CenterScreen,从而将屏幕的形式中心建成。

引证:

>>>。

this.CenterToScreen();




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签