[英]c# winform Resizing button on different form
I want to resize my button on form2
using the button on form1
. 我想使用
form1
上的按钮来调整form2
的按钮的大小。
This is my code and it gives me error: 这是我的代码,它给我错误:
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);
}
It has an error at Form2.button8.Size
.. I made my button8
Public so it can be accessed.. but still it gives me error "Form2.button8 is inaccessible because of its protection level" .. 它在
Form2.button8.Size
处出现错误。.我将我的button8
公开,因此可以对其进行访问..但仍然给我错误“ Form2.button8由于其保护级别而无法访问” ..
this is my button8 at form2 这是我在form2上的button8
public void button8_Click(object sender, EventArgs e) { } public void button8_Click(对象发送者,EventArgs e){}
How can I solve this issue? 我该如何解决这个问题?
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));
}
}
}
I made button1 on the form2.designer.cs internal. 我在form2.designer.cs内部创建了button1。
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.