Windows无边框表单不会更改位置

时间:2012-12-21 18:30:42

标签: c# forms flash

我有一个无边框表单,我想以编程方式更改位置。我尝试过几种不同的东西,似乎没什么用。奇怪的是,如果我进入表单的属性,手动将位置更改为100,100,将StartPosition设置为手动,它仍然从0,0开始。另一个注意事项是表单只有一个控件,它是一个Flash播放器控件。我不确定这与它有什么关系。为什么它不会移动窗户的任何问题?

1 个答案:

答案 0 :(得分:1)

通过表单的Load事件更改位置。

void Form1_Load(object sender, EventArgs e)
{
    Location = new Point(400, 600);
}

EDIT1:发布一个完整的例子,以回应作者的评论。这对我来说是正常的。

<强> Form1.cs的

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        var flash = new AxShockwaveFlash();
        Controls.Add(flash);
        FormBorderStyle = FormBorderStyle.None;
        StartPosition = FormStartPosition.Manual;
        Location = new Point(400, 600);
    }
}

<强> Form1.Designer.cs

partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (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()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this._axShockwaveFlash = new AxShockwaveFlashObjects.AxShockwaveFlash();
        ((System.ComponentModel.ISupportInitialize)(this._axShockwaveFlash)).BeginInit();
        this.SuspendLayout();
        // 
        // flash
        // 
        this._axShockwaveFlash.Enabled = true;
        this._axShockwaveFlash.Location = new System.Drawing.Point(0, 0);
        this._axShockwaveFlash.Name = "_axShockwaveFlash";
        this._axShockwaveFlash.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("flash.OcxState")));
        this._axShockwaveFlash.Size = new System.Drawing.Size(192, 192);
        this._axShockwaveFlash.TabIndex = 0;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(486, 299);
        this.Controls.Add(this._axShockwaveFlash);
        this.Name = "Form1";
        this.Text = "Form1";
        ((System.ComponentModel.ISupportInitialize)(this._axShockwaveFlash)).EndInit();
        this.ResumeLayout(false);
    }

    #endregion

    private AxShockwaveFlash _axShockwaveFlash;

}