在另一个面板中调整面板的大小和位置

时间:2018-12-31 14:41:07

标签: c# winforms user-controls panel

我要在另一个面板(此面板位于用户控件中)内的面板固定的位置,并且最大尺寸会随其中面板的尺寸而变化。调整大小或位置均无法正常工作。调整大小的确发生了,但很快就完成了。如果您只有1个针脚面板用于输出和输入,则该位置很好。当您的位置多于1个时,位置是固定的,但是您需要调整面板的大小以重新查看其他面板。如果看到问题,您能为我指明正确的方向吗?

在这种情况下,我有一个面板drawPanel用作用户控件的一种背景。我在此drawPanel内放置面板。我希望这些pinpanel可以通过usercontrol调整大小,并给它们固定的位置

    private void OnClickPinPanel(object source, EventArgs e)
    {
        if (source is PinPanel p)
        {
            int index;
            if ((index = Array.IndexOf(inputPins, p)) >= 0)
            {
                ClickedPinPanel?.Invoke(index, true);
            }
            else
            {
                ClickedPinPanel?.Invoke(Array.IndexOf(outputPins, p), false);
            }
        }
        //else log here
    }

    private void CreatePinPanels(bool isInput)
    {
        int x = 0;
        int y = -(int)(this.Width * 0.05)/2;

        if (isInput)
        {
            for (int i = 0; i < inputPins.Length; i++)
            {
                y += (i + 1) * (this.Height / inputPins.Length + 1);
                inputPins[i] = new PinPanel()
                {
                    Location = new Point(x, y),
                    Size = new Size((int)(this.Width * 0.05), (int)(this.Width * 0.05)),
                    Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right,
                };
                inputPins[i].Click += OnClickPinPanel;
            }
        }
        else
        {
            x += this.Width - (int)(this.Width * 0.1);
            for (int i = 0; i < outputPins.Length; i++)
            {
                y += (i + 1) * (this.Height / inputPins.Length+1);
                outputPins[i] = new PinPanel()
                {
                    Size = new Size((int)(this.Width * 0.1), (int)(this.Width * 0.1)),
                    Location = new Point(x, y),
                    Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right
                };
                outputPins[i].Click += OnClickPinPanel;
            }
        }
    }

我现在得到的结果是,小键盘具有固定的位置,但是当您有1个以上的小键盘时,该位置是错误的,就像他认为用户控件更大,则是Reality。为了查看所有引脚,我必须调整大小并获得此After resize

我希望它看起来像这样 expectations

1 个答案:

答案 0 :(得分:0)

尝试这样的事情。

这是我的测试装备:

import {forkJoin} from 'rxjs';
import {map} from 'rxjs/operators';
forkJoin([this.statesService.getStates(), this.countyService.getCounties(), this.zoneService.GetZoneDetails(this.prodPointId)])
    .subscribe(res => {
        // res[0] would be the result of getStates
        // res[1] would be the result of getCounties
})

具有5个输入和3个输出的采样芯片:

enter image description here

这是我的PinPanel UserControl(仅绘制椭圆/固定控件的大小):

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        numericUpDown1.Value = someChip1.NumberInputPins;
        numericUpDown2.Value = someChip1.NumberOutputPins;
    }

    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
        someChip1.NumberInputPins = (int)numericUpDown1.Value;
    }

    private void numericUpDown2_ValueChanged(object sender, EventArgs e)
    {
        someChip1.NumberOutputPins = (int)numericUpDown2.Value;
    }

}

最后,我的SomeChip UserControl:

public partial class PinPanel : UserControl
{

    public PinPanel()
    {
        InitializeComponent();
    }

    private void PinPanel_Paint(object sender, PaintEventArgs e)
    {
        Rectangle rc = new Rectangle(new Point(0, 0), new Size(this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1));
        e.Graphics.DrawEllipse(Pens.Black, rc);
    }

    private void PinPanel_SizeChanged(object sender, EventArgs e)
    {
        this.Refresh();
    }

}
相关问题