不同窗体上的c#winform大小调整按钮

不同窗体上的c#winform大小调整按钮,c#,winforms,button,C#,Winforms,Button,我想使用form1上的按钮调整form2上的按钮大小 这是我的代码,它给了我错误: public void button7_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); int x = Convert.ToInt32(textBox7.Text); int y = Convert.ToInt32(textBox8.Text); f2.button8.Size = new System.Dra

我想使用
form1
上的按钮调整
form2
上的按钮大小

这是我的代码,它给了我错误:

public void button7_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    int x = Convert.ToInt32(textBox7.Text);
    int y = Convert.ToInt32(textBox8.Text);
    f2.button8.Size = new System.Drawing.Size(x, y);
}
它在
Form2.button8.Size
处出错。。我将我的
按钮8
公开,以便可以访问。。 但它仍然给我错误“Form2.button8由于其保护级别而无法访问”

这是我在form2的按钮

公共无效按钮8_单击(对象发送者,事件参数e) { }

我如何解决这个问题

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
    Form2 f2 = new Form2();

    public Form1()
    {
        InitializeComponent();
        f2.Show();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        f2.button1.Size = new Size(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
    }
}
}
我在form2.designer.cs内部制作了按钮1

namespace WindowsFormsApplication2
{
    partial class Form2
    {
        /// <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()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(95, 89);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "buttonForm2";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.button1);
            this.Name = "Form2";
            this.Text = "Form2";
            this.ResumeLayout(false);

        }

        #endregion

    //This is where you change from private to internal
        internal System.Windows.Forms.Button button1;
    }
}
命名空间窗口窗体应用程序2
{
部分类别表格2
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
this.button1=new System.Windows.Forms.Button();
这个.SuspendLayout();
// 
//按钮1
// 
this.button1.Location=新系统图纸点(95,89);
this.button1.Name=“button1”;
this.button1.Size=新系统图纸尺寸(75,23);
this.button1.TabIndex=0;
this.button1.Text=“buttonForm2”;
this.button1.UseVisualStyleBackColor=true;
// 
//表格2
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(284262);
this.Controls.Add(this.button1);
this.Name=“Form2”;
this.Text=“Form2”;
此选项为.resume布局(false);
}
#端区
//这是您从私有变为内部的地方
内部System.Windows.Forms.Button按钮1;
}
}
我在form2.designer.cs内部制作了按钮1

namespace WindowsFormsApplication2
{
    partial class Form2
    {
        /// <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()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(95, 89);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "buttonForm2";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.button1);
            this.Name = "Form2";
            this.Text = "Form2";
            this.ResumeLayout(false);

        }

        #endregion

    //This is where you change from private to internal
        internal System.Windows.Forms.Button button1;
    }
}
命名空间窗口窗体应用程序2
{
部分类别表格2
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
this.button1=new System.Windows.Forms.Button();
这个.SuspendLayout();
// 
//按钮1
// 
this.button1.Location=新系统图纸点(95,89);
this.button1.Name=“button1”;
this.button1.Size=新系统图纸尺寸(75,23);
this.button1.TabIndex=0;
this.button1.Text=“buttonForm2”;
this.button1.UseVisualStyleBackColor=true;
// 
//表格2
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(284262);
this.Controls.Add(this.button1);
this.Name=“Form2”;
this.Text=“Form2”;
此选项为.resume布局(false);
}
#端区
//这是您从私有变为内部的地方
内部System.Windows.Forms.Button按钮1;
}
}

try
form2f2=newform2();f2.按钮8….
该按钮解决了第二个错误。。但由于其防护等级,仍然无法进入。你的Form2等级防护等级是什么?名称空间定义是否正确?当您调用Form2 with object时,更改按钮int x=Convert.ToInt32(textBox7.Text)的大小;int y=转换为32(textBox8.Text);Form2 frm=新Form2();frm.button8.Size=新系统图纸尺寸(x,y);这是我在form2的按钮。。公共作废按钮8_单击(对象发送者,事件参数e)尝试
Form2 f2=new Form2();f2.按钮8….
该按钮解决了第二个错误。。但由于其防护等级,仍然无法进入。你的Form2等级防护等级是什么?名称空间定义是否正确?当您调用Form2 with object时,更改按钮int x=Convert.ToInt32(textBox7.Text)的大小;int y=转换为32(textBox8.Text);Form2 frm=新Form2();frm.button8.Size=新系统图纸尺寸(x,y);这是我在form2的按钮。。public void button 8_单击(对象发送者,事件参数e)进入form2.designer.cs并将按钮从private更改为internal或public。处理者可以保持隐私,也应该保持隐私。我只是这么做了,而且成功了。如果需要,可以提供完整的示例转到form2.designer.cs,并将按钮从private更改为internal或public。处理者可以保持隐私,也应该保持隐私。我只是这么做了,而且成功了。如果需要,可以提供完整的示例