Results 1 to 6 of 6

Thread: form resize [resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65

    form resize [resolved]

    i have a picbox that i use to draw a graph. dock is set to fill so it will consume the entire graph. but, the graph is scaled and becomes stretched when the user resizes one border of the form. i want the form to always be a square shape, so the height and width are always the same.

    i use this code right now, but it gives me a nice little infinite loop:
    VB Code:
    1. Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    2.         If Me.Width > Me.Height Then
    3.             Me.Height = Me.Width
    4.         Else
    5.             Me.Width = Me.Height
    6.         End If
    7.     End Sub

    any suggestions?
    Last edited by joeframbach; May 20th, 2003 at 06:57 PM.
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Strange, on my machine it doesn't infinitely loop (although it looks to me like it ought to). Why don't you try:

    VB Code:
    1. Private Sub Form1_Resize(ByVal sender As Object, _
    2.     ByVal e As System.EventArgs) Handles MyBase.Resize
    3.         If Me.Width <> Me.Height Then
    4.             If Me.Width > Me.Height Then
    5.                 Me.Height = Me.Width
    6.             Else
    7.                 Me.Width = Me.Height
    8.             End If
    9.         End If
    10.     End Sub

    This should reduce the number of times the event fires (avoid adjusting width/height if they are already equal)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65
    wow. thanks. that was really obvious.
    but im not gonna put [resolved] up there cuz it still flickers
    Last edited by joeframbach; May 18th, 2003 at 06:59 PM.
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    It is going to flicker because while the user is resizing your form while you are adjusting it also, making it fight back and forth drawing and redrawing the form.

    Here is one way to stop that, but you don't get the effect visually:
    VB Code:
    1. Dim formResized As Boolean
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         formResized = False
    5.     End Sub
    6.  
    7.     Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    8.         formResized = True
    9.     End Sub
    10.  
    11.     Private Sub Form1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter
    12.         If formResized = True Then
    13.             MessageBox.Show("Form was resized")
    14.             Me.Width = Me.Height
    15.             formResized = False
    16.         End If
    17.     End Sub
    Last edited by hellswraith; May 18th, 2003 at 07:28 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65
    works great! but there has to be a faster way...
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    If you dont want Hellswraith code then the other code will make flicker unless you change your display settings in windows. If you are using windows XP then go to Display Setting, Choose Appearance>Effects and remove the tick where it says: 'Show window contents while dragging'
    There should be somthing similar for other windows too.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width