c#上实现如下功能

dandingjie1 2020-01-11 11:52:36
加精


请教各位大佬!!想在c#上实现 ,当我参数分段选一段,下面只显示一段参数;当我选择十二段,下面显示十二段参数;
我现在是用groupbox,参数分段多了会显示不全,想做一个类似下拉的!
...全文
3923 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_44615268 2020-06-08
  • 打赏
  • 举报
回复
这个可以借鉴一下
zjiadaxiaojie 2020-03-12
  • 打赏
  • 举报
回复
mark一下
lzhdim 2020-03-09
  • 打赏
  • 举报
回复
界面再优化一下。。。
木 土 硎 2020-03-03
  • 打赏
  • 举报
回复
用两个button动态添加删除即可
weixin_44614745 2020-01-12
  • 打赏
  • 举报
回复
做一个下拉控件呢,然后添加12个分段,在选择不用分段时,把不想出现的分段隐藏掉,这样子可以吗
dandingjie1 2020-01-11
  • 打赏
  • 举报
回复 1
引用 2 楼 贵阳老马马善福专业维修游泳池堵漏防水工程 的回复:
帮你完整写了一个

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

namespace T395615469
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private int max = 0;

private string no = "一,二,三,四,五,六,七,八,九,十,十一,十二";

public void RemoveSegment()
{
if (max > 0)
{
if (max > 2)
{
Controls["btn" + (max * 2 - 3).ToString()].Visible = true;
Controls["btn" + (max * 2 - 4).ToString()].Visible = true;
}
else if (max > 1)
{
Controls["btn" + (max * 2 - 4).ToString()].Visible = true;
}
Controls.Remove(Controls["lbl" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["lbl" + (max * 2 - 2).ToString()]);
Controls.Remove(Controls["cbo" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["cbo" + (max * 2 - 2).ToString()]);
Controls.Remove(Controls["btn" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["btn" + (max * 2 - 2).ToString()]);
max--;
}
}

public void AddSegment()
{
if (max == no.Split(',').Count())
return;
Label lbl = new Label();
lbl.Text = "第" + no.Split(',')[max] + "段";
lbl.Name = "lbl" + (max * 2).ToString();
lbl.Left = 25 + AutoScrollPosition.X;
lbl.Top = 60 + max * 40 + AutoScrollPosition.Y;
lbl.AutoSize = true;
Controls.Add(lbl);
ComboBox cbo = new ComboBox();
cbo.Items.AddRange(Enumerable.Range(0, 23).Select(x => (object)x).ToArray());
cbo.Left = 90 + AutoScrollPosition.X;
cbo.Top = 57 + max * 40 + AutoScrollPosition.Y;
cbo.Name = "cbo" + (max * 2).ToString();
Controls.Add(cbo);
lbl = new Label();
lbl.Text = "-----";
lbl.Name = "lbl" + (max * 2 + 1).ToString();
lbl.Left = 225 + AutoScrollPosition.X;
lbl.Top = 60 + max * 40 + AutoScrollPosition.Y;
lbl.AutoSize = true;
Controls.Add(lbl);
cbo = new ComboBox();
cbo.Items.AddRange(Enumerable.Range(0, 23).Select(x => (object)x).ToArray());
cbo.Left = 265 + AutoScrollPosition.X;
cbo.Top = 57 + max * 40 + AutoScrollPosition.Y;
cbo.Name = "cbo" + (max * 2 + 1).ToString();
Controls.Add(cbo);
Button btn = new Button();
btn.Text = "Add";
btn.Left = 410 + AutoScrollPosition.X;
btn.Top = 56 + max * 40 + AutoScrollPosition.Y;
btn.Name = "btn" + (max * 2).ToString();
btn.Click += new EventHandler(btn1_Click);
Controls.Add(btn);
btn = new Button();
btn.Text = "Remove";
btn.Left = 490 + AutoScrollPosition.X;
btn.Top = 56 + max * 40 + AutoScrollPosition.Y;
btn.Name = "btn" + (max * 2 + 1).ToString();
btn.Click += new EventHandler(btn2_Click);
Controls.Add(btn);
if (max == no.Split(',').Count() - 1)
{
Controls["btn" + (max * 2).ToString()].Visible = false;
Controls["btn" + (max * 2 - 1).ToString()].Visible = false;
Controls["btn" + (max * 2 - 2).ToString()].Visible = false;
}
else if (max == 0)
{
Controls["btn" + (max * 2 + 1).ToString()].Visible = false;
}
else
{
Controls["btn" + (max * 2 - 1).ToString()].Visible = false;
Controls["btn" + (max * 2 - 2).ToString()].Visible = false;
}
max++;
}

private void btn1_Click(object sender, EventArgs e)
{
AddSegment();
}

private void btn2_Click(object sender, EventArgs e)
{
RemoveSegment();
}

private void Form1_Load(object sender, EventArgs e)
{
AddSegment();
}
}
}
谢谢大神
dandingjie1 2020-01-11
  • 打赏
  • 举报
回复
解决啦 谢谢大家
牧歌ing 2020-01-11
  • 打赏
  • 举报
回复
厉害
threenewbee 2020-01-11
  • 打赏
  • 举报
回复
下载:https://download.csdn.net/download/caozhy/12097681
threenewbee 2020-01-11
  • 打赏
  • 举报
回复 1
帮你完整写了一个

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

namespace T395615469
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private int max = 0;

private string no = "一,二,三,四,五,六,七,八,九,十,十一,十二";

public void RemoveSegment()
{
if (max > 0)
{
if (max > 2)
{
Controls["btn" + (max * 2 - 3).ToString()].Visible = true;
Controls["btn" + (max * 2 - 4).ToString()].Visible = true;
}
else if (max > 1)
{
Controls["btn" + (max * 2 - 4).ToString()].Visible = true;
}
Controls.Remove(Controls["lbl" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["lbl" + (max * 2 - 2).ToString()]);
Controls.Remove(Controls["cbo" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["cbo" + (max * 2 - 2).ToString()]);
Controls.Remove(Controls["btn" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["btn" + (max * 2 - 2).ToString()]);
max--;
}
}

public void AddSegment()
{
if (max == no.Split(',').Count())
return;
Label lbl = new Label();
lbl.Text = "第" + no.Split(',')[max] + "段";
lbl.Name = "lbl" + (max * 2).ToString();
lbl.Left = 25 + AutoScrollPosition.X;
lbl.Top = 60 + max * 40 + AutoScrollPosition.Y;
lbl.AutoSize = true;
Controls.Add(lbl);
ComboBox cbo = new ComboBox();
cbo.Items.AddRange(Enumerable.Range(0, 23).Select(x => (object)x).ToArray());
cbo.Left = 90 + AutoScrollPosition.X;
cbo.Top = 57 + max * 40 + AutoScrollPosition.Y;
cbo.Name = "cbo" + (max * 2).ToString();
Controls.Add(cbo);
lbl = new Label();
lbl.Text = "-----";
lbl.Name = "lbl" + (max * 2 + 1).ToString();
lbl.Left = 225 + AutoScrollPosition.X;
lbl.Top = 60 + max * 40 + AutoScrollPosition.Y;
lbl.AutoSize = true;
Controls.Add(lbl);
cbo = new ComboBox();
cbo.Items.AddRange(Enumerable.Range(0, 23).Select(x => (object)x).ToArray());
cbo.Left = 265 + AutoScrollPosition.X;
cbo.Top = 57 + max * 40 + AutoScrollPosition.Y;
cbo.Name = "cbo" + (max * 2 + 1).ToString();
Controls.Add(cbo);
Button btn = new Button();
btn.Text = "Add";
btn.Left = 410 + AutoScrollPosition.X;
btn.Top = 56 + max * 40 + AutoScrollPosition.Y;
btn.Name = "btn" + (max * 2).ToString();
btn.Click += new EventHandler(btn1_Click);
Controls.Add(btn);
btn = new Button();
btn.Text = "Remove";
btn.Left = 490 + AutoScrollPosition.X;
btn.Top = 56 + max * 40 + AutoScrollPosition.Y;
btn.Name = "btn" + (max * 2 + 1).ToString();
btn.Click += new EventHandler(btn2_Click);
Controls.Add(btn);
if (max == no.Split(',').Count() - 1)
{
Controls["btn" + (max * 2).ToString()].Visible = false;
Controls["btn" + (max * 2 - 1).ToString()].Visible = false;
Controls["btn" + (max * 2 - 2).ToString()].Visible = false;
}
else if (max == 0)
{
Controls["btn" + (max * 2 + 1).ToString()].Visible = false;
}
else
{
Controls["btn" + (max * 2 - 1).ToString()].Visible = false;
Controls["btn" + (max * 2 - 2).ToString()].Visible = false;
}
max++;
}

private void btn1_Click(object sender, EventArgs e)
{
AddSegment();
}

private void btn2_Click(object sender, EventArgs e)
{
RemoveSegment();
}

private void Form1_Load(object sender, EventArgs e)
{
AddSegment();
}
}
}

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧