WPF 体验---对话框调用

很长时间没开博了。继续。。。。

WPF相对于Winform, dialog control是少了几个阿。不过都是一家子,可以必要时拿过来用用了。

做个简单程序调用个dialog。 效果图:

2010060917563151.png

2010060917580156.png

简单的调用,代码:

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
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 WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

public static string PicturePath = "" ;

private void btnShow_Click( object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg
= new Microsoft.Win32.OpenFileDialog();

// Set filter for file extension and default file extension

dlg.DefaultExt
= " .jpg " ;

dlg.Filter
= " JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|BMP Files (*.bmp)|*.bmp|All files (*.*)|*.* " ;



// Display OpenFileDialog by calling ShowDialog method

Nullable
< bool > result = dlg.ShowDialog();


// Get the selected file name and display in a TextBox

if (result == true )
{

// Open document

string filename = dlg.FileName;

PicturePath
= filename;

}


this .image1.Source = GetImage();
this .image1.Width = this .picPanel.Width;
image1.Height
= picPanel.Height;


}

private static BitmapImage GetImage()
{
BitmapImage image
= new BitmapImage();
image.BeginInit();
image.UriSource
= new Uri(PicturePath);
image.EndInit();
return image;
}


private void btnClear_Click( object sender, RoutedEventArgs e)
{
this .image1.Source = null ;
}

private void btnSetBG_Click( object sender, RoutedEventArgs e)
{
System.Windows.Forms.ColorDialog color
= new System.Windows.Forms.ColorDialog();
if (color.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this .picPanel.Background = new SolidColorBrush(Color.FromArgb(color.Color.A,color.Color.R,color.Color.G,color.Color.B));
}
}

private void btnClose_Click( object sender, RoutedEventArgs e)
{
this .Close();
}


}
}

别忘了引用system.windows.form噢!!

 

哦对了,这里有个Bug:拉伸窗体的时候只有最后一个Button拉伸变化,其它的不变。什么问题呢? 待研究...

转载于:https://www.cnblogs.com/jimson/archive/2010/06/09/dialog.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值