|
|
|
|
|
Dicas
|
|
Visual Basic (ActiveX/Controles/DLL)
|
|
|
Título da Dica: Centralizar imagem num form MDI
|
|
|
|
Postada em 25/2/2002 por MarceloGomes
Primeiro, dentro do form MDI, crie 3 objetos PictureBox, sendo que o Picture3 agrupa o Picture2 e Picture1 (ou seja, desenhe primeiro o Picture3 e depois desenhe o Picture1 e o Picture2 dentro do Picture3). Coloque o Picture3 e o Picture1 do tamanho total do MDI. Deixe o Picture2 num tamanho normal.
Depois, crie nas declaracoes do MDI, coloque o seguinte código:
Type BITMAP '24 bytes bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Sub ResizeCenterWallpaper() Dim Rc As RECT Dim bmWallpaper As BITMAP Dim iSX As Integer, iSY As Integer, iX As Integer Dim iY As Integer, iWidth As Integer, iHeight As Integer Dim dAspect As Double hMDIClientwnd& = FindWindowEx(Me.hWnd, 0, "MDIClient", vbNullString) GetWindowRect hMDIClientwnd&, Rc hdc& = Picture2.hdc iWidth = (Rc.Right - Rc.Left) ' = rc.Width iHeight = (Rc.Bottom - Rc.Top) ' = rc.Height Picture2.Width = iWidth * Screen.TwipsPerPixelX Picture2.Height = iHeight * Screen.TwipsPerPixelY GetObject Picture1.Image, 24, bmWallpaper iSX = bmWallpaper.bmWidth ' The current width of the picture iSY = bmWallpaper.bmHeight ' The current height of the picture dAspect = iSX / iSY If (iSX > iWidth) Then iSX = iWidth iSY = iWidth / dAspect End If If (iSY > iHeight) Then iSX = iHeight * dAspect iSY = iHeight End If iX = ((iWidth - iSX) / 2) ' Left of picture iY = ((iHeight - iSY) / 2) ' Top of picture hBrush& = CreateSolidBrush(RGB(130, 130, 130)) ' Select a background color hOldBrush& = SelectObject(hdc&, hBrush&) ' Fill Top of wallpaper Rc.Left = 0 Rc.Top = 0 Rc.Right = iWidth Rc.Bottom = iY FillRect hdc&, Rc, hBrush& ' Fill Bottom of wallpaper Rc.Left = 0 Rc.Top = iY + iSY Rc.Right = iWidth Rc.Bottom = iHeight FillRect hdc&, Rc, hBrush& ' Fill Left of wallpaper Rc.Left = 0 Rc.Top = iY Rc.Right = iX Rc.Bottom = iY + iSY FillRect hdc&, Rc, hBrush& ' Fill Right of wallpaper Rc.Left = iX + iSX Rc.Top = iY Rc.Right = iWidth Rc.Bottom = iY + iSY FillRect hdc&, Rc, hBrush&
SelectObject hdc&, hOldBrush& ' Reset Brush StretchBlt hdc&, iX, iY, iSX, iSY, Picture1.hdc, 0, 0, bmWallpaper.bmWidth, bmWallpaper.bmHeight, vbSrcCopy Me.Picture = Picture2.Image ' Set the new Picture End Sub
Feito isso, coloque isto no MDI.Load..
Picture1.Visible = False Picture2.Visible = False Picture3.Visible = False Picture1.Container = Picture3 Picture2.Left = 0 Picture2.Top = 0 Picture1.Left = 0 Picture1.Top = 0 Picture1.ScaleMode = vbPixels
Após isso feito, no evento Resize do MDI, coloque isso:
ResizeCenterWallpaper
Pronto. Está feito.
|
|
|
|
|