none
自绘Combobox里的item白边 RRS feed

  • 问题

  •  

    如图,自绘Drop List模式的combobox,第一次显示正常,但在选择一个item后就会出现一个白边,请问怎么消除掉?谢谢!


    我是快乐的小鱼^_^
    2011年8月3日 2:27

全部回复

  • 可能是您自绘的DrawItem中处理的有问题吧~
    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    2011年8月3日 5:01
    版主
  • 查找了,没找到,纠结
    我是快乐的小鱼^_^
    2011年8月4日 5:23
  • 你好,

     

    您能否提供给我们一些实例代码,这样可以方便我们重现您的问题?

    我们期待您的回信,并乐意帮助您解决您的问题


    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年8月5日 6:02
  • void PngCombobox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
    	//绘制Item背景和字符串
    	Graphics graphics(lpDrawItemStruct -> hDC);
    	int curID = lpDrawItemStruct -> itemID;	
    	CRect itemTempRect( lpDrawItemStruct -> rcItem);
    	
    	Rect itemRect(itemTempRect.left, itemTempRect.top, itemTempRect.Width(), itemTempRect.Height());	//已选择项的Rect
    	Rect itemBgRect(itemRect);		//未选择项的Rect
    
    	if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
    		(lpDrawItemStruct->itemState & ODS_SELECTED))
    	{
    		graphics.DrawImage(_selectButtonImage, itemRect, BUTTON_CLICK * _listButtonW, 0, _listButtonW, _listButtonH, UnitPixel);
    	}
    	else
    	{
    		SolidBrush bgBrush(Color(80, 80, 80));
    		graphics.FillRectangle(&bgBrush, itemBgRect);
    		graphics.DrawImage(_listImage, itemBgRect, 0, 0, _listW, _listH, UnitPixel);
    	}
    
    	//绘制Item字符串
    	if((curID != -1) && _DrawChars)
    	{
    		Gdiplus::Font myFont(L"宋体", 10.0f);
    		PointF point( itemTempRect.left + 2.0f, itemTempRect.top + 2.0f);
    		SolidBrush whiteBrush(Color(200,200,200));
    
    		CString itemText;
    		GetLBText(curID,itemText);							//获取当前Item字符串
    		wstring witemText(itemText.AllocSysString());		//转换为wstring
    		graphics.DrawString(witemText.c_str(), -1, &myFont, point, &whiteBrush);
    	}
    }
    
    void PngCombobox::OnPaint()
    {
    	CPaintDC dc(this); 
    
    	Graphics graphics(dc.m_hDC);
    	
    	CRect rect;
    	GetClientRect(&rect);
    
    	graphics.DrawImage(_staticImage,Rect(0, 0, rect.Width(), rect.Height()),
    							_staticW * _State, 0, _staticW, _staticH, UnitPixel);
    
    	COMBOBOXINFO info;
    	info.cbSize = sizeof info;
    	GetComboBoxInfo(&info);
    	RECT ItemRect = info.rcItem;
    	Gdiplus::Font myFont(L"宋体", 10.0f);
    	PointF point( ItemRect.left + 2.0f, ItemRect.top + 2.0f);
    	SolidBrush whiteBrush(Color(200,200,200));
    
    	CString itemText;
    	GetLBText(GetCurSel(), itemText);
    	wstring witemText(itemText.AllocSysString());
    	graphics.DrawString(witemText.c_str(), -1, &myFont, point, &whiteBrush);
    }
    


     


    我是快乐的小鱼^_^
    2011年8月8日 2:57