Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / March 2004



Tip: Looking for answers? Try searching our database.

Resize

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hans Eekels - 06 Mar 2004 13:52 GMT
I found out a strange behaviour of the resize-event.
I use a picturebox in a mdiForm. Based on a classmodule I can paint the
picturebox with my firmname vertical, including some dithering from white to
black.
I use the resize-event to draw the picturebox when it resizes. No problem
with "normal" resizing of the form, but troubles when clicking the max or
min-button in the right top of the form ! I figured out that the
resize-event fires before the form actually changes in size (!?) and not
after the changing (like by a normal resizing). So my picturebox isn't
drawed correctly when using the max or min-button.
I am now using a timer to draw my picturebox after resizing, but it remains
strange, though  ?

Hans Eekels (NL)
Randy Birch - 06 Mar 2004 14:07 GMT
Have you tried placing your code to repaint the picture in the Paint event?
You might want to provide a flag that is set to true if the resize is
detected in the resize event to prevent unnecessary repainting of the form -
probably not needed but available if it is.

Signature

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.

: I found out a strange behaviour of the resize-event.
: I use a picturebox in a mdiForm. Based on a classmodule I can paint the
[quoted text clipped - 10 lines]
:
: Hans Eekels (NL)
Hans Eekels - 06 Mar 2004 14:26 GMT
There is no Paint event in a mdiForm :)
HE

> Have you tried placing your code to repaint the picture in the Paint event?
> You might want to provide a flag that is set to true if the resize is
[quoted text clipped - 17 lines]
> :
> : Hans Eekels (NL)
Rick Rothstein - 06 Mar 2004 15:58 GMT
What about if you use the Paint event of the PictureBox?

Rick - MVP

> There is no Paint event in a mdiForm :)
> HE
[quoted text clipped - 25 lines]
> > :
> > : Hans Eekels (NL)
Hans Eekels - 06 Mar 2004 16:50 GMT
I am not sure if I understand what you mean. I can use a lot of events or
methods to repaint my picture, but the start must be the resize-event. And
because the resize-event fires before the form actually changes in size, no
code will work. It works with a timer (interval=2), Timer.Enabled=True in
the Resize-event and in the timer_timer-event I redraw my picturebox.
I was just wondering that the behavior of the resize-event is so different.

HE

> What about if you use the Paint event of the PictureBox?
>
[quoted text clipped - 31 lines]
> > > :
> > > : Hans Eekels (NL)
Rick Rothstein - 06 Mar 2004 18:47 GMT
Okay, I decide to actually play around with a PictureBox in an MDIForm to
see what is happening. You didn't provide any code as to what you are
drawing in the PictureBox, so all I did was set the PictureBox aligned left
and drew a vertical gradient in it. What I found was, nothing special needed
to be done... I just set the AutoRedraw property of the PictureBox to True
and put my code in its Resize event. No matter how I resized the MDIForm,
the gradient was redrawn smoothly and correctly. Here is the code I used
(remember, this was all the code I used in the entire sample project).

Private Sub Picture1_Resize()
 Dim X As Long
 Dim PicWidth As Long
 Dim PicHeight As Long
 PicWidth = Picture1.Width
 PicHeight = Picture1.Height
 For X = 0 To Picture1.Height
   Picture1.Line (0, X)-(PicWidth, X), _
                 RGB(255 * X / PicHeight, _
                     255 * X / PicHeight, _
                     255 * X / PicHeight)
 Next
End Sub

Now I guess it is possible you are doing something in your drawing routine
that might not be handled as smoothly as the above gradient; if so, post
some code so we can try it out on our own systems.

Rick - MVP

> I am not sure if I understand what you mean. I can use a lot of events or
> methods to repaint my picture, but the start must be the resize-event. And
[quoted text clipped - 42 lines]
> > > > :
> > > > : Hans Eekels (NL)
Hans Eekels - 06 Mar 2004 19:38 GMT
Thanks a lot for your help, this is al the code:

in mdiForm
Picturebox with:
width=810
Autoredraw=true
Autosize=false
Borderstyle=1
Font: Times bold 36

Option Explicit
Private cLv As New cLogo

In load
cLv.DrawingObject = Picture1
cLv.Caption = "SpecialSoftware"

In Resize
On Error GoTo 0
Call cLv.Draw(1)  'place vertical text

======================
ClassModule

Option Explicit

Private Type RECT
   Left1 As Long
   tOp As Long
   Right1 As Long
   Bottom As Long
End Type
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As
RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As
Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As
Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal
nCount As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal
nIndex As Long) As Long
Private Const LOGPIXELSX = 88    '  Logical pixels/inch in X
Private Const LOGPIXELSY = 90    '  Logical pixels/inch in Y
Private Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal
nNumerator As Long, ByVal nDenominator As Long) As Long
Private Const LF_FACESIZE = 32
Private Type LOGFONT
   lfHeight As Long
   lfWidth As Long
   lfEscapement As Long
   lfOrientation As Long
   lfWeight As Long
   lfItalic As Byte
   lfUnderline As Byte
   lfStrikeOut As Byte
   lfCharSet As Byte
   lfOutPrecision As Byte
   lfClipPrecision As Byte
   lfQuality As Byte
   lfPitchAndFamily As Byte
   lfFaceName(LF_FACESIZE) As Byte
End Type
Private Declare Function CreateFontIndirect Lib "gdi32" Alias
"CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal
hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As
Long
Private Const FW_NORMAL = 400
Private Const FW_BOLD = 700
Private Const FF_DONTCARE = 0
Private Const DEFAULT_PITCH = 0
Private Const DEFAULT_CHARSET = 1
Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal
OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
Private Const CLR_INVALID = -1
Private Declare Function SetGraphicsMode Lib "gdi32" (ByVal hdc As Long,
ByVal iMode As Long) As Long
Private Const GM_ADVANCED = 2
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc
As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal
wFormat As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal
lpString As String) As Long
' lfQuality Constants:
Private Const DEFAULT_QUALITY = 0 ' Appearance of the font is set to default
Private Const DRAFT_QUALITY = 1 ' Appearance is less important that
PROOF_QUALITY.
Private Const PROOF_QUALITY = 2 ' Best character quality
Private Const NONANTIALIASED_QUALITY = 3 ' Don't smooth font edges even if
system is set to smooth font edges
Private Const ANTIALIASED_QUALITY = 4 ' Ensure font edges are smoothed if
system is set to smooth font edges

Private m_picThis As PictureBox
Private m_sCaption As String
Private m_bRGBStart(1 To 3) As Integer
Private m_oStartColor As OLE_COLOR
Private m_bRGBEnd(1 To 3) As Integer
Private m_oEndColor As OLE_COLOR

Public Property Let Caption(ByVal sCaption As String)
   m_sCaption = sCaption
End Property
Public Property Get Caption() As String
   Caption = m_sCaption
End Property

Public Property Let DrawingObject(ByRef picThis As PictureBox)
   Set m_picThis = picThis
End Property
Public Property Get StartColor() As OLE_COLOR
   StartColor = m_oStartColor
End Property
Public Property Let StartColor(ByVal oColor As OLE_COLOR)
Dim lColor As Long
   If (m_oStartColor <> oColor) Then
       m_oStartColor = oColor
       OleTranslateColor oColor, 0, lColor
       m_bRGBStart(1) = lColor And &HFF&
       m_bRGBStart(2) = ((lColor And &HFF00&) \ &H100)
       m_bRGBStart(3) = ((lColor And &HFF0000) \ &H10000)
       If Not (m_picThis Is Nothing) Then
           'aangepast was Draw
           Call Draw(1)
       End If
   End If

End Property
Public Property Get EndColor() As OLE_COLOR
   EndColor = m_oEndColor
End Property
Public Property Let EndColor(ByVal oColor As OLE_COLOR)
Dim lColor As Long
   If (m_oEndColor <> oColor) Then
       m_oEndColor = oColor
       OleTranslateColor oColor, 0, lColor
       m_bRGBEnd(1) = lColor And &HFF&
       m_bRGBEnd(2) = ((lColor And &HFF00&) \ &H100)
       m_bRGBEnd(3) = ((lColor And &HFF0000) \ &H10000)
       If Not (m_picThis Is Nothing) Then
           'aangepast was Draw
           Call Draw(1)
       End If
   End If
End Property

Public Sub Draw(iKeuze As Integer)

Dim lHeight As Long, lWidth As Long
Dim lYStep As Long
Dim lY As Long
Dim bRGB(1 To 3) As Integer
Dim tLF As LOGFONT
Dim hFnt As Long
Dim hFntOld As Long
Dim lR As Long
Dim tR As RECT
Dim rct As RECT
Dim hBr As Long
Dim hdc As Long
Dim dR(1 To 3) As Double
On Error GoTo DrawError

   hdc = m_picThis.hdc
   lHeight = m_picThis.Height \ Screen.TwipsPerPixelY
   rct.Right1 = m_picThis.Width \ Screen.TwipsPerPixelY
   ' Set a graduation of 255 pixels:
   lYStep = lHeight \ 255
   If (lYStep = 0) Then
       lYStep = 1
   End If
   rct.Bottom = lHeight
   LSet tR = rct

   bRGB(1) = m_bRGBStart(1)
   bRGB(2) = m_bRGBStart(2)
   bRGB(3) = m_bRGBStart(3)
   dR(1) = m_bRGBEnd(1) - m_bRGBStart(1)
   dR(2) = m_bRGBEnd(2) - m_bRGBStart(2)
   dR(3) = m_bRGBEnd(3) - m_bRGBStart(3)

If iKeuze = 1 Then 'dithering
   For lY = lHeight To 0 Step -lYStep
       ' Draw bar:
       rct.tOp = rct.Bottom - lYStep
       hBr = CreateSolidBrush((bRGB(3) * &H10000 + bRGB(2) * &H100& +
bRGB(1)))
       FillRect hdc, rct, hBr
       DeleteObject hBr
       rct.Bottom = rct.tOp
       ' Adjust colour:
       bRGB(1) = m_bRGBStart(1) + dR(1) * (lHeight - lY) / lHeight
       bRGB(2) = m_bRGBStart(2) + dR(2) * (lHeight - lY) / lHeight
       bRGB(3) = m_bRGBStart(3) + dR(3) * (lHeight - lY) / lHeight
       'Debug.Print bRGB(1), (lHeight - lY) / lHeight
   Next lY
End If
   pOLEFontToLogFont m_picThis.Font, hdc, tLF
   tLF.lfEscapement = 900

   hFnt = CreateFontIndirect(tLF)
   If (hFnt <> 0) Then
       hFntOld = SelectObject(hdc, hFnt)
       lR = TextOut(hdc, 0, lHeight - 16, m_sCaption, lstrlen(m_sCaption))
       SelectObject hdc, hFntOld
       DeleteObject hFnt
   End If

   m_picThis.Refresh
   Exit Sub
DrawError:
   Debug.Print "Problem: " & Err.Description
End Sub
Private Sub pOLEFontToLogFont(fntThis As StdFont, hdc As Long, tLF As
LOGFONT)
Dim sFont As String
Dim iChar As Integer

   ' Convert an OLE StdFont to a LOGFONT structure:
   With tLF
       sFont = fntThis.Name
       ' There is a quicker way involving StrConv and CopyMemory, but
       ' this is simpler!:
       For iChar = 1 To Len(sFont)
           .lfFaceName(iChar - 1) = CByte(Asc(Mid$(sFont, iChar, 1)))
       Next iChar
       ' Based on the Win32SDK documentation:
       .lfHeight = -MulDiv((fntThis.Size), (GetDeviceCaps(hdc,
LOGPIXELSY)), 72)
       .lfItalic = fntThis.Italic
       If (fntThis.Bold) Then
           .lfWeight = FW_BOLD
       Else
           .lfWeight = FW_NORMAL
       End If
       .lfUnderline = fntThis.Underline
       .lfStrikeOut = fntThis.Strikethrough
       .lfCharSet = fntThis.Charset
       .lfQuality = ANTIALIASED_QUALITY
   End With

End Sub

Private Sub Class_Initialize()
   StartColor = &H0
   EndColor = vbButtonFace
End Sub

> Okay, I decide to actually play around with a PictureBox in an MDIForm to
> see what is happening. You didn't provide any code as to what you are
[quoted text clipped - 24 lines]
>
> Rick - MVP
Rick Rothstein - 07 Mar 2004 09:44 GMT
Unless I'm missing something, doesn't the project work the way you want if
you remove the code in the MDIForm_Resize event and place it into the
Picture1_Resize event instead?

Rick - MVP

> Thanks a lot for your help, this is al the code:
>
[quoted text clipped - 275 lines]
> >
> > Rick - MVP
Hans Eekels - 07 Mar 2004 11:36 GMT
Realy great ! That works !

Thanks
HE

> Unless I'm missing something, doesn't the project work the way you want if
> you remove the code in the MDIForm_Resize event and place it into the
[quoted text clipped - 295 lines]
> > >
> > > Rick - MVP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.