如何进行C#Windows应用程序模板代码实现
发表于:2025-11-15 作者:千家信息网编辑
千家信息网最后更新 2025年11月15日,本篇文章为大家展示了如何进行C#Windows应用程序模板代码实现,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。C#Windows应用程序开发之应用程序模板实
千家信息网最后更新 2025年11月15日如何进行C#Windows应用程序模板代码实现
本篇文章为大家展示了如何进行C#Windows应用程序模板代码实现,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
C#Windows应用程序开发之应用程序模板实现
/* C#Windows应用程序模板代码实现to compile this source file, type csc MyWinApp.cs */ using System; using System.Windows.Forms; using System.Drawing; using System.IO; using System.ComponentModel; public class MyWinApp: Form { Label label = new Label(); Button button = new Button(); TreeView tree = new TreeView(); ImageList imageList = new ImageList(); static String imageFolder = "Images" + Path.DirectorySeparatorChar.ToString(); // --- Images declarations C#Windows应用程序模板代码实现----- Image newFileImage = new Bitmap(imageFolder + "newFile.bmp"); Image openFileImage = new Bitmap(imageFolder + "openFile.gif"); Image saveFileImage = new Bitmap(imageFolder + "saveFile.bmp"); Image printImage = new Bitmap(imageFolder + "print.gif"); // --C#Windows应用程序模板代码实现 End of Images declaration ---- // -------------- menu -C#Windows应用程序模板------ MainMenu mainMenu = new MainMenu(); MenuItem fileMenuItem = new MenuItem(); MenuItem fileNewMenuItem; MenuItem fileOpenMenuItem; MenuItem fileSaveMenuItem; MenuItem fileSaveAsMenuItem; MenuItem fileMenuWithSubmenu; MenuItem submenuMenuItem; MenuItem fileExitMenuItem; // -------------- End of menu C#Windows应用程序模板--------------------- // -------------- Toolbar C#Windows应用程序模板----------------- ToolBar toolBar = new ToolBar(); ToolBarButton separatorToolBarButton = new ToolBarButton(); ToolBarButton newToolBarButton = new ToolBarButton(); ToolBarButton openToolBarButton = new ToolBarButton(); ToolBarButton saveToolBarButton = new ToolBarButton(); ToolBarButton printToolBarButton = new ToolBarButton(); // -------------- End of Toolbar -------------- // -------------- StatusBar -C#Windows应用程序模板--------- StatusBar statusBar = new StatusBar(); StatusBarPanel statusBarPanel1 = new StatusBarPanel(); StatusBarPanel statusBarPanel2 = new StatusBarPanel(); // -------------- End of StatusBar ---------- public MyWinApp() { InitializeComponent(); } private void InitializeComponent() { this.Text = "My Windows Application"; this.Icon = new Icon(imageFolder + "applicationLogo.ico"); this.Width = 400; this.Height = 300; this.StartPosition = FormStartPosition.CenterScreen; imageList.Images.Add(newFileImage); imageList.Images.Add(openFileImage); imageList.Images.Add(saveFileImage); imageList.Images.Add(printImage); // menu fileMenuItem.Text = "&File"; // the following constructor is the same as: // menuItem fileNewMenuItem = new MenuItem(); // fileNewMenuItem.Text = "&New"; // fileNewMenuItem.Shortcut = Shortcut.CtrlN; // fileNewMenuItem.Click += new System.EventHandler(this.fileNewMenuItem_Click); fileNewMenuItem = new MenuItem("&New", new System.EventHandler(this.fileNewMenuItem_Click), Shortcut.CtrlN); fileOpenMenuItem = new MenuItem("&Open", new System.EventHandler(this.fileOpenMenuItem_Click), Shortcut.CtrlO); fileSaveMenuItem = new MenuItem("&Save", new System.EventHandler(this.fileSaveMenuItem_Click), Shortcut.CtrlS); fileSaveAsMenuItem = new MenuItem("Save &As", new System.EventHandler(this.fileSaveAsMenuItem_Click)); fileMenuWithSubmenu = new MenuItem("&With Submenu"); submenuMenuItem = new MenuItem("Su&bmenu", new System.EventHandler(this.submenuMenuItem_Click)); fileExitMenuItem = new MenuItem("E&xit", new System.EventHandler(this.fileExitMenuItem_Click)); mainMenu.MenuItems.Add(fileMenuItem); fileOpenMenuItem.Checked = true; fileMenuItem.MenuItems.Add(fileNewMenuItem); fileMenuItem.MenuItems.Add(fileOpenMenuItem); fileMenuItem.MenuItems.Add(fileSaveMenuItem); fileMenuItem.MenuItems.Add(fileSaveAsMenuItem); fileMenuItem.MenuItems.Add(fileMenuWithSubmenu); fileMenuWithSubmenu.MenuItems.Add(submenuMenuItem); fileMenuItem.MenuItems.Add("-"); // add a separator fileMenuItem.MenuItems.Add(fileExitMenuItem); toolBar.Appearance = ToolBarAppearance.Normal; //toolBar.Appearance = ToolBarAppearance.Flat; toolBar.ImageList = imageList; toolBar.ButtonSize = new Size(14, 6); separatorToolBarButton.Style = ToolBarButtonStyle.Separator; newToolBarButton.ToolTipText = "New Document"; newToolBarButton.ImageIndex = 0; openToolBarButton.ToolTipText = "Open Document"; openToolBarButton.ImageIndex = 1; saveToolBarButton.ToolTipText = "Save"; saveToolBarButton.ImageIndex = 2; printToolBarButton.ToolTipText = "Print"; printToolBarButton.ImageIndex = 3; toolBar.ButtonClick += new ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); toolBar.Buttons.Add(separatorToolBarButton); toolBar.Buttons.Add(newToolBarButton); toolBar.Buttons.Add(openToolBarButton); toolBar.Buttons.Add(saveToolBarButton); toolBar.Buttons.Add(separatorToolBarButton); toolBar.Buttons.Add(printToolBarButton); tree.Top = 40; tree.Left = 20; tree.Width = 100; tree.Height = 100; label.Location = new Point(220, 40); label.Size = new Size(160, 30); label.Text = "Yes, click the button"; button.Location = new Point(220, 80); button.Size = new Size(100, 30); button.Text = "Click this"; button.Click += new System.EventHandler(this.button_Click); statusBarPanel1.BorderStyle = StatusBarPanelBorderStyle.Sunken; statusBarPanel1.Text = "Press F1 for Help"; statusBarPanel1.AutoSize = StatusBarPanelAutoSize.Spring; statusBarPanel2.BorderStyle = StatusBarPanelBorderStyle.Raised; statusBarPanel2.ToolTipText = System.DateTime.Now.ToShortTimeString(); statusBarPanel2.Text = System.DateTime.Today.ToLongDateString(); statusBarPanel2.AutoSize = StatusBarPanelAutoSize.Contents; statusBar.ShowPanels = true; statusBar.Panels.Add(statusBarPanel1); statusBar.Panels.Add(statusBarPanel2); this.Menu = mainMenu; this.Controls.Add(toolBar); this.Controls.Add(tree); this.Controls.Add(label); this.Controls.Add(button); this.Controls.Add(statusBar); } // --- Event Handlers -C#Windows应用程序模板------- private void fileNewMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- New menu.", "The Event Information"); } private void fileOpenMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Open menu.", "The Event Information"); } private void fileSaveMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Save menu.", "The Event Information"); } private void fileSaveAsMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Save As menu.", "The Event Information"); } private void fileExitMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Exit As menu.", "The Event Information"); } private void submenuMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the submenu.", "The Event Information"); } protected void toolBar_ButtonClick(Object sender, ToolBarButtonClickEventArgs e) { // Evaluate the Button property to determine which button was clicked. switch (toolBar.Buttons.IndexOf(e.Button)) { case 1: MessageBox.Show("Second button.", "The Event Information"); break; case 2: MessageBox.Show("third button", "The Event Information"); break; case 3: MessageBox.Show("fourth button.", "The Event Information"); break; } } protected override void OnClosing(CancelEventArgs e) { MessageBox.Show("Exit now.", "The Event Information"); } private void button_Click(Object sender, System.EventArgs e) { MessageBox.Show("Thank you.", "The Event Information"); } // ---- End of Event Handlers ------- public static void Main() { MyWinApp form = new MyWinApp(); Application.Run(form); } } //C#Windows应用程序模板C#Windows应用程序模板的代码实现就向你介绍到这里,希望对你学习和了解C#Windows应用程序模板有所帮助。
上述内容就是如何进行C#Windows应用程序模板代码实现,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。
应用程序
程序
应用
模板
代码
内容
技能
知识
简明
简明扼要
就是
文章
更多
篇文章
行业
资讯
资讯频道
频道
一亮
储备
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
julia能否用于软件开发
hpa数据库免疫组化图片
我的世界推荐的建筑服务器
网络安全大厂360
网络安全管理员初级
陈鑫杰网络安全全栈视频下载
兄弟连linux服务器教程交流
小软件开发团队管理及定位
工程网络安全建设ppt
汽车网络安全黑客大赛冠军
网络安全法知识问答题
海南高科技软件开发报价
实验仿真软件开发意义
中山大学新华学院软件开发
作文网络安全的作文
开发小程序不需要服务器吗
华讯一面软件开发
软件开发与实践的总结报告
上海网络技术咨询服务收费
关于网络安全主题的手抄报内容
优酷合一网络技术
如何安卓端上位机软件开发
破碎时空奇迹服务器中断
利辛租房软件开发
电脑服务器稳定吗
怎么把图片上传到网络上的服务器
公司信息 数据库
网络安全三字经大全
数据库民航售票管理
上海网络技术咨询服务收费