WinForms下的SliderButtons设计
发布日期:2021-05-14 04:36:46 浏览次数:14 分类:博客文章

本文共 4038 字,大约阅读时间需要 13 分钟。

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������

������������������������������������������userControl���������������UserControl���������������������������������������

using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Drawing;
using
System.Data;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
SlideButtons
{
public
delegate
void
RaiseEventHandler();
public
partial
class
UserControl1 : UserControl
{
public
UserControl1()
{
InitializeComponent();
}
public
string
imgPath {
get
;
set
; }
public
string
lblText {
get
;
set
; }
private
int
formWidth
=
0
;
private
int
formHeight
=
0
;
private
int
picWidth
=
0
;
private
int
picHeight
=
0
;
private
int
radisNum
=
0
;
private
int
radisStep
=
0
;
private
bool
flag
=
false
;
//
��������������������� ���������������true ���������false
private
int
count
=
0
;
//
���������
public
RaiseEventHandler raiseEventHandler;
private
void
UserControl1_Load(
object
sender, EventArgs e)
{
formWidth
=
this
.Width;
//
���������������
formHeight
=
this
.Height;
//
���������������
picWidth
=
this
.pictureBox1.Width;
//
���������������
picHeight
=
this
.pictureBox1.Height;
//
���������������
this
.radisNum
=
40
;
//
���������������������������
this
.radisStep
=
5
;
//
������
this
.pictureBox1.Image
=
Image.FromFile(imgPath);
this
.label1.Text
=
lblText;
this
.label1.TextAlign
=
ContentAlignment.MiddleCenter;
}
private
void
pictureBox1_MouseLeave(
object
sender, EventArgs e)
{
timer2.Enabled
=
true
;
timer1.Enabled
=
false
;
flag
=
false
;
}
private
void
timer1_Tick(
object
sender, EventArgs e)
{
if
(flag)
{
count
++
;
if
(count
>
radisStep)
{
timer1.Enabled
=
false
;
timer2.Enabled
=
false
;
}
this
.pictureBox1.Height
=
this
.pictureBox1.Height
-
radisStep;
this
.pictureBox1.Width
=
this
.pictureBox1.Width
-
radisStep;
this
.pictureBox1.Left
=
this
.pictureBox1.Left
+
radisStep
/
2
;
this
.pictureBox1.Top
=
this
.pictureBox1.Top
+
radisStep
/
2
;
}
}
private
void
timer2_Tick(
object
sender, EventArgs e)
{
if
(
!
flag)
{
count
--
;
if
(count
<
0
)
{
timer2.Enabled
=
false
;
timer1.Enabled
=
false
;
}
this
.pictureBox1.Height
=
this
.pictureBox1.Height
+
radisStep;
this
.pictureBox1.Width
=
this
.pictureBox1.Width
+
radisStep;
this
.pictureBox1.Left
=
this
.pictureBox1.Left
-
radisStep
/
2
;
this
.pictureBox1.Top
=
this
.pictureBox1.Top
-
radisStep
/
2
;
}
}
private
void
pictureBox1_Click(
object
sender, EventArgs e)
{
raiseEventHandler();
}
private
void
pictureBox1_MouseEnter(
object
sender, EventArgs e)
{
timer1.Enabled
=
true
;
timer2.Enabled
=
false
;
flag
=
true
;
}
}
}

������������������������������Timer���������������picture���������������������������������������������������������������������������������������

������������������������������������

using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
SlideButtons
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
this
.DoubleBuffered
=
true
;
//
��������������� ������������������
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
UserControl1[] u
=
new
UserControl1[
5
];
for
(
int
i
=
0
; i
<
5
; i
++
)
{
u[i]
=
new
UserControl1();
u[i].imgPath
=
@"
D:\img\
"
+
i.ToString()
+
"
.png
"
;
u[i].lblText
=
"
���������
"
+
i.ToString();
u[i].Left
=
u[i].Width
*
i
+
10
;
u[i].Top
=
10
;
u[i].raiseEventHandler
+=
new
RaiseEventHandler(mycontrol_click);
this
.groupBox1.Controls.Add(u[i]);
}
}
private
void
mycontrol_click()
{
MessageBox.Show(
"
������������������
"
);
}
}
}

������������������������������������������������

上一篇:WinForm中的DataGridView子窗体刷新父窗体备忘
下一篇:asp.net下载网络文件

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月08日 09时11分42秒