我有一个无边界表单,我想以编程方式更改其位置。我尝试了几种不同的方法,但似乎没有任何效果。奇怪的是,如果我进入表单的属性,手动将位置更改为 100,100,将其设置StartPosition
为手动,它仍然从 0,0 开始。另一个注意事项是表单只有一个控件,它是一个 Flash 播放器控件。我不确定这是否与它有关。关于为什么它不会移动窗口的任何想法?
问问题
287 次
1 回答
1
Load
通过Form的事件改变位置。
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;
}
于 2012-12-21T18:32:22.640 回答