成都网站建设设计

将想法与焦点和您一起共享

vb.net窗口最小化 Windows窗口最小化

vb.net点关闭 最小化到托盘

添加托盘图标控件,并设置好其Icon属性,然后添加如下代码:

创新互联公司是一家集网站建设,常山企业网站建设,常山品牌网站建设,网站定制,常山网站建设报价,网络营销,网络优化,常山网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

e.Cancel = True

Me.Hide()

End Sub

VB 窗体最小化与还原

VB程序运行时,把窗口最大化后,窗口是不能被调整大小的(最小化除外),在程序中也不行。

设计时,可以正常窗口呈现,并屏蔽窗体的最大化按钮,自己做个替代的“最大化”按钮,实现窗体放大。当点击“最大化”时,触发Form的ReSize事件,在Form的ReSize事件中,写入:

Private Sub Form_Resize()

Form1.Left = 0

Form1.Top = 0

Form1.Width = Screen.Width

Form1.Height = Screen.Height - GetTaskbarHeight

End Sub

(当程序启动时,也会同时触发Form_ReSize的)

其中,GetTaskbarHeight的获取要写进模块文件中:

Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

Public Const SPI_GETWORKAREA = 48

Public Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Public Function GetTaskbarHeight() As Integer

Dim lRes As Long

Dim rectVal As RECT

lRes = SystemParametersInfo(SPI_GETWORKAREA, 0, rectVal, 0)

GetTaskbarHeight = ((Screen.Height / Screen.TwipsPerPixelX) -rectVal.Bottom) * Screen.TwipsPerPixelX

End Function

但是,这样做还要考虑到有些人把任务栏移到其他地方的,比如左侧,右侧,甚至隐藏,所以,也是很麻烦的哦

vb点击按钮控制窗口大小

窗体的BorderStyle=Sizable那么窗体就可以任意调整大小,不理解你为什么非要用个按钮来控制?

就一个按钮?点了是让窗体大呀还是小呀?还是窗体随鼠标移动来改变大小呢?如果是最后这一种,跟用系统的方法调整大小又有什么区别呢?多此一举啊。

----------------------------

明白你的意思了。

在网上找的一段代码,我运行了,有效,你看看吧。

Option Explicit

' demo project showing how to manipulate the style bits of a VB

' form via the SetWindowLong and GetWindowLong API functions

' by Bryan Stafford of New Vision Software?- newvision@imt.net

' this demo is released into the public domain "as is" without

' warranty or guaranty of any kind. In other words, use at

' your own risk.

Private Const GWL_STYLE As Long = (-16)

Private Const GWL_EXSTYLE As Long = (-20)

Private Const WS_THICKFRAME As Long = H40000

Private Const WS_MINIMIZEBOX As Long = H20000

Private Const WS_MAXIMIZEBOX As Long = H10000

Private Declare Function GetWindowLong Lib "user32" _

Alias "GetWindowLongA" (ByVal hWnd, ByVal nIndex)

Private Declare Function SetWindowLong Lib "user32" _

Alias "SetWindowLongA" (ByVal hWnd, ByVal nIndex, _

ByVal dwNewLong)

Private Type POINTAPI

x As Long

y As Long

End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI)

Private Declare Function SetCursorPos Lib "user32" (ByVal x, ByVal y)

Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd, lpPoint As POINTAPI)

Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd, ByVal bRevert)

Private Sub Command1_Click()

' we start off sizeable and change the style bits for the form to Fixed on the first

' click of the button. Each subsequent click just reverses the last action

Call SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) Xor _

(WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX))

' cause the system menu to revert to the state

' that is appropriate for the current borderstyle

Call GetSystemMenu(hWnd, 1)

' change the button caption to the appropriate string

Select Case Command1.Caption

Case "Make My Border Fixed"

Command1.Caption = "Make My Border Sizeable"

Case Else

Command1.Caption = "Make My Border Fixed"

End Select

' adjust the size of the form to force the window to redraw correctly

Move Left, Top, Width - 50, Height - 50

Move Left, Top, Width + 50, Height + 50

Dim tagSavePoint As POINTAPI, tagMovePoint As POINTAPI

' we need to move the cursor over the border of the form to get the nonclient area to

' redraw. We just move it there and then back to the original position.

Call GetCursorPos(tagSavePoint)

With tagMovePoint

.x = (-1)

.y = 10

End With

Call ClientToScreen(hWnd, tagMovePoint)

Call SetCursorPos(tagMovePoint.x, tagMovePoint.y)

Call SetCursorPos(tagSavePoint.x, tagSavePoint.y)

End Sub

VB中窗体绘图在最小化后消失,如何解决?

当窗体被隐藏之后,在窗体重新出现时,系统将触发Paint事件,重绘整个窗体,此时如果Paint方法为空,那么您使用graphic对象绘制的图将全部消失。

要使您绘制的图能始终出现,您就必须在Paint事件触发时,在其方法中添加绘制窗体的代码。由于您的图是任意的,所以您可以通过使用一个全局的数组或数据结构存储在Form上的图像信息,然后在Form_Paint方法中读取图像信息并重绘。如果Form上绘制了新的图像,那么您可以将这个图像信息添加到全局的数组或数据结构中,以保证在Form上始终是正确的图像。

另外:

VB.NET2008中的AutoRedraw问题

.NET 2009-05-04 15:55:22 阅读44 评论0 字号:大中小

VB6中的PictureBox控件的有AutoRedraw属性,设置为True,则窗口最小化或被覆盖后重新打开窗口,原来的图形还在(使用Line等函数画的图形),但VB.NET没有了这个属性,为此烦了好久,MSDN上也没有找到明确的代用方法,上星期去书店翻了翻,终于明白怎么会事.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Bmp As Bitmap

Dim Gra As Graphics

Dim Pen As New Pen(Color.White)

Bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)

Gra = Graphics.FromImage(Bmp)

Dim Dia As Single = Math.Min(PictureBox1.Height, PictureBox1.Width) * 0.5!

Gra.DrawArc(Pen, (PictureBox1.Width - Dia) / 2.0!, (PictureBox1.Height - Dia) / 2.0!, Dia, Dia, 0, 360)

Gra.DrawLine(Pen, 0, 0, PictureBox1.Width / 2.0!, PictureBox1.Height / 2.0!)

PictureBox1.Image = Bmp

End Sub

上面代码画的图形在最小化后重新打开图形还在,下面的则没有了.

Private Sub PictureBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DoubleClick

Dim Gra As Graphics = PictureBox1.CreateGraphics()

Dim Pen As New Pen(Color.Magenta)

Dim Dia As Single = Math.Min(PictureBox1.Height, PictureBox1.Width) * 0.5!

Gra.DrawRectangle(Pen, (PictureBox1.Width - Dia) / 2.0!, (PictureBox1.Height - Dia) / 2.0!, Dia, Dia)

End Sub

希望对你有帮助!

VB中怎样取消2窗体上的“最大化”和“最小化”按钮?

的形式控件选项设置为false,这是摆脱的最大和最小化按钮

形式的属性borderstyle设置为1,3,4,5

也可以禁用最大的按钮设置为false

maxbutton

设置为false,禁用最小的按钮minbutton


网站栏目:vb.net窗口最小化 Windows窗口最小化
转载来于:http://chengdu.cdxwcx.cn/article/hhjdji.html