I want to add a tooltip to the DateTimePicker Calendar that show some informations based on the date that the mouse is over. Is there a way to retrive the date under the mouse without clicking it?
The native Windows DTP control is quite primitive. It doesn't support anything like HitTest() as supported by ListView and TreeView. Trying to guess where the mouse is located from the mouse position is dangerous, DTP is sensitive to format overrides in the Control Panel's Region settings. Don't try to make this work.
Are you talking about the Calendar control (AFAIK there is no DateTimePicker built into WPF as it stands).
See the section Replacing the CalendarItem Template in the article below: you can add your ToolTip there, right in the control.
http://msdn.microsoft.com/en-us/magazine/dd882520.aspx
It shows a calendar with phases of the moon, modified to look like a planner: very customisable!
Edit: Obviously I should say, there is source code included.
Hope that helps!
Related
Is it possible to change the color of dateTimePicker if I change date in Calendar?
Maybe not a direct answer (certainly a belated one):
I always take the DateTimePicker control and place it docked (fill) inside a Panel. I make sure the panel has at least a padding of 1 (on all sides). Then, if I need to change the background color or to simulate a border color change, I do it on the surrounding panel instead of the DateTimePicker control directly.
My use case is to simulate when the control is invalid, i.e. put a Color.Red border on the surrounding panel if the date field in question is required.
There is not a property for changing Backgroundcolor change property but There are several properties that allows you to customize the appearance and behavior of the DateTimePicker control.
If you are using Windows Vista or Windows 7 and using themes such as Aero, then the properties that modifies the color of the calendar has no effect. To see the results of changing the colors of the calendar, we need to disable Visual Styles. For the sake of demonstration, we will do just that. Find Program.cs in the solution explorer and open it by double clicking it. Comment out or delete the line:
Application.EnableVisualStyles();
For more information use this The DateTimePicker Control
You didn't show any effort but..
DateTimePicker class has ValueChanged event that occurs when the Value property changes.
It is not clear which color that you want to change but you can use CalendarMonthBackground or CalendarForeColor properties that you can use with it.
private void DateTimePicker1_ValueChanged(Object sender, EventArgs e)
{
//
}
Looks like changing BackColor or ForeColor properties has no effect on current control. In such a case, general recommendation is like; you have to render it yourself and this can be really hard. Solution on Changing the background color of a DateTimePicker in .NET probably will not work either.
Also there is thread on MSDN forum that uses a custom control inherited from DateTimePicker .
I am developing an app for Windows Phone 7.8 (probably WP8 at a later date) that needs the user to enter a date. I am currently using the DatePicker control from the Silverlight Toolkit as I like the visual style of it.
The DatePicker control, when placed on the page, is shown as a TextBox that when clicked opens the DatePicker.
Is there anyway to not have the TextBox included as I do not need and it is cluttering up my form. Maybe a way to open the DatePicker through code rather than trough the OnClick event?
Any help is appreciated :)
You can simply edit the Control Template of the DatePicker to change the way it looks.
VS 2012 can do this by default (right click and edit template), else you will need to edit the template using Expression Blend.
In particular, the Control Template consists of a Button (among other things):
<Button x:Name="DateTimeButton"
Content="{TemplateBinding ValueString}"
...
The Buttons Content property is bound to ValueString. If you remove this Binding (for example) you will be left with a blank button. You could put anything you like in the content of the button...
These links should help you get started with using Blend:
Styling a control that supports templates
Create or modify a template
The guides on Project Rosetta are nice too.
may be, you can create the DatePicker and hiden it.
when you click item (item which you want to use), you change focus to DatePicker.
I think that you can instantiate the DatePickerPage object and navigate to it. As I understand it has a Value property (coming from the IDateTimePickerPage interface) which you can set and read.
I cannot test it at today but I will definitely try it tomorrow and let you know what I found. Meantime you can go to the http://silverlight.codeplex.com/ page and check the source of the Toolkit.
What is the event that should trigger the opening of the datepicker page? Is it a click or tap on a button, an image or what?
If it is any of these, you could place a DatePicker in xaml over that control so that they overlap (placing them in a grid's same row, same column). Set the Opacity of the DatePicker to 0. Then the user will not see the DatePicker's TextBox, just the control below it. However, when the user clicks on that control (button, image, etc), he or she will in fact click on the invisible DatePicker and then the datepicker page will open up.
Currently i developing a WPF application. My application allow user to select any date from the datepicker and data from the selected date will show up. However, user is not allow to select any specific time from the datepicker. The output from the datepicker will be something like 02-dec-2012 12:00:00 AM. The time from the datepicker will always be 12:00am. So, how can i allow user to alter the time?
I found some resource from DateTimePicker, but i looking for another solution. Any advice? Thanks
WPF DatePicker doesn't support time selection or display. It only supports Date picking.
A simple workaround is to use several TextBox controls and bind their Text property to a DateTime data source to allow the user to see and change the time.
For more information about DataBinding, please refer to http://msdn.microsoft.com/en-us/library/ms752347.aspx.
If you want to add time picking feature to DatePicker, you will need to introduce custom control.
For more information about Custom Control, please refer to http://msdn.microsoft.com/en-us/library/ms745025.aspx.
Source
you can also take a look at the following example for how to do this: Example Project
I am trying to develop a custom radio button that looks like a two-option button control that looks somewhat as shown below with toggling of highlighted state. Not sure where to start.
Is there any such controls already available that I can use.
OK, here is a brief overview of what you will need to do ...
Firstly, you will need to change the ControlTemplate for the existing RadioButton control. There are lots of tutorials available that describe this,, for example this one.
Replace the standard template with some suitable markup for your illustration above. Perhaps a two column Grid?
Within each Grid cell add a Rectangle, one behind Option1, and the other behind Option2
Use the VisualStateManager to change the Fill property of each Rectangle based on the controls current VisualState. i.e. when Pressed toggle the background colours.
The steps above should help you achieve your goal. Please read the linked web pages and the Silverlight documentation. If you are still struggling after that,, come back and ask another question.
I implemented a custom DateTimePicker. On the DateTimePicker there is a button. In the examples I've found it's width is set to 16. This is working but I would like to have a dynamic approach.
So, is there a way to get the size of this button or is there a general way to get information about .Net-Control sub elements like size etc.?
Trying DateTimePicker.Controls didn't help me (it's empty).
Most all Win32 arrow buttons key off the scroll bar metric:
You want SystemInformation.VerticalScrollBarArrowHeight
Two helpful classes: SystemInformation and ControlPaint. When dealing with custom controls they can be invaluable.
Int32 size = SystemInformation.VerticalScrollBarArrowHeight;
ControlPaint.DrawScrollButton(e.Graphics, 0, 0, size, size, ScrollButton.Down, ButtonState.Normal);
All windows forms controls have a struct assigned to them called "Size" if you refer to the myButton.Size.Width you should be able to modify the size of the button which is an int. Conversely you can do the same with myButton.Size.Height .
The DateTime picker uses the native Windows controls. The "button" you mention is something that is drawn by Windows itself.
In your current OS, there might be something that resembles a button, but in an old or future OS the DateTime picker might be completely different.
Just draw your control the nicest and easiest for the user, and they will be happy.
Can you post the code for the DateTimePicker that you've implemented? It might help illustrate your exact problem. By the sounds of it, the button isn't contained within the DateTimePicker, but on the form adjacent to it. Please correct me if I'm wrong.
So, if you had the following:
DateTimePicker dtp = new DateTimePicker();
Button btn = new Button();
btn.Size.Width = btn.Size.Width * 2;
You can access and re-set the size of the button control.
If the button really is contained within the DateTimePicker, then expose it as a public property (or ideally an internal property), and access it directly via the DTP.