当用户登录到Windows时,ToolStripButton从PropertyGrid中消失
本文关键字:ToolStripButton PropertyGrid 消失 用户 登录 Windows | 更新日期: 2023-09-27 18:10:07
我有一个问题,场景如下:
我用一个组件PropertyGrid
创建了用户控件。对于这个PropertyGrid
,我添加了按钮(十六进制模式)到PropertyGrid的ToolStrip
。一切都很好,工作得很好!
但是当这个控件显示在表单中,用户按下"Windows->Switch User"
并再次以相同的用户名登录我的按钮(十六进制模式)消失。另外,手动隐藏的第四个按钮出现了…
Windows 7 (x64/x86)
public partial class CompProperty : UserControl
{
private System.Windows.Forms.ToolStripButton _tsbMode = null;
public CompProperty()
{
InitializeComponent();
createAdditionalButtons();
}
private void createAdditionalButtons()
{
foreach ( Control control in propertyGrid.Controls )
{
ToolStrip toolStrip = control as ToolStrip;
if ( toolStrip != null )
{
toolStrip.Items[4].Visible = false;
_tsbMode = new System.Windows.Forms.ToolStripButton();
_tsbMode.CheckOnClick = true;
_tsbMode.Checked = true;
_tsbMode.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
_tsbMode.Image = Resources.img_edit;
_tsbMode.ImageTransparentColor = System.Drawing.Color.Magenta;
_tsbMode.Name = "tsbMode";
_tsbMode.Size = new System.Drawing.Size( 23, 22 );
_tsbMode.Text = "Heximal Mode";
_tsbMode.ToolTipText = "Heximal Mode";
toolStrip.Items.AddRange( new System.Windows.Forms.ToolStripItem[] {
_tsbMode} );
break;
}
}
}
}
是的,这是设计。PropertyGrid类在SystemEvents。UserPreferencesChange事件触发。这确实很可能在桌面交换机上触发。你可以像这样修补它:
using System;
using System.Windows.Forms;
class MyPropertyGrid : PropertyGrid {
protected override void OnSystemColorsChanged(EventArgs e) {
// Do nothing
}
}
当然不理想。冷酷无情的事实是,这根本不被支持。