符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
把任务栏隐藏了再把form最大化
威远ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
[DllImport("user32.dll")]
private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("User32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private const int SW_SHOW = 5;
private const int SW_HIDE = 0;
IntPtr handle;
int result;
//获取任务栏窗口的句柄
//Shell_TrayWnd是任务栏的窗口名
handle = FindWindow("Shell_TrayWnd", null); result = ShowWindow(handle, SW_SHOW); //显示
result = ShowWindow(handle, SW_HIDE); //隐藏
如果是窗体右键单击事件,是
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
If e.Button = Windows.Forms.MouseButtons.Right Then
'这里写你要的代码
End If
End Sub
但是如果只是右键单击就弹出菜单的话没必要这样,只需要在窗体上放置一个ContextMenuStrip控件,然后在Form的ContextMenuStrip属性中绑定这个控件就可以了。
可以实现
首先创建一个Button类型控件数组:
1、创建“Windows应用程序”类型的工程,添加名为ButtonArray的类,并使该类继承 System.Collection.CollectionBase 类。System.Collections.CollectionBase类是.NET框架类库中为集合操作提供抽象的基类,通过对它的继承可以为我们的ButtonArray类具备集合增加、删除、索引的功能。
2、为ButtonArray类添加ParentForm属性,即控件组所在窗体,创建初始化函数(构造函数);
3、为控件数组类增加AddItem方法,该方法在控件数组类中添加成员;
4、为控件数组类增加RemoveItem方法,该方法在控件数组中删除一个成员。
示例代码:
Public Class ButtonArray
Inherits System.Collections.CollectionBase
Private ReadOnly ParentForm As System.Windows.Forms.Form
Public Sub New(ByVal pForm As System.Windows.Forms.Form)
ParentForm = pForm
End Sub
Default Public ReadOnly Property Item(ByVal index As Integer) As System.Windows.Forms.Button
Get
Return Me.List.Item(index) ' ButtonArray的List 属性从CollectionBase 继承
End Get
End Property
Public Sub AddItem()
Dim btnItem As New System.Windows.Forms.Button
Me.List.Add(btnItem)
ParentForm.Controls.Add(btnItem) '向窗体中增加控件
btnItem.Tag = Me.Count 'Count属性从CollectionBase 继承
btnItem.Top = Me.Count * 30
btnItem.Left = 200
btnItem.Text = "Button" Me.Count.ToString
AddHandler btnItem.Click, AddressOf btnItem_Click '绑定事件处理程序
End Sub
Public Sub AddItem(ByVal btnItem As System.Windows.Forms.Button)
Me.List.Add(btnItem)
AddHandler btnItem.Click, AddressOf btnItem_Click '绑定事件处理程序
End Sub
Public Sub RemoveItem()
If Me.Count 0 Then
ParentForm.Controls.Remove(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
Public Sub btnItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'在这里编写控件数组对点击事件的响应
'例如:
MsgBox("点击:" sender.GetType().ToString CType(CType(sender, Button).Tag, String))
End Sub
End Class
使用创建的控件数组
在Form1中放置两个按钮Button1、Button2,分别测试控件数组的增添、删除。
双击Form添加代码:
Public Class Form1
Inherits System.Windows.Forms.Form
……Windows窗体设计器生成的代码……
Dim Buttons As New ButtonArray(Me)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Buttons.AddItem()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Buttons.RemoveItem()
End Sub
End Class
其他的控件数组也可以用类似的方式来实现
例如 Label控件数组
LabelArray.vb代码如下:
Public Class LabelArray
Inherits System.Collections.CollectionBase
Private ReadOnly ParentForm As System.Windows.Forms.Form
Public Sub New(ByVal pForm As System.Windows.Forms.Form)
ParentForm = pForm
End Sub
Default Public ReadOnly Property Item(ByVal index As Integer) As System.Windows.Forms.Label
Get
Return Me.List.Item(index) ' ButtonArray的List 属性从CollectionBase 继承
End Get
End Property
Public Sub AddItem(ByVal btnItem As System.Windows.Forms.Label)
Me.List.Add(btnItem)
AddHandler btnItem.Click, AddressOf btnItem_Click '绑定事件处理程序
End Sub
Public Sub btnItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'在这里编写控件数组对点击事件的响应
'例如:
MsgBox("点击:" sender.GetType().ToString CType(CType(sender, Label).Tag, String))
End Sub
End Class
使用创建的Label控件
在Form1中放置两个按钮Label1、Label2
双击Form添加代码:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
'用来绑定label
BindArray()
End Sub
……Windows窗体设计器生成的其他代码……
#End Region
Dim Labels As New LabelArray(Me)
Public Sub BindArray()
Me.Label1.Tag = "1111"
Me.Label2.Tag = "222"
Labels.AddItem(Me.Label1)
Labels.AddItem(Me.Label2)
End Sub
End Class
然后可以测试点击两个label可以显示相应的Tag的信息。
直接添加一个MID父窗体或在已有窗体的属性中找到IsMDIContainer属性,然后设置为True,然后创建第二个窗体 ,需要加载子窗体的时候:
Dim NewMDIChild As New Form2
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
Public Shared Sub CheckMDIChildForm(ByVal MDIForm As Windows.Forms.Form, ByVal MDIChildForm As Windows.Forms.Form, ByVal MDIChildFormName As String)
If MDIForm.MdiChildren.Length 1 Then
'如果没有任何一个MDI子窗体,则创该MDI子窗体的窗体实例
Dim MDIChildFrm As Windows.Forms.Form = MDIChildForm ' 定义MDI子窗体
MDIChildFrm.MdiParent = MDIForm '指定父窗体
MDIChildFrm.Show() '打开窗体
Exit Sub
Else
Dim x As Integer
Dim frmyn As Boolean
For x = 0 To (MDIForm.MdiChildren.Length) - 1
Dim tempChild As Windows.Forms.Form = CType(MDIForm.MdiChildren(x), Windows.Forms.Form)
If tempChild.Name = MDIChildFormName Then
'检测到有该MDI子窗体,设为激活 并退出循环
frmyn = True
tempChild.BringToFront()
Exit For
Else
frmyn = False
End If
Next
If Not frmyn Then
'在打开的窗体中没检测到则新建
Dim MDIChildFrm As Windows.Forms.Form = MDIChildForm ' 定义MDI子窗体
MDIChildFrm.MdiParent = MDIForm '指定父窗体
MDIChildFrm.Show() '打开窗体
End If
End If
End Sub