Miten saan pyöreän Formin?
enpäs tiiä (sori oli pakko :D)
Katsopa tämän keskustelunaiheen loppupuolella oleva koodinpätkä:
https://www.ohjelmointiputka.net/keskustelu/923-läpinäkyvä-vb
edit: Muuttamalla formin koodia seuraavasti muodoksi tulee ympyrä.
Const PII = 3.14159 Private Sub Form_Load() Dim sade As Integer, i As Single 'ympyrän säde sade = 100 ' create non rectangular window Dim xp(49) As POINTAPI 'lasketaan ympyrän koordinaatit For i = 0 To 49 xp(i).x = sade + Sin(i * (2 * PII / 50)) * sade xp(i).y = sade + Cos(i * (2 * PII / 50)) * sade Next ' create polygonal region from given points arec = ApiServices.CreatePolygonRgn(xp(0), 50, 2) ' set region to window ApiServices.SetWindowRgn Me.hWnd, arec, True End Sub
Jes!! Miljoonat kiitokset!!!!
Hmmm... Se kyllä muuttuu 16-bittiseksi, mutta väliäkös sillä
Herjaa tästä: POINTAPI
User defined type...
Laita toi koodi moduliin ja modulin nimeksi ApiServices!
'Moduliin Public Type POINTAPI x As Long y As Long End Type Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type ' sets a region to window object Public Declare Function SetWindowRgn Lib "User32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long ' creates a polygonal region Public Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long ' deletes a created region Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Älä muuta sitä mokomaa apiservicesiksi vaan muuta rivit
arec = ApiServices.CreatePolygonRgn(xp(0), 50, 2) ' set region to window ApiServices.SetWindowRgn Me.hWnd, arec, True
tällaiseksi:
arec = CreatePolygonRgn(xp(0), 50, 2) ' set region to window SetWindowRgn Me.hWnd, arec, True
eli nappaat "apiservices." pois
Senverran epämääräistä häröilyä että pistetään nyt vielä kerran toimiva koodi: (ja muuttujatki esitelty)
Option Explicit Private Type POINTAPI x As Long y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function SetWindowRgn Lib "User32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long ' sets a region to window object Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long ' creates a polygonal region Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long ' deletes a created region Const PII = 3.14159 Private Sub Form_Load() Dim Sade As Integer Dim I As Single Dim Arec As Variant 'ympyrän säde Sade = 150 ' create non rectangular window Dim xp(49) As POINTAPI 'lasketaan ympyrän koordinaatit For I = 0 To 49 xp(I).x = Sade + Sin(I * (2 * PII / 50)) * Sade xp(I).y = Sade + Cos(I * (2 * PII / 50)) * Sade Next ' create polygonal region from given points Arec = CreatePolygonRgn(xp(0), 50, 2) ' set region to window SetWindowRgn Me.hWnd, Arec, True End Sub
Myös ympyrän muotoisen regioniin löytyy valmis funktio.
lainaus Win 32 SDK:sta:
HRGN CreateEllipticRgn( int nLeftRect, // x-coordinate of the upper-left corner of the bounding rectangle int nTopRect, // y-coordinate of the upper-left corner of the bounding rectangle int nRightRect, // x-coordinate of the lower-right corner of the bounding rectangle int nBottomRect // y-coordinate of the lower-right corner of the bounding rectangle );
?
!
elikkäs jotain tyyliin: Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal nLeftRect as Integer, ByVal nTopRect as Integer, ByVal nRightRect as Integer, ByVal nBottomRect as Integer) As Long
voi olla että noi As Integerit pitää muuttaa As Longiksi...?
Tässä on funktion oikea määrittely:
Public Declare Function CreateEllipticRgn Lib "gdi32" Alias "CreateEllipticRgn" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Aihe on jo aika vanha, joten et voi enää vastata siihen.