dateTimePicker - remove highlight

I am using a dateTimePicker control in a windows app using c#. I am only interested in getting & passing on the month & year, so I have enabled the up/down buttons, and I use a custom format to display the month & year (MMMM  '-' yyyy). It works great functionally - does exactly what I want. However, when it displays the month and year (like this:   March - 2011) it piuts a blue background (highlight) around the month name. Although it works perfectly, it looks very odd. Clicking or double-clicking on the highlighted month name has no effect - the contents are read-only. There are a number of properties associated with color for the control (CalendarForeColor, CalendarMonthBackground, etc) but they have no effect - probably because I'm actually disabling the calendar part. I have also tried setting them in code, again, with no effect.

Not a huge deal, the thing still works, after all, but it would look a lot better if I could disable or control this background highlighting.
bassman592Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kdwoodCommented:

Sounds like the blue highlight on the month is due to the DateTimePicker having focus.   Try adding this to your DateTimePicker ValueChanged event:

Me.Focus()

Regards,

Keith
0
bassman592Author Commented:
I added this:

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            Me.Focus();
            btnExportToExcel.Enabled = true;
            btnExportToPowerPoint.Enabled = true;
        }

But it gives me the error:
"The name 'Me' does not exist in the current context"

Also, the highlight appears as soon as the form is displayed, before the user selects anything.
0
kdwoodCommented:

Sorry, I'm not a C# coder, but I believe you need to use:

this.Focus() instead of Me.Focus

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

bassman592Author Commented:
good catch!

Well, it doesn't complain, but it also doesn't remove the highlight - either at the start, or after I click the up/down arrows for different months.

Does it do this in VB?
0
kdwoodCommented:
Yes, it worked in VB.  I'll try in C# a little later.  On the road now.
0
kdwoodCommented:
bassman,

Very interesting!   The reason why it worked for me was because I did not have the ShowUpDown property set to True on the DateTimePicker.   As soon as I set that to True, my suggestion above no longer worked.

The only work around that I can find, which is a bit of a bandaid, is to put a blank label on your form and set focus to it in the ValueChangedEvent.

I not a fan of this approach, but I seem to find a better way.   Perhaps another expert has an idea.

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
       
        {
            label1.Focus();
            btnExportToExcel.Enabled = true;
            btnExportToPowerPoint.Enabled = true;
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bassman592Author Commented:
Great idea! However, it works a little differently than you described. First, I tried what you suggested, using a label, but it didn't work. BTW, in all of these experiments, I'm using the Form's Load event instead of the control's ValueChanged event, since the highlight appears right off the bat. After trying the label, I tried palying with the tabindex property. Unfortunately, the dateTimePicker and the blank label (I was actually already using one) are the only 2 controls that are both visible and enabled, and for this to work, they both have to be true. Basically, I found that it works only if the "dummy" control is visible, enabled, and is a control that accepts some type of input - like a button, or a text box. Not a label, or a panel. So what I did was create a dummy button, make it really small, then I positioned it over the dateTimePicker control and changed its order to "send to back". So although it was visible and enabled, it still wouldn't be seen (or used). Then I made its tabindex = 0, and it works perfectly! As you said, not ideal, but it works. Also, I found that setting it's focus in code has no effect - you have to set the tabindex (although I guess you could do THAT in code). But the basic idea is yours, so I'm accepting your answer as the solution. Thank you.
0
bassman592Author Commented:
Good out-of-the-box thinking!
0
kdwoodCommented:

Glad you got it working.  Thanks for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.