怎么在实现了切分的窗口上添加按钮? 我做了一个已经切分好了的窗口,想在窗口的下部添加按钮,但我在资源视图中添加按钮资源并编辑好后,运行时发现并没有出现我想要的按钮,我相信这是一个极其初级的问题,有谁可以指导指导我吗?谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要添加到哪里?formview上直接加就行了,动态添加也很简单在这篇文章中,我们将学习如何在winform中添加按钮。我们可以在设计视图里添加按钮控件,也可以在代码中动态添加按钮控件,下面的代码显示了如何在winform中动态添加一个按钮控件。using System;using System.ComponentModel;using System.WinForms;using System.Drawing;public class MenuTest :Form {private MainMenu mainMenu;private ContextMenu popUpMenu;public MenuTest() {mainMenu = new MainMenu();popUpMenu =new ContextMenu();popUpMenu.MenuItems.Add("Hello",new EventHandler(pop_Clicked));this.ContextMenu = popUpMenu;MenuItem File = mainMenu.MenuItems.Add("&File");File .MenuItems.Add(new MenuItem("&New",new EventHandler(this.FileNew_clicked),Shortcut.CtrlN));File .MenuItems.Add(new MenuItem("&Open",new EventHandler(this.FileOpen_clicked),Shortcut.CtrlO));File .MenuItems.Add(new MenuItem("&Exit",new EventHandler(this.FileExit_clicked),Shortcut.CtrlX));this.Menu=mainMenu;MenuItem About = mainMenu.MenuItems.Add("&About");About.MenuItems.Add(new MenuItem("&About",new EventHandler(this.About_clicked),Shortcut.CtrlA));this.Menu=mainMenu;mainMenu.GetForm().BackColor = Color.Indigo ;}private void FileExit_clicked(object sender, EventArgs e) { this.Close(); }private void FileNew_clicked(object sender, EventArgs e) { MessageBox.Show("New","MENU_CREATION",MessageBox.IconInformation); }private void FileOpen_clicked(object sender, EventArgs e) { MessageBox.Show("Open","MENU_CREATION",MessageBox.IconInformation); }private void pop_Clicked(object sender, EventArgs e) { MessageBox.Show("Popupmenu","MENU_CREATION",MessageBox.IconInformation); }private void About_clicked(object sender, EventArgs e) { MessageBox.Show("G.GNANA ARUN GANESH","[email protected]",MessageBox.IconInformation); }public static void Main(string[] args) { Application.Run(new MenuTest()); } } ---------------------------------------------| Menu ___________________________________|| | || view1 | view2 || | ||-------------------------------------------|| button1 button1 |---------------------------------------------这样吗,那你button的位置是什么位置,第三个formview? 使用VS2005安装部署文件,卸载的时候进度条停止不动,怎么回事 照例子做一点按钮出来 hello,world!的MFC程序 出错 工作者线程通信错误 高分悬赏tabctrl拖拽问题 请教高手——关于大型场景中的碰撞检测 请教webbrowser控件中的NewWindow2事件的问题 出售人力资源(人事)管理系统软件和源码!!! 高手帮忙 谁来解释一下编译原理中的两句话? 关于(CFile类写文件时如何输入回车)的小菜问题 一個簡單的串口問題,急急啊,在綫等,各位前輩多多指教 请教!!VC中如何更快的读写文件?
在这篇文章中,我们将学习如何在winform中添加按钮。我们可以在设计视图里添加按钮控件,也可以在代码中动态添加按钮控件,下面的代码显示了如何在winform中动态添加一个按钮控件。using System;
using System.ComponentModel;
using System.WinForms;
using System.Drawing;public class MenuTest :Form {
private MainMenu mainMenu;
private ContextMenu popUpMenu;
public MenuTest() {
mainMenu = new MainMenu();
popUpMenu =new ContextMenu();
popUpMenu.MenuItems.Add("Hello",new EventHandler(pop_Clicked));
this.ContextMenu = popUpMenu;
MenuItem File = mainMenu.MenuItems.Add("&File");
File .MenuItems.Add(new MenuItem("&New",new EventHandler(this.FileNew_clicked),Shortcut.CtrlN));
File .MenuItems.Add(new MenuItem("&Open",new EventHandler(this.FileOpen_clicked),Shortcut.CtrlO));
File .MenuItems.Add(new MenuItem("&Exit",new EventHandler(this.FileExit_clicked),Shortcut.CtrlX));
this.Menu=mainMenu;
MenuItem About = mainMenu.MenuItems.Add("&About");
About.MenuItems.Add(new MenuItem("&About",new EventHandler(this.About_clicked),Shortcut.CtrlA));
this.Menu=mainMenu;
mainMenu.GetForm().BackColor = Color.Indigo ;}
private void FileExit_clicked(object sender, EventArgs e) {
this.Close();
}
private void FileNew_clicked(object sender, EventArgs e) {
MessageBox.Show("New","MENU_CREATION",MessageBox.IconInformation);
}
private void FileOpen_clicked(object sender, EventArgs e) {
MessageBox.Show("Open","MENU_CREATION",MessageBox.IconInformation);
}
private void pop_Clicked(object sender, EventArgs e) {
MessageBox.Show("Popupmenu","MENU_CREATION",MessageBox.IconInformation);
}
private void About_clicked(object sender, EventArgs e) {
MessageBox.Show("G.GNANA ARUN GANESH","[email protected]",MessageBox.IconInformation);
}
public static void Main(string[] args) {
Application.Run(new MenuTest());
}
}
| Menu ___________________________________|
| | |
| view1 | view2 |
| | |
|-------------------------------------------|
| button1 button1 |
---------------------------------------------这样吗,那你button的位置是什么位置,第三个formview?