如何找到ContextMenuStrip的父控件 [英] How to find the Parent Control of a ContextMenuStrip

查看:715
本文介绍了如何找到ContextMenuStrip的父控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的问题是我有一个contextmenustrip,它由表单上的多个按钮使用,并且contextmenustrip具有contextmenustripitems,它们调用自定义按钮外观的方法,例如字体,前景色和背景色.

问题是我试图获取已调用contextmenustrip的按钮.这样做的原因是,我可以通过向当前按钮提供将进行这些更改的方法作为参数,然后将颜色或新字体应用于已打开contextmenustrip的按钮.

我真的不知道该怎么做,因此不胜感激:)

Hi all,

My problem is that I have a contextmenustrip that is used by multiple buttons on a form and the contextmenustrip has contextmenustripitems, that call methods that customize the look of a button, for instance the font, fore and back colour.

The problem being is that I am trying to get the button that the contextmenustrip has been called on. The reason for this is so that I can then apply the colour or new font to the button that has had the contextmenustrip opened on, by supplying the current button the method that will make these changes, as an argument.

I don''t really know how I would go about doing this so any help is much appreciated :)

推荐答案

您可以从打开活动期间的上下文菜单.

这是VB.net代码,尚未检查C#等效项.

You can determine this from the SourceSource control property of the Context menu during the opening event.

This is the VB.net code, haven''t checked for the C# equiv.

Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

    Debug.WriteLine(ContextMenuStrip1.SourceControl.ToString)

End Sub


这篇关于如何找到ContextMenuStrip的父控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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