partial class SkinForm : Form
{
//控件层
private SkinMain Main;
//带参构造
public SkinForm(SkinMain main)
{
InitializeComponent();
//将控制层传值过来
this.Main = main;
//减少闪烁
SetStyles();
//初始化
Init();
}
#region 初始化
private void Init()
{
//最顶层
TopMost = Main.TopMost;
//是否在任务栏显示
ShowInTaskbar = Main.SkinShowInTaskbar;
//无边框模式
FormBorderStyle = FormBorderStyle.None;
//自动拉伸背景图以适应窗口
BackgroundImageLayout = ImageLayout.Stretch;
//还原任务栏右键菜单
CommonClass.SetTaskMenu(this);
//设置绘图层显示位置
this.Location = new Point(Main.Location.X - Main.MainPosition.X, Main.Location.Y - Main.MainPosition.Y);
//设置ICO
Icon = Main.Icon;
//是否显示ICO
ShowIcon = Main.ShowIcon;
//设置大小
Size = Main.SkinSize;
//设置标题名
Text = Main.Text;
//设置背景
Bitmap bitmaps = new Bitmap(Main.SkinBack, Size);
if (Main.SkinTrankColor != Color.Transparent)
{
bitmaps.MakeTransparent(Main.SkinTrankColor);
}
BackgroundImage = bitmaps;
//控制层与绘图层合为一体
Main.TransparencyKey = Main.SkinWhetherTank ? Color.Empty : Main.BackColor;
Main.Owner = this;
//绘制层窗体移动
this.MouseDown += new MouseEventHandler(Frm_MouseDown);
this.MouseMove += new MouseEventHandler(Frm_MouseMove);
this.MouseUp += new MouseEventHandler(Frm_MouseUp);
this.LocationChanged += new EventHandler(Frm_LocationChanged);
//控制层层窗体移动
Main.MouseDown += new MouseEventHandler(Frm_MouseDown);
Main.MouseMove += new MouseEventHandler(Frm_MouseMove);
Main.MouseUp += new MouseEventHandler(Frm_MouseUp);
Main.LocationChanged += new EventHandler(Frm_LocationChanged);
}
#endregion
而SkinMain中的构造函数为:
public partial class SkinMain : Form
{
//绘制层
private SkinForm skin;
public SkinMain()
{
InitializeComponent();
//减少闪烁
SetStyles();
//初始化
Init();
}
#region 初始化
private void Init()
{
//不显示在Windows任务栏中
ShowInTaskbar = false;
}
#endregion
SkinMain中用于显示阴影的代码:
Protected Overrides Sub OnVisibleChanged(e As EventArgs)
MyBase.OnVisibleChanged(e)
If Visible Then
If Not DesignMode Then
DWin32.AnimateWindow(Me.Handle, 150, DWin32.AW_BLEND Or DWin32.AW_ACTIVATE)
ElseIf Not DesignMode AndAlso ds Is Nothing Then
ds = New DSkin(Me)
ds.Show(Me)
End If
MyBase.OnVisibleChanged(e)
Else
MyBase.OnVisibleChanged(e)
DWin32.AnimateWindow(Me.Handle, 150, DWin32.AW_BLEND Or DWin32.AW_HIDE)
End If
End Sub
问题是,用vb.net 定义SkinForm 必须要用private skin as SkinForm(me)才可以,但是如果这样,程序运行就会导致溢出,报错显示无限循环。如果用private skin as SkinFrom 这样也报错,必须要有参数。
请问各位大神,怎么转换。或者代码应该怎么写?
1 个解决方案
#1
Private skin As SkinForm
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
skin = New SkinForm(Me)
skin.Show(Me)
MyBase.OnVisibleChanged(e)
End Sub
'试过了,这个代码没有问题的。
#1
Private skin As SkinForm
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
skin = New SkinForm(Me)
skin.Show(Me)
MyBase.OnVisibleChanged(e)
End Sub
'试过了,这个代码没有问题的。