Visual Studio를 사용하여 Windows 양식 응용 프로그램을 만듭니다. 내 시스템은 대학 모듈 정보를 작성하고 보는 역할을 담당합니다. 그러나 현재는 시스템이 부팅 될 때 Tool Strip Menu를 채울 것입니다. 새 항목을 만들 때이 목록에 새 항목을 추가하는 방법이 필요합니다. 새 레코드는 다른 형식으로 만들어졌으며 Form2를 만드는 중 하나에서 Form1의 ToolStripDropdown에 항목을 추가하는 방법을 알 수 없습니다 (아래 그림 참조). ToolStripMenuItem을 공용으로 단순히 만들려고했지만 작동하지 않습니다. 누구든지 나를 도울 수 있습니까? 드롭에 항목을 추가하는다른 양식의 ToolStripMenuItem 드롭 다운 목록에 항목 추가
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;
using System.IO;
namespace Mod_Note_2._0
{
public partial class Form2 : Form
{
public string newmodcode;
public string baseText = "Enter information related to the module section here";
public string newmodtitle;
public string newmodsyn;
public string newmodlo;
public string newmodassign;
public Form2()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
newmodcode = NewModuleCode.Text;
//Adds the file path and name to the module code to create the file names
newmodtitle = newmodcode + "title.txt";
newmodsyn = newmodcode + "synopsis.txt";
newmodlo = newmodcode + "LOs.txt";
newmodassign = newmodcode + "assignments.txt";
//Adds the file path the new module code so it can create the file
string newmodcodepath = newmodcode + "code.txt";
//Creates the new files with the filler text as default
File.WriteAllText(newmodcodepath, newmodcode);
File.WriteAllText(newmodtitle, baseText);
File.WriteAllText(newmodsyn, baseText);
File.WriteAllText(newmodlo, baseText);
File.WriteAllText(newmodassign, baseText);
현재 코드 : 여기 대답
ToolStripItem newDropDownItem = new ToolStripMenuItem(); newDropDownItem.Text = newmodcode; Form1.modulesToolStripMenuItem.DropDownItems.Add(newDropDownItem);
Close();
}
//Simple cancelation sequence closing the entry form
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}
당신은 두 번째 형태의 첫 번째 양식에 대한 참조가 필요합니다. 이렇게 : http://stackoverflow.com/a/38460510/3185569 – user3185569