高级控件:菜单、工具栏多窗口控制
来源:互联网 发布:tgp腾讯游戏客户端mac 编辑:程序博客网 时间:2024/06/06 00:13
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <DockPanel> <Menu DockPanel.Dock="Top"> <MenuItem Header="文件"> <MenuItem Header="打开" Name="miOpen" Click="miOpen_Click"></MenuItem> </MenuItem> <MenuItem Header="编辑"> <MenuItem Header="复制"></MenuItem> </MenuItem> </Menu> <TextBox DockPanel.Dock="Bottom"></TextBox> </DockPanel> </Grid></Window>
<Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized" Title="主程序" Height="350" Width="525"> <Grid> <DockPanel> <Menu DockPanel.Dock="Top"> <MenuItem Header="打开"></MenuItem> <MenuItem Header="编辑"></MenuItem> </Menu> <ToolBar DockPanel.Dock="Top" Height="30"> <Button Name="btnDelete" Click="btnDelete_Click"> <Image Source="Images/delete.ico"></Image> </Button> <Button> <Button.Content> <Image Source="Images/clipboard.ico"></Image> </Button.Content> </Button> <CheckBox Content="自动保存"></CheckBox> <TextBox></TextBox> </ToolBar> <TextBox Name="txtName" DockPanel.Dock="Bottom"></TextBox> </DockPanel> </Grid></Window>
<Application x:Class="WpfApplication2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
在APP.xaml里StartupUri="MainWindow.xaml"是指定主窗口的属性
<Window x:Class="WpfApplication2.AboutWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="关于" Height="500" Width="800" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closed="Window_Closed"> <Grid> <TextBox Name="txtTest" Height="23" HorizontalAlignment="Left" Margin="58,91,0,0" VerticalAlignment="Top" Width="120" Text="我的对话框" /> <PasswordBox Height="23" HorizontalAlignment="Left" Margin="69,126,0,0" Name="pwdBox1" VerticalAlignment="Top" Width="120" /> </Grid></Window>
ResizeMode="NoResize"<span style="white-space:pre"></span>使其无法修改大小
WindowStartupLocation="CenterScreen" <span style="white-space:pre"></span>窗口打开的位置在正中央
WindowState="maxsize" <span style="white-space:pre"></span>让窗口打开时最大化
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace WpfApplication2{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void btnDelete_Click(object sender, RoutedEventArgs e) { string name = txtName.Text; AboutWindow aboutWin = new AboutWindow(); aboutWin.UserName = name;//无论是子窗口向主窗口传值 //还是子窗口给主窗口传值,都是通过属性 aboutWin.ShowDialog(); MessageBox.Show(aboutWin.Password); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace WpfApplication2{ /// <summary> /// AboutWindow.xaml 的交互逻辑 /// </summary> public partial class AboutWindow : Window { public string UserName { get; set; } public string Password { get; set; } public AboutWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { txtTest.Text = UserName; } private void Window_Closed(object sender, EventArgs e) { Password = pwdBox1.Password; }//传递数值 }}
private void button3_Click(object sender, RoutedEventArgs e) { //openfiledialog ofd = new openfiledialog(); //ofd.filter = "文本文件|*.txt|png图片|*.png|视频|*.avi|所有文件|*.*"; //if (ofd.showdialog() == true) //{ // string file = ofd.filename;//打开的文件名 // messagebox.show("打开文件" + file); //} //else //{ // messagebox.show("取消了"); //} SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "文本文件|*.txt|word文档|*.doc"; if (sfd.ShowDialog() == true) { //会自动加后缀扩展名 MessageBox.Show(sfd.FileName); } }
<span style="white-space:pre"> private void btnChoosePic_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "JPEG图片|*.jpg|PNG图片|*.png|BMP图片|*.bmp"; if (ofd.ShowDialog() == true) { string picFileName = ofd.FileName; image1.Source = new BitmapImage(new Uri(picFileName)); } }</span>
0 0
- 高级控件:菜单、工具栏多窗口控制
- Eclipse plugin 用户权限控制菜单与工具栏
- Winform控件之菜单控件,工具栏控件和状态栏控件
- C#进阶 WPF基础二 布局嵌套、菜单、工具栏、多窗口
- 用open弹出窗口,可以实现无菜单,无工具栏..........
- VC++中添加菜单、状态栏、工具栏及窗口全屏
- PyQt5:PyQt5中的菜单和工具栏、主窗口(7)
- Delphi中菜单与工具栏按钮的状态控制
- 一个ASP.NET工具栏和菜单控件(源码)
- 控件(主菜单、上下文菜单、工具栏、状态栏)
- InstallShield 自定义窗口控件控制
- QT主窗口创建菜单、工具栏和状态栏,添加上下文菜单
- MFC基于对话框 创建工具栏 工具栏提示 窗口同步缩放 拦截主界面Enter按下 窗口过程 菜单工具栏按钮变灰
- Asp.net 2.0 自定义控件开发[工具栏菜单控件](示例代码下载)
- 自定义高级控件打造主流的侧滑菜单控件
- 工具栏&菜单项
- Ext工具栏菜单_wayfoon
- RCP--菜单,工具栏
- MAC - 使用 brew 安装东西时出现 curl: (7) Failed connect to downloads.sf.net:443; Operation timed out 的解决办法
- POJ 1002 487-3279
- Servlet的一些重要细节
- iOS多线程GCD
- 电容的充电速率
- 高级控件:菜单、工具栏多窗口控制
- PHP Console工具使用分享
- MongoDB之整库备份还原单表collection备份还原
- 数据结构基础java实现—双向链表
- poj3009 冰球
- Android:圆形头像
- HDU1162最小生成树
- 网页宽度自动调整响应式网页
- 结合属性文件的工厂模式(java反射的应用)