2011-06-12 7 views
6

जब कॉम्बोबॉक्स की ड्रॉपडाउन स्टाइल ड्रॉपडाउनलिस्ट और ड्रामोड सामान्य है - यह अच्छा लग रहा है, लेकिन जब मैं ड्रॉमोड को मालिक के लिए बदलता हूं - यह बहुत बुरा लगता है (ड्रॉपबॉक्स के समान टेक्स्टबॉक्स के समान) । क्या DrawMode सामान्य नहीं होने पर यह अच्छा दिखने का कोई समाधान है?मेरा कॉम्बोबॉक्स खराब दिखता है जब उसका ड्रॉमोड सामान्य नहीं है

कि तरह लग रहा है: looks like that

मैं इसे उस तरह लग रहे हैं: I want it to look like that

उत्तर

1

मुझे solutio मिला एन वीबी में यहां: how-to-make-a-custom-combobox-ownerdrawfixed-looks-3d-like-the-standard-combobo टेक्स्ट और तीर ड्राइंग के लिए कुछ कोड जोड़ा गया। यह काम करता है :)

class MyComboBox: ComboBox 
{ 
    public MyComboBox() 
    { 
     this.SetStyle(ControlStyles.Opaque | ControlStyles.UserPaint, true); 
     Items.Add("lol"); 
     Items.Add("lol2"); 
    } 

    protected override void OnPaint(PaintEventArgs e) 
    { 
     if (DroppedDown) 
      ButtonRenderer.DrawButton(CreateGraphics(), new System.Drawing.Rectangle(ClientRectangle.X - 1, ClientRectangle.Y - 1, ClientRectangle.Width + 2, ClientRectangle.Height + 2), PushButtonState.Pressed); 
     else 
      ButtonRenderer.DrawButton(CreateGraphics(), new System.Drawing.Rectangle(ClientRectangle.X - 1, ClientRectangle.Y - 1, ClientRectangle.Width + 2, ClientRectangle.Height + 2), PushButtonState.Normal); 
     if (SelectedIndex != -1) 
     { 
      Font font; 
      if (SelectedItem.ToString().Equals("lol")) 
       font = new Font(this.Font, FontStyle.Bold); 
      else 
       font = new Font(this.Font, FontStyle.Regular); 
      e.Graphics.DrawString(Text, font, new SolidBrush(Color.Black), 3, 3); 
     } 
     if (DroppedDown) 
      this.CreateGraphics().DrawImageUnscaled(new Bitmap("c:\\ArrowBlue.png"), ClientRectangle.Width - 13, ClientRectangle.Height - 12); 
     else 
      this.CreateGraphics().DrawImageUnscaled(new Bitmap("c:\\ArrowGray.png"), ClientRectangle.Width - 13, ClientRectangle.Height - 12); 
     base.OnPaint(e); 
    } 

मैं झिलमिलाहट को निकालने का तरीका जब माउस में प्रवेश और ComboBox जा रहा है पता नहीं है। जब डबलबफरिंग सक्षम है, कॉम्बोबॉक्स काला है। लेकिन मेरे लिए ठीक काम करता है।

+0

क्या आपको किसी भी मौके से पता चला कि अब इस झटके को कैसे हटाया जाए? – Otiel

+0

'CreateGraphics' पर आपकी लगातार कॉल GDI संसाधनों को रिसाव कर देगी। आपको 'उपयोग' विधि को कॉल करने के लिए '() 'ब्लॉक में लिपटे एक एकल' ग्राफिक्स 'ऑब्जेक्ट का उपयोग करना चाहिए। – Dai

0

जब आप इसे OwnerDrawFixed को बदलने के लिए, आप अपने आप को ड्राइंग संभाल चाहिए

 private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) 
       { 
        //Wrtie your code here 
    e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), this.Font, Brushes.Black,e.Bounds); 
e.DrawBackground(); 

       } 

इस लिंक को देख ComboBoxRenderer Class

+0

ठीक है, मैंने अपनी पोस्ट संपादित की और e.DrawBackground() जोड़ा; – DeveloperX

+0

इस मामले में मुझे लगता है कि आपको DropDownStyle को ComboBoxStyle में बदलना चाहिए। DropDownList – DeveloperX