winForm下拉框相关的问题,估计有点难

愚痴鱼 2008-11-24 04:43:36
comboBox的下拉框里有很多个选项,当鼠标在这些选项上移动时(不是选择了该项),将当前项的值显示在一个标签上。
例如有“AAA”“BBB”两个选项,鼠标移到“AAA”时,标签就显示AAA,移到“BBB”时就显示BBB。

急。一有答案立即给分;

注:本人结帖率100%
...全文
350 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
愚痴鱼 2008-11-25
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 bossma 的回复:]
这个可以

C# code
private void moveComboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
//Console.WriteLine(e.State.ToString());

if (e.State == DrawItemState.Selected)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Beige), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));

[/Quote]

很好很强大,接分!
mjjzg 2008-11-24
  • 打赏
  • 举报
回复
可以在MouseEnter 里写
也可以用JS来的onMouseOver(鼠标悬停)来做
萤火架构 2008-11-24
  • 打赏
  • 举报
回复
这个可以

private void moveComboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
//Console.WriteLine(e.State.ToString());

if (e.State == DrawItemState.Selected)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Beige), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
label1.Text = moveComboBox1.Items[e.Index].ToString();
}
else if (e.State == DrawItemState.None)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
}

e.Graphics.DrawString(moveComboBox1.Items[e.Index].ToString(), moveComboBox1.Font, new SolidBrush(Color.Black), 2, e.Bounds.Y + 2);
}
萤火架构 2008-11-24
  • 打赏
  • 举报
回复
将DrawMode 设置为OwnerDrawFixed
然后绑定DrawItem事件

能获得鼠标移动到的项,但是没有解决重画的问题 楼主可以参考下


private void moveComboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
//Console.WriteLine(e.State.ToString());

if (e.State == DrawItemState.Selected)
{
e.Graphics.FillRectangle(SystemBrushes.MenuHighlight, new RectangleF(1, 1, e.Bounds.Width - 1, e.Bounds.Height - 1));
label1.Text = moveComboBox1.Items[e.Index].ToString();
}

if (e.State == DrawItemState.None)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), new RectangleF(1, 1, e.Bounds.Width - 1, e.Bounds.Height - 1));
}

e.Graphics.DrawString(moveComboBox1.Items[e.Index].ToString(), moveComboBox1.Font, SystemBrushes.ControlText, 2, e.Bounds.Y + 2);
}
fengyupeng 2008-11-24
  • 打赏
  • 举报
回复
楼主 是不是第二帖了;
前一帖我也回答了这个问题
fengyupeng 2008-11-24
  • 打赏
  • 举报
回复
MouseEnter
事件
fengyupeng 2008-11-24
  • 打赏
  • 举报
回复
MouseEnter
里去实现
愚痴鱼 2008-11-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 djc7811 的回复:]
可以用ToolTip这个控件实现
[/Quote]

当鼠标在下拉框的选项上移动时,会触发什么事件呢?如果有事件,接着使用ToolTip倒像是可以
dai78 2008-11-24
  • 打赏
  • 举报
回复
可以用ToolTip这个控件实现
EsMo 2008-11-24
  • 打赏
  • 举报
回复
dx控件可以实现popupContainerControl可以实现...
zcl26 2008-11-24
  • 打赏
  • 举报
回复
没做过这样的问题,但是这个应该不难,楼主百度一下,应该会有答案吧
MicroDeviser 2008-11-24
  • 打赏
  • 举报
回复
顶~~~~~~~

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧