private void btnshake_Click(object sender, EventArgs e)//按下btnshake按钮的时候 { int recordx = this.Left; //指定窗体左边值 int recordy = this.Top; //指定窗体上边值 for (int i = 0; i < 10; i++) //设定循环次数为20 且加1 { if (i % 2 == 0) //如果i 能给2整除 { this.Left=this.Left + 10; //窗体左边值加10 } else //否则 { this.Left = this.Left - 10;//窗体左边边值减10 } if (i % 2 == 0)//如果i能给2整除 { this.Top = this.Top +10;//窗体上边值加10 } else//否则 { this.Top = this.Top - 10;//窗体上边值减10 } System.Threading.Thread.Sleep(30);//震动频率 } this.Left = recordx;//重设窗体初此左边值 this.Top = recordy; //重设窗体初此上边值 rtbget.Text = "您发送了一个窗口抖动。" + System.Environment.NewLine;//提示发了震动并且换行 }
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim st As New Point Dim st1 As New Point Dim st2 As New Point st = Me.Location st1 = New Point(st.X + 2, st.Y + 2) st2 = New Point(st.X - 2, st.Y - 2) Dim i As Integer = 0 While i <= 4 Me.Location = st1 System.Threading.Thread.Sleep(60) Me.Location = st2 System.Threading.Thread.Sleep(60) i = i + 1 End While Me.Location = st End Sub
SetwindowPos 改变窗口位置
WINDOWPLACEMENT 这个结构可以得到最大化最小化之前的位置
{
int recordx = this.Left; //指定窗体左边值
int recordy = this.Top; //指定窗体上边值 for (int i = 0; i < 10; i++) //设定循环次数为20 且加1
{ if (i % 2 == 0) //如果i 能给2整除
{
this.Left=this.Left + 10; //窗体左边值加10
}
else //否则
{
this.Left = this.Left - 10;//窗体左边边值减10
}
if (i % 2 == 0)//如果i能给2整除
{
this.Top = this.Top +10;//窗体上边值加10
}
else//否则
{
this.Top = this.Top - 10;//窗体上边值减10
}
System.Threading.Thread.Sleep(30);//震动频率
}
this.Left = recordx;//重设窗体初此左边值
this.Top = recordy; //重设窗体初此上边值
rtbget.Text = "您发送了一个窗口抖动。" + System.Environment.NewLine;//提示发了震动并且换行 }
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim st As New Point
Dim st1 As New Point
Dim st2 As New Point
st = Me.Location
st1 = New Point(st.X + 2, st.Y + 2)
st2 = New Point(st.X - 2, st.Y - 2)
Dim i As Integer = 0
While i <= 4
Me.Location = st1
System.Threading.Thread.Sleep(60)
Me.Location = st2
System.Threading.Thread.Sleep(60)
i = i + 1
End While
Me.Location = st
End Sub