我有两种形式(“Startfenster”和form1)。第一个Startfenster打开,我可以写两个变量(“Rohrdurchmesser”和“Messlanzen”),我发送Form1。表格1有2个图片框和5个按钮。图片盒的大小应该取决于可变的“Rohrdurchmesser”,但第二种形式(form1)的大小和最小尺寸也应该依赖于“Rohrdurchmesser”,这不起作用......这是我的一部分代码...
public partial class Form1 : Form
{
Startfenster fh;
int Rohrdurchmesser, Messlanzen;
...
Bitmap bmp;
Graphics z;
public Form1(Startfenster aufrufer) // Startfenster was the first Form, which opens first when you start the program
{
fh = aufrufer;
InitializeComponent();
Anordnen();
bmp = new Bitmap(pic1.ClientSize.Width, pic1.ClientSize.Height);
z = Graphics.FromImage(bmp);
Startfenster.ActiveForm.Hide();
}
private void Form1_Load(object sender, EventArgs e)
{
Rohrdurchmesser = Convert.ToInt32(fh.Controls["txbRohrdurchmesser"].Text);
Messlanzen = Convert.ToInt32(fh.Controls["txbMesslanzen"].Text);
pic1.Height = Convert.ToInt32(PixelToCm(Rohrdurchmesser)) * Rohrdurchmesser;
pic1.Width = pic1.Height;
pic2.Height = Convert.ToInt32(PixelToCm(Rohrdurchmesser)) * Rohrdurchmesser;
pic2.Width = pic2.Height;
Form1.ActiveForm.Size = new Size(2 * pic1.Width + 40, pic1.Height + 60); // doesn't work! why?
Form1.ActiveForm.MinimumSize = new Size(2 * pic1.Width + 40, pic1.Height + 60);// doesn't work! why?
}
private void Anordnen()
{
pic1.Width = this.ClientSize.Width / 2 - 30;
pic2.Width = this.ClientSize.Width / 2 - 30;
pic2.Left = pic1.Right + 20;
btnVergleichen.Left = pic1.Right + 10 - btnVergleichen.Width / 2;
btnEinlesen1.Left = pic1.Left + pic1.Width / 2 - btnEinlesen1.Width / 2;
btnBewerten1.Left = pic1.Left + pic1.Width / 2 - btnBewerten1.Width / 2;
btnEinlesen2.Left = pic2.Left + pic2.Width / 2 - btnEinlesen2.Width / 2;
btnBewerten2.Left = pic2.Left + pic2.Width / 2 - btnBewerten2.Width / 2;
}
double PixelToCm(double Pixel)
{
double cm = -1;
using (Graphics g = this.CreateGraphics())
{
cm = (Pixel / g.DpiY) * 2.5399999d;
}
return (double)cm;
}
答案 0 :(得分:0)
你的意思是什么'不工作' ?
Form1.ActiveForm.Size = new Size(2 * pic1.Width + 40, pic1.Height + 60); // doesn't work! why?
Form1.ActiveForm.MinimumSize = new Size(2 * pic1.Width + 40, pic1.Height + 60);// doesn't work! why?
不应该
this..ActiveForm.Size = new Size(2 * pic1.Width + 40, pic1.Height + 60);
this.ActiveForm.MinimumSize = new Size(2 * pic1.Width + 40, pic1.Height + 60);
或一些真实的表格参考,而不是类名?