wpf源码分享-select返回结果输出window-完整函数+调用示范

using System.Data;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace WpfBrowserApplication1
{
    class Classtest
    {
        static public double FontSizestatic = 20;
        static private Window tmpwin;  //敲键盘时关联的窗口;
        static public DataGrid Add_DataGrid(Canvas father, double y, double x, double Height)
        {
            DataGrid tmpDataGrid = new DataGrid();
            tmpDataGrid.Margin = new Thickness(x, y, 0, 0);
            tmpDataGrid.FontSize = FontSizestatic;
            tmpDataGrid.Height = Height;
            //tmpDataGrid.Width = 20;
            tmpDataGrid.Visibility = System.Windows.Visibility.Visible;
            father.Children.Add(tmpDataGrid);
            return tmpDataGrid;
        }
        static public void selectshow(int showmode, double y, double x, double FontSize, int WinH, DataTable DT)
        {
            //string str=initstr;
            double dgwiny = 0, dgwinx = 0;
            FontSizestatic = FontSize;
            Window readwin = new Window();
            tmpwin = readwin;
            Canvas tmpfather = new Canvas();
            readwin.Content = tmpfather;
            switch (showmode)
            {
                case 0:
                    readwin.AllowsTransparency = true; readwin.Background = Brushes.Transparent;
                    readwin.WindowStyle = WindowStyle.None; tmpfather.Background = Brushes.Transparent;
                    readwin.Top = y; readwin.Left = x;
                    dgwiny = 0; dgwinx = 0;
                    break;
                case 1:
                    readwin.Top = y; readwin.Left = x;
                    dgwiny = y; dgwinx = x;
                    break;
                default:
                    readwin.Top = y; readwin.Left = x;
                    dgwiny = y; dgwinx = y;
                    break;
            }
            //TextBox tmpbox = Add_TextBox_static(tmpfather, 0, 0, tsstr, initstr, lines, length);
            DataGrid tmpdatagrid = Add_DataGrid(tmpfather, dgwiny, dgwinx, WinH * (FontSize * 1.5));
            tmpdatagrid.BorderBrush = Brushes.Red;
            tmpdatagrid.Background = Brushes.LightSkyBlue;
            tmpdatagrid.KeyDown += Tmpdatagrid_KeyDown;
            tmpdatagrid.ItemsSource = DT.DefaultView; 
            Button tmpButton = Add_Button_static(tmpfather, WinH * (FontSize * 1.5) + 20, (SystemParameters.FullPrimaryScreenWidth - x * 2) / 2 - 20, "关闭", "close");
            tmpButton.Click += TmpButton_Click;


            readwin.ShowDialog();




            return;
        }
         
        private static void TmpButton_Click(object sender, RoutedEventArgs e)
        {
            tmpwin.DialogResult = true;
        }
         
        static public Button Add_Button_static(Canvas father, double y, double x, string name, string uid)
        {
            Button stButton = new Button();
            stButton.Name = name;
            stButton.Content = name;
            stButton.Uid = uid;
            stButton.FontSize = FontSizestatic;
            stButton.Margin = new Thickness(x, y, 0, 0);
            stButton.Visibility = System.Windows.Visibility.Visible;
            father.Children.Add(stButton);
            return stButton;
        }
        private static void Tmpdatagrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Escape)
                tmpwin.DialogResult = false;
            else if (e.Key == System.Windows.Input.Key.Q)
                tmpwin.DialogResult = false;
        }
    }
}


//上面的是完整的直接使用,下面要自己改成本地数据库访问的。
public partial class Window1 : Window
{


        ....
DataTable dt = new DataTable();
SqlDataAdapter da;
string StrSql, connectionString;
        StrSql="select * from biaotest";
        connectionString=...//连接数据库的串
da = new SqlDataAdapter(StrSql, connectionString);
da.Fill(dt);
Classtest.selectshow(0, 128, 410, 20, 12, dt.Tables);  //主要是提供了这个函数直接查看表内容,必须返回后才操作其他功能,必定有场景会用到还可以改造他用。
            .....
 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值