假如:Form1为主窗体,Form2为子窗体.Form1中(this.IsMdiContainer = true;):
private void Form1_Load(object sender, EventArgs e)
{
this.RightToLeft = RightToLeft.Yes;
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.MdiParent = this;
form.Show();
}private void Form2_Load(object sender, EventArgs e)
{
MessageBox.Show(this.RightToLeft.ToString());
}
这样是没有问题的.子窗体可以继承到主窗体的RightToLeft属性.但是:如果不用MdiParent方式 ( form1.IsMdiContainer = fase;);
直接用Show()或者ShowDialog()方式打开子窗体:
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.Show();
//或者用form.ShowDialog()
}
这个时候不能继承到父窗体属性.
请问,在这样的情况下有哪些解决方法可以选择呢?
因为项目中这样的问题太多了,所以我更希望找到一种通用的/或者说一劳永逸的解决办法.
private void Form1_Load(object sender, EventArgs e)
{
this.RightToLeft = RightToLeft.Yes;
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.MdiParent = this;
form.Show();
}private void Form2_Load(object sender, EventArgs e)
{
MessageBox.Show(this.RightToLeft.ToString());
}
这样是没有问题的.子窗体可以继承到主窗体的RightToLeft属性.但是:如果不用MdiParent方式 ( form1.IsMdiContainer = fase;);
直接用Show()或者ShowDialog()方式打开子窗体:
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.Show();
//或者用form.ShowDialog()
}
这个时候不能继承到父窗体属性.
请问,在这样的情况下有哪些解决方法可以选择呢?
因为项目中这样的问题太多了,所以我更希望找到一种通用的/或者说一劳永逸的解决办法.
然后Form1:Form3,Form2:Form3
Form2 form = new Form2();
form.RightToLeft=this.RightToLeft;
form.Show();
//Code from Form1
public Form1()
{
InitializeComponent();
}/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(193, 178);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(510, 264);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); //
this.RightToLeft = System.Windows.Forms.RightToLeft.No; }
{
public Form2()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
MessageBox.Show(this.RightToLeft.ToString());
}
}
this.RightToLeft = RightToLeft.Yes; 放在构造函数中执行