Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在windowsform c#面板的自定义位置添加按钮_C#_Button_Layout - Fatal编程技术网

在windowsform c#面板的自定义位置添加按钮

在windowsform c#面板的自定义位置添加按钮,c#,button,layout,C#,Button,Layout,我已经试了几个小时了,但没能让它工作,我必须用c#中的面板和按钮实现一个二元搜索树。到目前为止,我所做的是从文本区域获取输入,并制作一个带有文本值的按钮,现在我必须以层次方式显示按钮以生成一个树。我不知道我可以用什么工具来完成我的任务,我昨天刚开始学习C#,对此我没有太多的知识。关于这个主题的更多指导将对我非常有帮助,谢谢这里是到目前为止的代码 using System; using System.Collections.Generic; using System.ComponentModel;

我已经试了几个小时了,但没能让它工作,我必须用c#中的面板和按钮实现一个二元搜索树。到目前为止,我所做的是从文本区域获取输入,并制作一个带有文本值的按钮,现在我必须以层次方式显示按钮以生成一个树。我不知道我可以用什么工具来完成我的任务,我昨天刚开始学习C#,对此我没有太多的知识。关于这个主题的更多指导将对我非常有帮助,谢谢这里是到目前为止的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        string value;
        int z=30;
        int y=100;
        List<Panel> ls = new List<Panel>();
        Button main = new Button();
        public Form1()
        {
            InitializeComponent();
        }

        private void retrieveInput_Click(object sender, EventArgs e)
        {
            value = this.inputText.Text;
            long number1= 0;
            bool canConvert = long.TryParse(value, out number1);
            if (canConvert == true)
            {
                Button button1 = new Button();
               Panel pan = new Panel();
                ls.Add(pan);
                pan.Location = new Point(10, z * 100);
                pan.Size = new Size(200, 90);  // just an example
                this.Controls.Add(pan);
                button1.Click +=(Onb2Click);
                button1.Text = value;
                button1.Width = 100;//this.Width - 10;
                button1.Height = 30;
                pan.Controls.Add(button1);
                pan.Location = new Point(10, z * 100);
                z = z + 30;
                pan.Size = new Size(200, 90);  // just an example
                this.Controls.Add(pan);
                panel1.Controls.Add(pan);

            }
            else
            {
               // Console.WriteLine("numString is not a valid long");

            }   
        }

        private void inputText_TextChanged(object sender, EventArgs e)
        {
            value = this.inputText.Text;
           // retrieveInput_Click(object sender, EventArgs e);

        }

        void Onb2Click(object sender, EventArgs e)
        {

        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {
            z++;
            y++;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }


    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间Windows窗体应用程序1
{
公共部分类Form1:Form
{
字符串值;
int z=30;
int y=100;
列表ls=新列表();
按钮主=新按钮();
公共表格1()
{
初始化组件();
}
私有无效检索输入\单击(对象发送方,事件参数e)
{
值=this.inputText.Text;
长数1=0;
bool canConvert=长锥巴色(值,输出编号1);
如果(canConvert==true)
{
Button button1=新按钮();
面板盘=新面板();
ls.添加(pan);
平移位置=新点(10,z*100);
pan.Size=new Size(200,90);//只是一个例子
this.Controls.Add(pan);
按钮1.点击+=(点击按钮2);
按钮1.文本=值;
button1.Width=100;//this.Width-10;
按钮1.高度=30;
平移。控件。添加(按钮1);
平移位置=新点(10,z*100);
z=z+30;
pan.Size=new Size(200,90);//只是一个例子
this.Controls.Add(pan);
面板1.控件。添加(pan);
}
其他的
{
//WriteLine(“numString不是有效的long”);
}   
}
private void inputText\u TextChanged(对象发送者,事件参数e)
{
值=this.inputText.Text;
//检索输入\单击(对象发送者,事件参数e);
}
单击时无效(对象发送者,事件参数e)
{
}
私有void flowLayoutPanel1_绘制(对象发送方,PaintEventArgs e)
{
z++;
y++;
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有void panel 1_Paint(对象发送器,PaintEventArgs e)
{
}
}
}

我建议您改用
TreeView
控件。
更容易处理父子显示流

我尝试了面板和flowlayout,flowlayout自动以流的方式定位按钮,通过使用面板它只添加一次按钮,我不使用循环或继续池输入字段来检查输入,我现在很困惑:(这是homewoek还是你为什么不使用现成的TreeView?FLP会自动填充,因此你必须在每个“节点”前放入空白的虚拟文件。你/用户如何创建层次结构?你有期望结果的草图吗?是的,这是一个家庭作业,我解决了我的问题。我使用datagrid插入了按钮,但到目前为止我能够实现只有一个级别的bst树,它没有添加更多的按钮。如果我可以使用一些可靠的方法来完成这个任务,请指导我