菜单和工具条

上传人:简****9 文档编号:111140332 上传时间:2019-11-01 格式:PPT 页数:26 大小:1.08MB
返回 下载 相关 举报
菜单和工具条_第1页
第1页 / 共26页
菜单和工具条_第2页
第2页 / 共26页
菜单和工具条_第3页
第3页 / 共26页
菜单和工具条_第4页
第4页 / 共26页
菜单和工具条_第5页
第5页 / 共26页
点击查看更多>>
资源描述

《菜单和工具条》由会员分享,可在线阅读,更多相关《菜单和工具条(26页珍藏版)》请在金锄头文库上搜索。

1、菜单和工具条,菜单,下拉菜单以友好的方式提供了大量的选择 主菜单 上下文菜单 菜单是用于包含菜单项的容器,MenuStrip,MenuStrip 控件是.NET2.0的新功能,使用该控件可以轻松创建Microsoft Office 中那样的菜单。 MenuStrip 控件支持多文档界面(MDI) 和菜单合并、工具提示和溢出。您可以通过添加访问键、快捷键、选中标记、图像和分隔条,来增强菜单的可用性和可读性。 MenuStrip 控件取代了MainMenu 控件并向其中添加了功能;但是也可选择保留MainMenu 控件以备向后兼容和将来使用。,菜单项的设置,提供用键盘快速访问菜单项的方法 在菜单项

2、的Text属性中加&,其后的字符即为快捷键(示例) 菜单的加速键 设置ShortCutKeys(示例) 菜单的图标 标准项的添加,设计菜单的注意事项,尽量保持与通用设置一致 Ctrl+N 创建新窗口 Ctrl+S 保存当前文件 Ctrl+C/V/X 复制/粘贴/剪切 Alt+F4 关闭窗口 。 遵循顶级菜单和子菜单的一些约定(MS office) 菜单的最常用事件Click 示例:实现图片加载Load和窗体关闭,上下文菜单ContextMenuStrip,快捷菜单(也称为上下文菜单)在用户单击鼠标右键时会出现在鼠标位置。快捷菜单在鼠标指针位置提供了工作区或控件的选项。 ContextMenuS

3、trip 控件替换ContextMenu 控件并向其添加功能;但是也可选择保留ContextMenu 控件以备向后兼容和将来使用。 ContextMenuStrip和MenuStrip都是ToolStripMenuItem、ToolStripComboBox、ToolStripSeparator 和ToolStripTextBox 对象的容器。,一般跟窗体或者窗体中的某个/某组控件绑定,一般为竖排,由右键激活 上下文菜单设计 为窗体增加一个ContextMenuStrip实例 设置某控件的ContextMenu属性 添加上下文菜单的事件处理函数 示例:用上下文菜单实现图片的大小调整,Conte

4、xtMenuStrip,private void 伸展ToolStripMenuItem_Click(object sender, EventArgs e) this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; ,如何在运行期改变图片框的尺寸模式?,下拉事件和事件参数,DropDownItemClicked 子菜单项被点击后触发,private void menuImage_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) ProcessIm

5、ageClick(e); private void ProcessImageClick(ToolStripItemClickedEventArgs e) ToolStripItem item = e.ClickedItem; string enumVal = item.Tag as string; if (enumVal != null) pbxPhoto.SizeMode = (PictureBoxSizeMode) Enum.Parse(typeof(PictureBoxSizeMode),enumVal); ,如何在图片未加载的情况下使得Image菜单子项不可用?,private voi

6、d menuImage_DropDownOpening(object sender, EventArgs e) ProcessImageOpening(sender as ToolStripDropDownItem); private void ProcessImageOpening(ToolStripDropDownItem parent) if (parent != null) string enumVal = pbxPhoto.SizeMode.ToString(); foreach (ToolStripMenuItem item in parent.DropDownItems) ite

7、m.Enabled = (pbxPhoto.Image != null); item.Checked = item.Tag.Equals(enumVal); ,DropDownOpening 当子菜单项正在打开时发生,MenuItem的继承层次,System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.ToolStripItem System.Windows.Forms.ToolStripButton System.Windows.Forms.ToolStripCon

8、trolHost System.Windows.Forms.ToolStripDropDownItem System.Windows.Forms.ToolStripMenuItem System.Windows.Forms.ToolStripLabel System.Windows.Forms.ToolStripSeparator,各Strip的集成层次,System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms

9、.ScrollableControl System.Windows.Forms.ToolStrip System.Windows.Forms.BindingNavigator System.Windows.Forms.MenuStrip System.Windows.Forms.StatusStrip System.Windows.Forms.ToolStripDropDown,状态栏StatusStrip,Windows 窗体StatusStrip 控件在窗体中作为一个区域使用,此区域通常显示在窗口底部,应用程序可以在这里显示各种状态信息。 StatusStrip 控件上通常有ToolStr

10、ipStatusLabel 控件,用于显示指示状态的文本或图标,或者有可以用图形显示进程完成状态的ToolStripProgressBar。,示例,为程序添加状态栏显示图片文件路径,图片的实际长度等信息,private void SetStatusStrip(string path) if (pbxPhoto.Image != null) statusInfo.Text = path; statusImageSize.Text = String.Format(“0:#x1:#“, pbxPhoto.Image.Width, pbxPhoto.Image.Height); else status

11、Info.Text = null; statusImageSize.Text = null; statusAlbumPos.Text = null; ,工具栏和工具栏按钮,工具栏为用户提供了另一种使用常见操作的方法,按钮的图标可以形象说明该按钮的含义 设置工具栏 工具栏事件编码 运行时刻隐藏/显示工具栏,工具栏ToolStrip,使用ToolStrip 控件可以: 创建易于自定义的常用工具栏,让这些工具栏支持高级用户界面和布局功能,如停靠、漂浮、带文本和图像的按钮、下拉按钮和控件、“溢出”按钮和ToolStrip 项的运行时重新排序。 支持操作系统的典型外观和行为。 对所有容器和包含的项进行事

12、件的一致性处理,处理方式与其他控件的事件相同。 将项从一个ToolStrip 拖到另一个ToolStrip 内。 使用ToolStripDropDown 中的高级布局创建下拉控件及用户界面类型编辑器。,ToolStrip组成项,ToolStripMenuItem的常用属性,Checked 获取或设置一个值,该值指示是否选中 ToolStripMenuItem CheckOnClick获取或设置一个值,该值指示 ToolStripMenuItem 是否应在被单击时自动显示为选中或未选中。 DropDownItems 获取与此 ToolStripDropDownItem 关联的 ToolStrip

13、DropDown 中的项的集合。 Enabled 获取或设置一个值,该值指示是否已启用控件。,示例,简易写字板的实现 页面设计 常用对话框的使用(见L3对话框及其使用) 其他实现,Font字体类,初始化新 Font,它使用指定的现有 Font 和 FontStyle。 常用的构造函数 Font (Font, FontStyle) public Font ( string familyName, float emSize ) public Font ( string familyName, float emSize, FontStyle style ),Font字体类,初始化新 Font,它使用

14、指定的现有 Font 和 FontStyle。 常用的构造函数 Font (Font f, FontStyle style) public Font ( string familyName, float emSize ) public Font ( string familyName, float emSize, FontStyle style),字体和字号填充,private void Form1_Load(object sender, EventArgs e) foreach (FontFamily f in FontFamily.Families) this.toolStripCombo

15、Box1.Items.Add(f.Name); for (int i = 5; i = 70; i+) this.toolStripComboBox2.Items.Add(i.ToString(); this.toolStripComboBox1.SelectedIndex = this.toolStripComboBox1.FindString(“Times New Roman“); this.toolStripComboBox2.SelectedIndex = 5; ,改变字体,private void toolStripComboBox1_SelectedIndexChanged(obj

16、ect sender, EventArgs e) Font curFont = this.richTextBox1.SelectionFont; Font newFont = new Font (this.toolStripComboBox1.SelectedItem.ToString(),curFont.Size, curFont.Style); this.richTextBox1.SelectionFont = newFont; ,注意:ToolStripComboBox默认事件是Click,而不是SelectedIndexChanged,字体样式FontStyle,指定应用到文本的字形信息。此枚举允许其成员值按位组合。 FlagsAttribute public enum F

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号