1
我打算让DataGridViewComboboxCell显示类似于文本框的3D固定样式。我管理与使用此代码一个ComboBox做到这一点:在3d样式中显示DataGridViewComboBoxColumn
public Form1()
{
cmbbox.DrawMode = DrawMode.OwnerDrawFixed;
cmbbox.DrawItem += ComboBox_DrawItem_3DFixed;
}
private void ComboBox_DrawItem_3DFixed(object sender, DrawItemEventArgs e)
{
ComboBox cmb = sender as ComboBox;
e.DrawBackground();
if (e.State == DrawItemState.Focus)
e.DrawFocusRectangle();
var index = e.Index;
if (index < 0 || index >= cmb.Items.Count)
return;
var item = cmb.Items[index];
string text = (item == null) ? "(null)" : cmb.GetItemText(item);
using (var brush = new SolidBrush(e.ForeColor))
{
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString(text, e.Font, brush, e.Bounds);
}
}
不幸的是,我不知道如何使用的DataGridViewComboBoxCell做到这一点。芹苴我没有在这里找到一个解决方案:
public void Form1()
{
dgView.CellPainting += dgView_EditingControlShowing;
}
void dgView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is ComboBox)
{
ComboBox cb = (ComboBox)e.Control;
cb.DrawMode = DrawMode.OwnerDrawFixed;
cb.DrawItem += new DrawItemEventHandler(ComboBox_DrawItem_3DFixed);
}
}
但问题与此,它只会改变的DataGridViewComboBoxCell的外观点击特定的小区时,当它失去焦点,它返回到正常。
我找到了CellPainting事件,但我不知道它是如何工作的这段代码。谁能帮我?谢谢!
看起来不错,但有什么办法,我可以改变ControlPaint.DrawComboButton的外观,它看起来像是3D Fixed。 –
你希望它是3D。你不是吗? –
我其实想要在图像的顶部做外观,下面的是我得到的。 Image here:https://i.imgsafe.org/6467d94258.jpg –