2010-01-19 14 views
16

मेरे पास टूलस्ट्रिप बटन है जिसका उपयोग रेडियो बटन के रूप में किया जाता है। जब यह चेक किया जाता है, तो नीली रूपरेखा बटन को घेरती है, लेकिन पृष्ठभूमि का कोई रंग नहीं है। यह उपयोगकर्ता के लिए पर्याप्त स्पष्ट नहीं है कि बटन चेक किया गया है, इसलिए मैं चेक स्थिति को और अधिक दृश्यमान बनाने के लिए पृष्ठभूमि रंग बदलना चाहता हूं।जांचने पर System.Windows.Forms.ToolStrip बटन हाइलाइट/पृष्ठभूमि रंग कैसे बदलें?

चेक किए गए प्रॉपर्टी को सही होने पर हाइलाइट रंग बदलने के बारे में मैं कैसे जा सकता हूं?

कोड स्निपेट है:

this.hideInactiveVehiclesToolstripButton.CheckOnClick = true; 
     this.hideInactiveVehiclesToolstripButton.ForeColor = System.Drawing.Color.Blue; 
     this.hideInactiveVehiclesToolstripButton.AutoSize = false; 
     this.hideInactiveVehiclesToolstripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 
     this.hideInactiveVehiclesToolstripButton.Image = global::ClientUI.Properties.Resources.toggleInactive; 
     this.hideInactiveVehiclesToolstripButton.ImageTransparentColor = System.Drawing.Color.Black; 
     this.hideInactiveVehiclesToolstripButton.Name = "hideInactiveVehiclesToolstripButton"; 
     this.hideInactiveVehiclesToolstripButton.Size = new System.Drawing.Size(48, 48); 
     this.hideInactiveVehiclesToolstripButton.Text = "Hide Inactive Vehicles"; 
     this.hideInactiveVehiclesToolstripButton.Click +=new System.EventHandler(this.hideInactiveVehiclesToolstripButton_Click); 

उत्तर

36

आप बटन की पृष्ठभूमि जिस तरह से आप चाहते हैं उन्हें आकर्षित करने के लिए अपने स्वयं के उपकरण पट्टी रेंडरर प्रदान कर सकते हैं। यह उदाहरण कोड चेक बटन को एक बहुत ही दृश्यमान काला पृष्ठभूमि देता है:

public partial class Form1 : Form { 
    public Form1() { 
     InitializeComponent(); 
     toolStrip1.Renderer = new MyRenderer(); 
    } 
    private class MyRenderer : ToolStripProfessionalRenderer { 
     protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { 
      var btn = e.Item as ToolStripButton; 
      if (btn != null && btn.CheckOnClick && btn.Checked) { 
       Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size); 
       e.Graphics.FillRectangle(Brushes.Black, bounds); 
      } 
      else base.OnRenderButtonBackground(e); 
     } 
    } 
} 
+0

बहुत सराहना की! – mwalsher

संबंधित मुद्दे