如何在Menustrip上更改Mousehover上的Toolstripmenuitem的前景颜色.. [英] How Do I Change The Fore Color Of Toolstripmenuitem On Mousehover On Menustrip..

查看:315
本文介绍了如何在Menustrip上更改Mousehover上的Toolstripmenuitem的前景颜色..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在win form应用程序的MenuStrip上更改MouseHover上的toolstripMenuItem的ForeColor?

请帮忙。

How can i change the ForeColor of toolstripMenuItem on MouseHover on MenuStrip in win form application?
Please help.

推荐答案

你可以使用MouseEnter& MouseLeave事件具有此类效果。

You can use MouseEnter & MouseLeave events to have such effects.
private void myToolStripMenuItem_MouseEnter(object sender, EventArgs e)
{
    ((ToolStripMenuItem)sender).ForeColor = Color.Blue; //new color
}

private void myToolStripMenuItem_MouseLeave(object sender, EventArgs e)
{
    ((ToolStripMenuItem)sender).ForeColor = Color.Gray; //original color
}





希望,它有帮助:)



参考:

https://msdn.microsoft.com/en- us / library / system.windows.forms.control.mouseenter%28v = vs.110%29.aspx [ ^ ]

https://msdn.microsoft.com/en-us /library/system.windows.forms.control.mouseleave%28v=vs.110%29.aspx [ ^ ]


这个问题表明对我来说你d了解C#.NET中事件和事件处理程序的基础知识。



您需要在设计时右键单击要修改其行为的控件,从菜单中选择属性,然后在属性浏览器中研究该控件的事件。您需要双击您感兴趣的列出的事件,然后观察/研究Visual Studio为您生成的EventHandler代码。



您需要阅读这些事件的文档。



除非您了解.NET C#应用程序设计和编码的这一基本方面,否则您将永远无法编写有用的代码。通过研究事件,您可以大致了解每个控件如何触发某些常见事件,例如MouseEnter,MouseMove,MouseLeave等。然后,对于特定类型的特定控件,如文本框和'RichTextBox(两者都继承自'TextBoxBase),你会明白其他控件不会分享特定的事件,比如'TextChanged。



好​​消息是:它并不难学!方法如下:



创建示例应用程序,在其中试验提供的控件及其Events / EventHandlers;在EventHanders中放置断点,当在运行时到达它们以响应您与控件的交互时,检查传递给EventHandler的EventArgs对象中的属性,字段,可用。
This question indicates to me you need to learn the basics of Events and EventHandlers in C# .NET.

You need to right-click at design-time on Controls you want to modify the behavior of, select 'Properties from the menu, and then study the Events in the Property Browser for that Control. You need to double-click those Events listed that interest you, and then go observe/study the EventHandler code generated for you by Visual Studio.

You need to read the documentation for those Events.

Unless you learn this fundamental aspect of .NET C# application design and coding, you will never be able to write useful code. By studying the Events, you can get a general sense of how, for every Control, certain common Events are triggered, such as 'MouseEnter, 'MouseMove, 'MouseLeave, etc. Then, for specific Controls of a certain Type, like 'Textbox and 'RichTextBox (both of which inherit from 'TextBoxBase), you will understand that there are specific Events other Controls do not share, like 'TextChanged.

The good news is: it's not that difficult to learn ! Here's how:

Create sample apps where you experiment with the provided Controls and their Events/EventHandlers; put break-points in the EventHanders and, when they are reached at run-time in response to your interacting with the Controls, inspect the Properties, Fields, available, in the EventArgs object passed to the EventHandler.


这是我越来越多地注意到的事情,并且它在开发论坛中相当稳定。这就是当某人提出问题时(无论他们的经验如何),答案似乎属于两个态度类别中的一个:



1.问题建议回答。

2.问题没有得到解答,而是对请求者的心态,经验和推理进行了严格审查。



根据我的经验,#2似乎是那些在论坛上拥有比排名更高'排名'的人的心态(即更多徽章,积分,声誉等)。



此外,通常(在他们的回复中的某个地方)跟随#2的人永远不会错过建议请求者在询问之前学习某事的机会。或者,更准确地说,通过询问问题,他们显然对他们想要完成的主题或任务一无所知。



我发现这有点讽刺,原因有两个。首先,通过研究和实践获得所有知识。例如,前者的一个例子就是阅读开发论坛(例如这个)。



第二个是当问到问题时知识的增长,并收到答案。例如,发布问题并从更有经验的同事那里获得答案,他们自己正在寻找答案,希望增长他们的知识(类似于周期性的合作伙伴关系)。



有什么讽刺意味?跟随#2的人很少给出答案,但大多数人总是提供批评。批评似乎各不相同,从编码风格到主题知识,再到他们使用的语法。始终是非建设性的批评。简而言之,他们提倡他们扼杀的东西。



对于那些遵循模式#2的人,我可以建议如下:



1.如果您不打算给出答案,或以建设性的方式接收答案,请不要回复帖子。

2.如果你心情不好,或者有一个糟糕的一天,并寻找一个车辆来发泄你的挫折..不要回复任何帖子。

3.如果你认为你在这里比大多数人都好,并且发现你被冒犯了一个菜鸟可能会问这样一个愚蠢的问题..不要频繁论坛请PLEASE。 />
4.如果您的论坛状态以某种方式授予您最高身份的礼物,并且您完全忘记了成为菜鸟的感觉..不要频繁参加该论坛。



最后(#5):如果你对主题的知识和一般的发展在某种程度上是基于你的概念获得的......那么我向你致敬,并羡慕你。我们其他人必须努力学习。



我的2美分价值。



和我的贡献(虽然是迟到的,但万一仍然需要):



使用自定义渲染器可以很好地完成请求者想要的操作。这是一个MSDN问题的链接,解释了如何:



https://social.msdn.microsoft.com/Forums / windows / en-US / 140096de-05d3-4d7e-8d4c-9f277bc72ddb / change-backcolor-and-forecolor-when-hovering-menu-items-of-menustrip?forum = winforms



祝你有美好的一天!
Here's what I've noticed more and more often, and it is fairly constant among development forums. And that is when a question is asked by someone (regardless of their experience) the answer seems to fall into one of two 'Attitude' categories:

1. The Question is answered with recommendations.
2. The Questions is not answered, but instead a critical review of the requester's mindset, experience, and reasoning is brought into review.

It's been my experience that #2 seems to be the mindset of those who hold a higher 'ranking' on the forum than the requester (i.e. More Badges, Points, Reputations, etc.).

Also, those that follow #2 usually (somewhere in their response) never miss the opportunity to advise the requester to 'Learn' something before asking. Or, more accurately, state that by asking the question they obviously know nothing about the subject matter or task in which they are trying to accomplish.

I find this somewhat ironic, for a couple of reasons. The first is that all knowledge is gained though research and practice. An example of the former would be, for instance, reading development forums (such as this).

The second is that the growing of knowledge comes when questions are asked, and answers are received. An example of this would be, for instance, posting a question and getting answers from more experienced colleagues who, themselves, are searching for answers in hopes to grow their knowledge (sort of a cyclical partnership thing).

What's ironic? The fact that those who follow #2 rarely give answers, but most always provide just criticism. And the criticism seems to vary, from coding style to subject knowledge to the grammar they use. Always non constructive criticism. In short, they are advocating the very thing they are stifling.

For those that follow pattern #2, may I suggest the following:

1. If your not going to give an answer, or a constructive way in which to receive an answer, don't reply to the posting.
2. If your in a bad mood, or are having a bad day, and looking for a vehicle to vent your frustrations.. don't reply to any post.
3. If you think you're better than most on here, and find you are offended that a noob could ask such a 'stupid' question.. don't frequent the forums PLEASE.
4. If your forum status has somehow granted you the gift of supreme being status, and you have completely forgotten what it was like to be a noob.. don't frequent THAT forum.

And lastly (#5): If your knowledge of the subject matter, and development in general, was somehow genetically obtained on your conception.. then I salute you, and envy you. The rest of us have to learn it the hard way.

My 2 cents worth.

And my contribution (albeit a late one, but just in case it's still needed):

There is a great way to do what the requester wants by using a custom renderer. Here's a link to an MSDN question that explains how:

https://social.msdn.microsoft.com/Forums/windows/en-US/140096de-05d3-4d7e-8d4c-9f277bc72ddb/change-backcolor-and-forecolor-when-hovering-menu-items-of-menustrip?forum=winforms

Have a great day all!


这篇关于如何在Menustrip上更改Mousehover上的Toolstripmenuitem的前景颜色..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆