2009-10-20 26 views
16

मैं नेट WinForms में एक स्प्लिट बटन की तलाश में हूँ। जिस तरह से एक तरफ एक बटन है और दूसरी तरफ एक ड्रॉपडाउन बटन है।स्प्लिट बटन

मैं उन्हें खिड़कियों में सब कुछ खत्म करते थे, खिड़की के रूप में दृश्य स्टूडियो में सहेजें की तरह देखते हैं, तो मैं समझ वे कुछ पुस्तकालय में नियंत्रण है मिल गया है।

मैं वहाँ TOOLSTRIPS के लिए एक है पता है, लेकिन मैं एक thats TOOLSTRIPS के बाहर प्रयोग करने योग्य की जरूरत है।

एक या अधिमानतः एक नि: शुल्क पुस्तकालय है कि किसी Microsoft पुस्तकालय है? मैं .NET 3.5

उपयोग कर रहा हूँ एक उदाहरण के लिए: Example Button

+0

हा, मुझे नहीं पता था कि छवि नेट एल से एक था:

this.BackgroundImageLayout = ImageLayout.None; this.BackgroundImage = YourResources.ButtonIcon; // Add padding so the text doesn't overlay the background image this.Padding = new Padding( this.Padding.Left + this.BackgroundImage.Width, this.Padding.Top, this.Padding.Right, this.Padding.Bottom); 

यहाँ कार्रवाई में मेरा एक बटन है ibrary। मैंने अभी विभाजन बटन पर एक Google छवि खोज की है और मैंने पाया कि सबसे अच्छा दिखने वाला विकल्प चुना है। – Jamiegs

उत्तर

4

आप एक सरल संस्करण स्वयं कर सकते हैं, बटन की छवि का उपयोग करते हुए। मेरे पास अपनी खुद की कक्षा है जो Button से ली गई है।

{ 
    this.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; 
    this.Image = YourResources.split_button; // Your down-arrow image 

    this.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage; 
} 


protected override void OnClick(EventArgs e) 
{ 
    var clickPos = this.PointToClient(new System.Drawing.Point(MousePosition.X, MousePosition.Y)); 

    // If click is over the right-hand portion of the button show the menu 
    if (clickPos.X >= (Size.Width - Image.Width)) 
     ShowMenuUnderControl() 
    else 
     base.OnClick(e); 
} 

// If you want right-mouse click to invoke the menu override the mouse up event 
protected override void OnMouseUp(MouseEventArgs mevent) 
{ 
    if ((mevent.Button & MouseButtons.Right) != 0) 
     ShowMenuUnderControl(); 
    else 
     base.OnMouseUp(mevent); 
} 

// Raise the context menu 
public void ShowMenuUnderControl() 
{ 
    splitMenuStrip.Show(this, new Point(0, this.Height), ToolStripDropDownDirection.BelowRight); 
} 

आप भी एक आइकन, ओ पी के रूप में, तुम इतनी तरह एक BackgroundImage और उचित गद्दी इस्तेमाल कर सकते हैं, चाहते हैं तो:

मैं छवि (नीचे तीर का है) तो तरह तैयार :
c# winforms split button with menu and arrow and icon

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