views:

165

answers:

3

Hello everybody,

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).

A: 

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 .

Scott Fox
The problem is I didn't find a way to access the button directly. There is nothing like DateTimePicker.Button etc.When performing DateTimePicker.Controls.Count it's 0.
Inno
A: 

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.

GvS
A: 

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.

Josh Smeaton