如何使用c#在messagebox上显示DateTimePicker控件?
是否可以在messagebox上显示DateTimePicker控件以在控制台应用程序中选择日期。不在标准messagebox上。您需要创建自己的表单来显示如何使用c#在messagebox上显示DateTimePicker控件?,c#,windows,datetime,C#,Windows,Datetime,是否可以在messagebox上显示DateTimePicker控件以在控制台应用程序中选择日期。不在标准messagebox上。您需要创建自己的表单来显示 `public MyClass() { // Create a new DateTimePicker DateTimePicker dateTimePicker1 = new DateTimePicker(); Controls.AddRange(new Control[] {dateTimePicker1}); Message
`public MyClass()
{
// Create a new DateTimePicker
DateTimePicker dateTimePicker1 = new DateTimePicker();
Controls.AddRange(new Control[] {dateTimePicker1});
MessageBox.Show(dateTimePicker1.Value.ToString());
dateTimePicker1.Value = DateTime.Now.AddDays(1);
MessageBox.Show(dateTimePicker1.Value.ToString());
}
`
这是访问消息框中的日期选择器控件的方法
你到底做了什么?您能更详细地解释一下这个要求吗?
MessageBox
是一个方便的功能。这种便利是以定制为代价的<代码>消息框不提供向其中添加自己控件的方法;您必须创建自己的表单
请注意,即使在控制台应用程序中,您仍然可以创建windows窗体。我知道现在很晚了,但如果有人正在研究如何创建窗体。使用CustomMessageBox代替MessageBox。教程可以找到
您不能添加模式表单吗?我使用的是控制台应用程序,而不是windowsapplication@KiranReddy然后您应该使用控制台输入让用户输入日期。
TimePicker timePicker = new TimePicker()
{
Margin = new Thickness(0, 10, 0, 10)
};
StackPanel myStackPanel = new StackPanel();
myStackPanel.Orientation = System.Windows.Controls.Orientation.Vertical;
myStackPanel.Children.Add(timePicker);
//Create a new custom message box
CustomMessageBox messageBox = new CustomMessageBox()
{
Content = myStackPanel,
LeftButtonContent = "Ok",
RightButtonContent = "Cancel",
IsFullScreen = false
};
messageBox.Show();