private void CopyButtonInfo2MenuItem(ButtonEx_sms cmdButton, ToolStripItem tsmi) { if (cmdButton == null || tsmi == null) { return; } cmdButton.Tag = tsmi; tsmi.Image = cmdButton.Icon; tsmi.Text = cmdButton.Caption; tsmi.Enabled = cmdButton.Enabled; tsmi.Visible = cmdButton.Visible; tsmi.Tag = cmdButton; tsmi.Click += TsmiOnClick; cmdButton.EnabledChanged += delegate(object sender, EventArgs args) { var cSender = sender as ButtonEx_sms; if (cSender == null) { return; } if (cSender.Enabled) { var iconE = ServiceStationClient.Skin.SkinAssistant.GetResourcesImage( cSender.Name.Replace("btn", "") + "_E", true); var iconL = (windowStatus == WindowStatus.Add || windowStatus == WindowStatus.Edit) ? ServiceStationClient.Skin.SkinAssistant.GetResourcesImage( cSender.Name.Replace("btn", "") + "_L", true) : null; cSender.Icon = iconL ?? iconE; } else { cSender.Icon = ServiceStationClient.Skin.SkinAssistant.GetResourcesImage( cmdButton.Name.Replace("btn", "") + "_D", true); } if ((cSender.Tag as ToolStripItem) != null) { (cSender.Tag as ToolStripItem).Enabled = cSender.Enabled; } }; cmdButton.VisibleChanged += delegate(object sender, EventArgs args) { var cSender = sender as ButtonEx_sms; if (cSender != null && (cSender.Tag as ToolStripItem) != null) { (cSender.Tag as ToolStripItem).Visible = cSender.Visible; } }; cmdButton.TextChanged += delegate(object sender, EventArgs args) { var cSender = sender as ButtonEx_sms; if (cSender != null && (cSender.Tag as ToolStripItem) != null) { (cSender.Tag as ToolStripItem).Text = cSender.Text; } }; }
public void AddToolStripItem(ButtonEx_sms button) { if (!tlp_command.Controls.Contains(button)) { return; } var tsmi = new ToolStripMenuItem { Name = "tsmi" + button.Name, Size = new System.Drawing.Size(165, 22), }; CopyButtonInfo2MenuItem(button, tsmi); cms_Function.Items.Add(tsmi); }