C#控件闪烁

乖紫 2012-11-02 11:52:43
一个PictureBox,在鼠标移动到它上边时改变它的边框样式,但是它会闪烁,怎么才能不让它闪烁。求高手解答。
...全文
315 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
PiKaQiuPiKaPi 2014-04-09
  • 打赏
  • 举报
回复
楼主解决了么,我也有闪烁的情况
ck467007978 2012-11-02
  • 打赏
  • 举报
回复
弱弱的说下:其实当窗体内容过多时,每次执行事件重绘时加载比较慢,就会造成LZ说的闪的问题。关注ing。
  • 打赏
  • 举报
回复
没有真相,普通处理不会有闪烁,难道你refresh了画面?
XBodhi. 2012-11-02
  • 打赏
  • 举报
回复
还有一个方式, timer 间隔换图片。


Timer timer = new Timer(1000);
timer.Enable = true;

time.Tick += ssssssss;


void ssssssss(o,e)
{
if(xxxx)
{}
else

{}
}

的方式就一直在换了,
安得权 2012-11-02
  • 打赏
  • 举报
回复
QQ 465631791 你加我,发来看看
乖紫 2012-11-02
  • 打赏
  • 举报
回复
求联系方式。
乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]

不知道 代码 什么情况

建议你 每个事件 前都打个 断点

看 是不是 有事件一直在执行

就算是在重绘,它也得有代码在一直 执行不是
[/Quote]

你不知道吗,一个窗体放的控件特别多(带背景图像),显示的时候就会闪
乖紫 2012-11-02
  • 打赏
  • 举报
回复
class CustomControl:TableLayoutPanel
{
#region
/// <summary>
/// 显示名称
/// </summary>
public string ItemName
{
get
{
return this.Controls[1].Text;
}
set
{
label.Text = value;
}
}
/// <summary>
/// 项目的执行路径
/// </summary>
public string ItemPath;
/// <summary>
/// 在主面板上的索引
/// </summary>
public int OverallIndex;
public DelItem del;

Label label;
TextBox tbox;
#endregion

public CustomControl(StartItem item,int index)
{
ItemPath = item.Path;
OverallIndex = index;

PictureBox pic = new PictureBox();
label = new Label();
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem MenuItemOpenDir = new ToolStripMenuItem("打开文件位置");
ToolStripMenuItem MenuItemReName = new ToolStripMenuItem("重命名");
ToolStripMenuItem MenuItemDel = new ToolStripMenuItem("删除");
MenuItemOpenDir.Click += new EventHandler(ItemOpenDir_Click);
MenuItemReName.Click += new EventHandler(ItemReName_Click);
MenuItemDel.Click += new EventHandler(ItemDel_Click);

menu.BackColor = Color.Silver;
menu.Font = new System.Drawing.Font("微软雅黑", 10);
menu.ShowImageMargin = false;
menu.Items.AddRange(new ToolStripItem[] { MenuItemOpenDir, MenuItemReName, MenuItemDel });
this.ContextMenuStrip = menu;
this.BackColor=Color.Transparent;
this.RowCount = 2;
this.ColumnCount = 1;
this.RowStyles.Add(new RowStyle(SizeType.Percent, 75F));
this.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));

pic.Anchor = AnchorStyles.None;
pic.BackColor = Color.Transparent;
pic.Size = new System.Drawing.Size(51, 50);
pic.SizeMode = PictureBoxSizeMode.StretchImage;
pic.TabStop = false;
pic.Image = item.icons[0].ToBitmap();
pic.MouseLeave += new EventHandler(pic_MouseLeave);
pic.MouseDown += new MouseEventHandler(pic_MouseDown);
pic.MouseUp += new MouseEventHandler(pic_MouseUp);
pic.MouseEnter += new EventHandler(pic_MouseEnter);

label.Anchor = AnchorStyles.None;
label.BackColor = Color.Transparent;
label.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
label.Size = new Size(100, 15);
label.Text = item.Name;
label.TextAlign = ContentAlignment.MiddleCenter;
this.Controls.Add(pic);
this.Controls.Add(label);

}

void pic_MouseEnter(object sender, EventArgs e)
{
((PictureBox)this.Controls[0]).BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
}

void ItemDel_Click(object sender, EventArgs e)
{
del(OverallIndex);
}


void ItemOpenDir_Click(object sender, EventArgs e)
{
Process.Start(@"Explorer", "/select," + ItemPath);
}

void pic_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
((PictureBox)this.Controls[0]).BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
Process.Start(ItemPath);
}
}

void pic_MouseDown(object sender, MouseEventArgs e)
{
((PictureBox)this.Controls[0]).BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
}
void pic_MouseLeave(object sender, EventArgs e)
{
((PictureBox)this.Controls[0]).BorderStyle = System.Windows.Forms.BorderStyle.None;
}
}
安得权 2012-11-02
  • 打赏
  • 举报
回复
不知道 代码 什么情况

建议你 每个事件 前都打个 断点

看 是不是 有事件一直在执行

就算是在重绘,它也得有代码在一直 执行不是
乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

C# code

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
PictureBox temp = sender as PictureBox;
temp.BorderStyle = BorderStyle.FixedSingle;
……
[/Quote]

你这个跟直接写pictureBox1.BorderStyle = BorderStyle.FixedSingle;不是一样吗
反正也是闪,还有控件比较多,显示窗体的时候控件各种闪。

另外一个窗体里边放个button,窗体无边框,button的dock=fill,button有一个backgroundimage。
我把窗体大小设置为(55,55),为啥启动了比较宽,宽度比55大多了。
安得权 2012-11-02
  • 打赏
  • 举报
回复
代码 怎么写的 能贴出来不?
安得权 2012-11-02
  • 打赏
  • 举报
回复

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
PictureBox temp = sender as PictureBox;
temp.BorderStyle = BorderStyle.FixedSingle;
}
乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

是不是 事件 一直被触发?
[/Quote]

应该不是,用的MouseMove事件,我觉得主要是重绘的问题
乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

设置的是哪个函数?你是不是用pictureBox的MouseEnter事件?
[/Quote]

乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你的js 是怎么实现的呢!
[/Quote]

引用点错了
我做的winform程序
安得权 2012-11-02
  • 打赏
  • 举报
回复
是不是 事件 一直被触发?
乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你的js 是怎么实现的呢!
[/Quote]

是啊
乖紫 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
一个PictureBox,在鼠标移动到它上边时改变它的边框样式,但是它会闪烁,怎么才能不让它闪烁。求高手解答。
[/Quote]
winform程序

cjlu98 2012-11-02
  • 打赏
  • 举报
回复
设置的是哪个函数?你是不是用pictureBox的MouseEnter事件?
IT修补匠 2012-11-02
  • 打赏
  • 举报
回复
你的js 是怎么实现的呢!

110,546

社区成员

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

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

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