简体   繁体   English

如何使按钮不可见但仍能正常工作?

[英]How do I make a button invisible but still functional?

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. 这一切都在C#Windows窗体应用程序中。

Any ideas? 有任何想法吗?

There are several solutions: 有几种解决方案:

  1. Use an empty PictureBox instead of a Button . 使用空的PictureBox代替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 ). 请注意,该第二个PictureBox必须是日历中的子PictureBox (背景颜色设置为Transparent )。 Transparency in Windows.Forms only applies to direct parents (it's more complex than this, but let's simplify). Windows.Forms中的透明度仅适用于直接父级(比这更复杂,但让我们简化一下)。

  2. 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. 使用要显示日历的PictureBox上的MouseUp事件,并使用作为事件处理程序的参数提供的MouseEventArgs在单击按钮时在该控件内查找鼠标的X和Y位置。

  3. 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. 事实:我不赞成#1,只是把它放在那儿,因为这似乎是您要的。 I'd rather go with #2 or #3 (specially #3) 我宁愿选择2号或3号(特别是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) PS:如果您想真正模拟Click ,则需要同时处理MouseDownMouseUp (单击通常意味着在控件上按下鼠标按钮,然后在同一控件内释放它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM