C#继承UserControl 的控件上添加PictureBox 隐藏PictureBox问题
C#继承UserControl 的控件上添加PictureBox 隐藏PictureBox 在我控制隐藏C#PictureBox不能直接隐藏 最小化重新最大化才能隐藏,继承UserControl代码如下 求各位高手指点,小弟C#新手
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace UserControlEx
{
/// <summary>
/// 透明面板
/// </summary>
public partial class UserPanel : UserControl
{
public UserPanel()
{
SetStyle(ControlStyles.SupportsTransparentBackColor
| ControlStyles.UserPaint
| ControlStyles.AllPaintingInWmPaint
| ControlStyles.Opaque, true);
this.BackColor = Color.Transparent;
}
private Image img;
public Image Image
{
get
{
return img;
}
set
{
img = value;
}
}
private string showName;
public string ShowName
{
get { return showName; }
set
{
showName = value;
}
}
protected override void OnLocationChanged(EventArgs e)
{
Visible = false;
Visible = true;
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaint(PaintEventArgs pe)
{
if (img != null)
{
base.OnPaint(pe);
pe.Graphics.DrawImage(img, 0, 0);
Graphics g = pe.Graphics;
g.DrawString(showName, SystemFonts.DefaultFont, Brushes.Yellow, 24, 26);
}
else
{
Graphics g = pe.Graphics;
g.DrawString(showName, SystemFonts.DefaultFont, Brushes.Yellow, 24, 26);
}
// Graphics e = pe.Graphics;
// System.Drawing.Graphics e = this.CreateGraphics();
// e.DrawImage(log, 20, 20, 10, 10);
}
private Image log;
public Image Log
{
get
{
return log;
}
set
{
log = value;
}
}
//设置双击事件
public new event EventHandler DoubleClick;
//注意DoubleClickTime属性获取
//允许的最大数量之间的毫秒
//通过双击鼠标点击是有效的
int previousClick = SystemInformation.DoubleClickTime;
//双击鼠标点击位置
int X, Y = 0;
protected override void OnMouseDown(MouseEventArgs e)
{
int now = System.Environment.TickCount;
int x = e.X;
int y = e.Y;
//双击检测 判断时间是否已过 双击鼠标位置是否有效。
if (now - previousClick <= SystemInformation.DoubleClickTime && X - x == 0 && Y - y == 0)
{
//进入DoubleClick事件
if (DoubleClick != null)
DoubleClick(this, EventArgs.Empty);
}
previousClick = now;
X = x;
Y = y;
base.OnMouseDown(e);
}
//DoubleClick事件
protected new virtual void OnDoubleClick(EventArgs e)
{
if (this.DoubleClick != null)
this.DoubleClick(this, e);
}
//按钮无焦点
protected override bool ShowFocusCues
{
get
{
//获得焦点的时候什么都不做
return false;
}
}
}
}
--------------------编程问答--------------------
PictureBox 在哪里?
--------------------编程问答--------------------
是这个自定义UserControlEx控件上添加PictureBox 不能及时重绘, 让UserControlEx继承PictureBox就可以重绘,为什么会这样呢
--------------------编程问答--------------------
记得调用 invalidate
补充:.NET技术 , C#