Windows无边框窗体不能更改位置

本文关键字:位置 不能 窗体 边框 Windows | 更新日期: 2023-09-27 17:49:25

我有一个无边界的形式,我想改变编程的位置。我尝试了几种不同的方法,但似乎都不起作用。奇怪的是,如果我进入表单的属性,手动将位置更改为100,100,将StartPosition设置为手动,它仍然从0,0开始。另一个注意事项是,表单只有一个控件,它是一个Flash播放器控件。我不确定这是否与此有关。你知道为什么窗户不动吗?

Windows无边框窗体不能更改位置

通过表单的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;
}