前言
========================================================
现在参加工作了,感觉中并没有原想象的那么忙,在我的心中,一个干写程序的人,就是应该要比较的
忙,现在我还记得学校里的一个老师说过,一个没有通宵写过程序的程序员不能算是真正的程序员,现在
我不管那位老师说的偏激不偏激,但是在我心中至少是这样的,所以我现在还不算一个真正的程序员.
我还是我,还是一个我自认为不是很喜欢追踪潮流的人,下面我就讲的就是一些老的东西,算是一个分享,
高手就飘过.
多说一句,现在园子里有首页问题,如果大家觉得这篇放首页有问题,我马上就撤下.
=========================================================
1, 自定义自定义窗体样式
第一步,设置窗体样式
Code
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
设置了以后,这个窗体就没有了边框,也就没有了缩放和移动的功能,甚至连关闭也没有了
第二步,疯狂panel
Code
//窗体上面放panel1(System.Windows.Forms.DockStyle.Fill)
//panel1里面有panel2,panel3,panel4,panel5,panel6
//分别用于上,左,右,中,底
Me.Panel1 = New System.Windows.Forms.Panel
Me.Panel2 = New System.Windows.Forms.Panel
Me.Panel3 = New System.Windows.Forms.Panel
Me.Panel4 = New System.Windows.Forms.Panel
Me.Panel5 = New System.Windows.Forms.Panel
Me.Panel6 = New System.Windows.Forms.Panel
Me.Panel1.Controls.Add(Me.Panel6)
Me.Panel1.Controls.Add(Me.Panel5)
Me.Panel1.Controls.Add(Me.Panel4)
Me.Panel1.Controls.Add(Me.Panel3)
Me.Panel1.Controls.Add(Me.Panel2)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel2.Dock = System.Windows.Forms.DockStyle.Top
Me.Panel3.Dock = System.Windows.Forms.DockStyle.Left
Me.Panel4.Dock = System.Windows.Forms.DockStyle.Right
Me.Panel5.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel6.Dock = System.Windows.Forms.DockStyle.Bottom
这样就有了一个大致的模型了
第三步,在各个panel中加入各自应该有的东西
比如在panel2中加上标题栏,在panel3中加入左边框,
第四步,移动,最小/大化
可以在panel2里加上自己做的几个按钮(我做的是picturebox)
我做的如下
事件响应如下
Code
'最小化响应
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Me.WindowState = FormWindowState.Minimized
End Sub
'放大事件响应
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
Me.WindowState = FormWindowState.Maximized
End Sub
还有一个不好做的地方,那就是移动了,
要用到系统API
Code
<DllImport("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal imsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean
End Function
Public Const WM_SYSCOMMAND As Integer = &H112
Public Const SC_MOVE As Integer = &HF010
Public Const HTCAPTION As Integer = &H2
然后就加入事件响应来达到移动的效果
Code
'点击上边框的panel时的响应
Private Sub Panel1_MouseDomn(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel2.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
AwardListForm2.ReleaseCapture()
AwardListForm2.SendMessage(Me.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End If
End Sub
好了,有了放大,缩小,关闭的功能就自己做吧,现在这个自定义窗体里的难点都讲了,其他的就自己做吧
2, 产生不重复的随机数,这个是从网上找的.我做一下摘录
我个人认为比较好的方式1,
原理,先将所有的数据装入一个链表A,再定义一个链表B用于存储产生的随机数,产生一个随机数,将这个数
先保存到B中, 然后将这个数在A中剔除,,如此下去就可能产生要随机的B
看示例:
Code
Private Sub GenerateRandNum(ByVal A As List(Of String), ByVal B As List(Of String), ByVal num As Integer)
Dim rand As Integer
Randomize()
For i As Integer = 1 To num
rand = Int(Rnd() * A.Count)
B.Add(A(rand))
A.RemoveAt(rand)
Next
End Sub
方式2,就是比较法,
就是在A链表中并不剔除元素,而是每产生一个随机数,就与B中已有的数比较,B中存在就再重新产生一个,再比较,
直到产生一个B中没有和随机数
示例:
Code
Private Function GenerateRandoms(ByVal sum As Integer, ByVal num As Integer) As Integer()
Dim c(num) As Integer
Dim k As Integer
Randomize()
For i As Integer = 0 To num
c(i) = Int(Rnd() * sum)
k = i
For j As Integer = 1 To k - 1
If c(j) = c(k) Then
i = i - 1
Exit For
End If
Next
Next
Return c
End Function