首页新闻找找看学习计划

silverlight 有没有仅选择时和分的控件

0
[已解决问题] 解决于 2013-08-14 12:52

rt  因为周期是天 所以只需要拿时和分

微风吹过12x的主页 微风吹过12x | 初学一级 | 园豆:73
提问于:2013-05-22 17:01
< >
分享
最佳答案
0

telerik  中的RadDateTimePicker

奖励园豆:5
土星的山羊 | 初学一级 |园豆:191 | 2013-07-10 14:50
其他回答(2)
0

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WindPowerSL.BaseClass
{
    public class DatePickerExpand : Canvas
    {
        bool onlyone = false;
        public DateTime datatime;

        public DatePickerExpand()
        {
            this.Loaded += new RoutedEventHandler(DatePickerExpand_Loaded);
        }
        void DatePickerExpand_Loaded(object sender, RoutedEventArgs e)
        {
            TextBox txt = new TextBox();
            txt.TextChanged += new TextChangedEventHandler(txt_TextChanged);
            txt.IsReadOnly = true;
            datatime = DateTime.Now;
            txt.Text = datatime.ToString("yyyy-MM-dd HH:mm");
            txt.Width = 132;
            txt.Height = 25;
            txt.Margin = new Thickness(5, 0, 0, 0);
            this.Children.Add(txt);
            Button btn = new Button();
            btn.Content = "请选择";
            btn.Opacity = 1.0;
            btn.Background = new SolidColorBrush(Colors.White);

    btn.Height = 25;
            btn.Click += new RoutedEventHandler(btn_Click);

            this.Children.Add(btn);
            btn.SetValue(MarginProperty, new Thickness(txt.Width, 0, 0, 0));
        }

        void txt_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox txt = this.Children[0] as TextBox;
            try
            {
                Convert.ToDateTime(txt.Text);
                datatime = Convert.ToDateTime(txt.Text);
                txt.Foreground = new SolidColorBrush(Colors.Black);
              
            }
            catch (Exception)
            {
                txt.Foreground = new SolidColorBrush(Colors.Red);
            }
        }

 

        void btn_Click(object sender, RoutedEventArgs e)
        {
            if (onlyone == false)
            {
                Border border = new Border();
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                Thickness tk = new Thickness(1.0);
                border.BorderThickness = tk;
                Canvas can = new Canvas();
                border.Child = can;
                can.Width = 190;

      can.Height = 203;
                can.Background = new SolidColorBrush(Colors.White);
                can.Opacity = 1.0;
                can.SetValue(ZIndexProperty, 200);
                Calendar calendar = new Calendar();
                calendar.BorderThickness = new Thickness(0.0);
                calendar.SelectedDate = datatime;
                calendar.SelectionMode = CalendarSelectionMode.SingleDate;
                TimePicker timePicker = new TimePicker();
                timePicker.Background = new SolidColorBrush(Colors.White);
                timePicker.Opacity = 1.0;
                timePicker.Value = datatime;
                Button btn1 = new Button();
                btn1.Opacity = 1.0;
                btn1.Background = new SolidColorBrush(Colors.White);
                btn1.Click += new RoutedEventHandler(btn1_Click);
                btn1.Content = "确定";
                can.Children.Add(calendar);
                can.Children.Add(timePicker);
                can.Children.Add(btn1);
                calendar.SetValue(MarginProperty, new Thickness(7, 0, 0, 0));
                timePicker.SetValue(MarginProperty, new Thickness(5, 175, 0, 0));

      

btn1.SetValue(MarginProperty, new Thickness(140, 175, 0, 0));
                this.Children.Add(border);
                can.SetValue(MarginProperty, new Thickness(0, 30, 0, 0));
                onlyone = true;
            }
        }

 

        void btn1_Click(object sender, RoutedEventArgs e)
        {
            Border border = this.Children[2] as Border;
            TextBox txt = this.Children[0] as TextBox;
            Canvas can = border.Child as Canvas;
            Calendar calendar = can.Children[0] as Calendar;
            TimePicker timePicker = can.Children[1] as TimePicker;
            string time1 = "";
            string time2 = "";
            if (calendar.SelectedDate == null)
            {
                time1 = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                time1 = Convert.ToDateTime(calendar.SelectedDate).ToString("yyyy-MM-dd");
            }
            if (timePicker.Value == null)
            {
                time2 = DateTime.Now.ToString("HH:mm");
            }
            else
            {
                time2 = Convert.ToDateTime(timePicker.Value).ToString("HH:mm");
            }
            txt.Text = time1 + " " + time2;
            this.Children.RemoveAt(Children.Count - 1);
            onlyone = false;

     datatime = Convert.ToDateTime(txt.Text);
        }
    }
}

cs518800 | 园豆:343 (菜鸟二级) | 2013-05-22 17:13

自定义控件?

支持(0) 反对(0) 微风吹过12x | 园豆:73 (初学一级) | 2013-05-22 17:18
0

.

微风吹过12x | 园豆:73 (初学一级) | 2013-06-17 16:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册