I am currently trying to make a program where I have a picture of a calendar and when the user clicks on any given Friday a message box will appear. The current method I have been trying to do this is by placing a button over the dates, but I can't seem to find a way so that the button will be invisible and functional at the same time.
This is all in C# Windows Forms Application.
Any ideas?
There are several solutions:
Use an empty PictureBox
instead of a Button
. This is the nearest and quickest solution to what you say you want. Note that this secondary PictureBox
needs to be a child of the calendar's one (with its background color set to Transparent
). Transparency in Windows.Forms only applies to direct parents (it's more complex than this, but let's simplify).
Use the MouseUp
event on the PictureBox
where you are showing the calendar, and use the MouseEventArgs
supplied as arguments to the event handler to find the X and Y position of the mouse within that control when the button was clicked.
Use a decent calendar/datepicker control instead of showing an image of one
Matter of fact: I don't endorse #1, and just put it there since it's what you seem to be asking for. I'd rather go with #2 or #3 (specially #3)
PS: if you want to really simulate Click
, you should need to handle both MouseDown
and MouseUp
(a click usually means pressing a mouse button down on a control then releasing it within the same control)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.