Prevent form/timer hanging while holding the minimize button

I got troubles when the customers holding the minimize button (without release) on my form, it make all forms and all timers/controls entirely hanging. And thus make some exception bugs for my application.
 Steps to Reproduce Behavior:
In Form1,  create a Timer1 & Label1 and paste this code :
Public Class Form1
Public a As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
a = a + 1
Label1.Text = a
End Sub
End Class
Press F5 to run the application. You will see the number display on Label1 increase rapidly. Now try to hold the Minimize button and the timer will hang up, label1 stop increasing. Release the minimize button will make the timer resume increasing.
I want my timer and all controls in form still working while holding the minimize button. Is there any good resolution for my issue ?

various possible resolution. remove controlbox. remove text. draw text if wanted. draw controls. use system.timers.timer. system menu removed so no menu for move size minimize maximize close available.
https://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
form transparent background in image. movement or buttons not affect timer may affect display speed.
Option Strict On
Imports System.Timers
Public Class Form1
' Code from this link - http://www.dreamincode.net/forums/topic/275178-drawing-icon-on-form-border/
WithEvents Timer1 As New System.Timers.Timer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Me.ControlBox = False
Me.Text = ""
Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
Timer1.Interval = 10
AddHandler Timer1.Elapsed, AddressOf Timer1_Elapsed
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Timer1.Enabled = False
End Sub
'A form with custom border and title bar.
'Some functions, such as resize the window via mouse, are not implemented yet.
'The color and the width of the border.
Private borderColor As Color = Color.GreenYellow
Private borderWidth As Integer = 3
'The color and region of the header.
Private headerColor As Color = Color.GreenYellow
Private headerRect As Rectangle
'The region of the client.
Private clientRect As Rectangle
'The region of the title text.
Private titleRect As Rectangle
'The region of the minimum button.
Private miniBoxRect As Rectangle
'The region of the maximum button.
Private maxBoxRect As Rectangle
'The region of the close button.
Private closeBoxRect As Rectangle
'The states of the three header buttons.
Private miniState As ButtonState
Private maxState As ButtonState
Private closeState As ButtonState
'Store the mouse down point to handle moving the form.
Private x As Integer = 0
Private y As Integer = 0
'The height of the header.
Const HEADER_HEIGHT As Integer = 25
'The size of the header buttons.
ReadOnly BUTTON_BOX_SIZE As Size = New Size(15, 15)
Dim Test As Boolean = False
Private Sub CustomBorderColorForm_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
'Draw the header.
Using b As Brush = New SolidBrush(Color.FromArgb(10, Color.White))
e.Graphics.FillRectangle(b, headerRect)
End Using
'Draw the title text
If Test = False Then
Using b As Brush = New SolidBrush(Me.ForeColor)
e.Graphics.DrawString("Anything you want Baby", Me.Font, b, titleRect)
End Using
ElseIf Test = True Then
Using b As Brush = New SolidBrush(Me.ForeColor)
e.Graphics.DrawString("Hello Dolly", Me.Font, b, titleRect)
End Using
End If
'Draw the header buttons.
If Me.MinimizeBox Then
ControlPaint.DrawCaptionButton(e.Graphics, miniBoxRect, CaptionButton.Minimize, miniState)
End If
If Me.MinimizeBox Then
ControlPaint.DrawCaptionButton(e.Graphics, maxBoxRect, CaptionButton.Maximize, maxState)
End If
If Me.MinimizeBox Then
ControlPaint.DrawCaptionButton(e.Graphics, closeBoxRect, CaptionButton.Close, closeState)
End If
'Draw the border.
ControlPaint.DrawBorder(e.Graphics, clientRect, borderColor, _
borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid)
End Sub
'Handle resize to adjust the region ot border, header and so on.
Private Sub CustomBorderColorForm_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
headerRect = New Rectangle(Me.ClientRectangle.Location, New Size(Me.ClientRectangle.Width, HEADER_HEIGHT))
clientRect = New Rectangle(New Point(Me.ClientRectangle.Location.X, Me.ClientRectangle.Y + HEADER_HEIGHT), _
CType(New Point(Me.ClientRectangle.Width, Me.ClientRectangle.Height - HEADER_HEIGHT), Drawing.Size))
Dim yOffset = (headerRect.Height + borderWidth - BUTTON_BOX_SIZE.Height) / 2
titleRect = New Rectangle(CInt(yOffset), CInt(yOffset), _
CInt(Me.ClientRectangle.Width - 3 * (BUTTON_BOX_SIZE.Width + 1) - yOffset), _
BUTTON_BOX_SIZE.Height)
miniBoxRect = New Rectangle(Me.ClientRectangle.Width - 3 * (BUTTON_BOX_SIZE.Width + 1), _
CInt(yOffset), BUTTON_BOX_SIZE.Width, BUTTON_BOX_SIZE.Height)
maxBoxRect = New Rectangle(Me.ClientRectangle.Width - 2 * (BUTTON_BOX_SIZE.Width + 1), _
CInt(yOffset), BUTTON_BOX_SIZE.Width, BUTTON_BOX_SIZE.Height)
closeBoxRect = New Rectangle(Me.ClientRectangle.Width - 1 * (BUTTON_BOX_SIZE.Width + 1), _
CInt(yOffset), BUTTON_BOX_SIZE.Width, BUTTON_BOX_SIZE.Height)
Me.Invalidate()
End Sub
Private Sub CustomBorderColorForm_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
'Start to move the form.
If (titleRect.Contains(e.Location)) Then
x = e.X
y = e.Y
End If
'Check and press the header buttons.
Dim mousePos As Point = Me.PointToClient(Control.MousePosition)
If (miniBoxRect.Contains(mousePos)) Then
miniState = ButtonState.Pushed
ElseIf (maxBoxRect.Contains(mousePos)) Then
maxState = ButtonState.Pushed
ElseIf (closeBoxRect.Contains(mousePos)) Then
closeState = ButtonState.Pushed
End If
End Sub
Private Sub CustomBorderColorForm_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
'Move and refresh.
If (x <> 0 And y <> 0) Then
Me.Location = New Point(Me.Left + e.X - x, Me.Top + e.Y - y)
Me.Refresh()
End If
End Sub
Private Sub CustomBorderColorForm_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
'Reset the mouse point.
x = 0
y = 0
'Check the button states and modify the window state.
If miniState = ButtonState.Pushed Then
Me.WindowState = FormWindowState.Minimized
miniState = ButtonState.Normal
ElseIf maxState = ButtonState.Pushed Then
If Me.WindowState = FormWindowState.Normal Then
Me.WindowState = FormWindowState.Maximized
maxState = ButtonState.Checked
Else
Me.WindowState = FormWindowState.Normal
maxState = ButtonState.Normal
End If
ElseIf closeState = ButtonState.Pushed Then
Me.Close()
End If
End Sub
'Handle this event to maxmize/normalize the form via double clicking the title bar.
Private Sub CustomBorderColorForm_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDoubleClick
If (titleRect.Contains(e.Location)) Then
If Me.WindowState = FormWindowState.Normal Then
Me.WindowState = FormWindowState.Maximized
maxState = ButtonState.Checked
Else
Me.WindowState = FormWindowState.Normal
maxState = ButtonState.Normal
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Test = False Then
Test = True
Me.Invalidate()
Else
Test = False
Me.Invalidate()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Timer1.Enabled = False Then
Timer1.Enabled = True
Else
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Elapsed(sender As Object, e As ElapsedEventArgs)
Invoke(New Timer1sDelegate(AddressOf Timer1sSub))
End Sub
Private Delegate Sub Timer1sDelegate()
Private Sub Timer1sSub()
Label1.Text = Now.Ticks.ToString
End Sub
End Class
La vida loca

Similar Messages

  • HT4623 The "Software Update" feature is not available in my Ipod 2nd Generation unit while the upgrade option in iTunes keeps on hanging while downloading the upgrade iOS (time out error). So, please tell me how I can upgrade the iOS.

    The "Software Update" feature is not available in my Ipod 2nd Generation unit while the upgrade option in iTunes keeps on hanging while downloading the upgrade iOS (time out error). So, please tell me how I can upgrade the iOS.

    The Settings>General>Software Update comes with iOS 5. The 2G can only go to iOS 4.2.1
    Try disabling the computer's security software during the download and update.

  • I was on the phone last night and my phone randomly turned off.  It will not come back on even when I have tried to hold the home button and the power button together while being plugged into the computer.  What do I do?

    I was on the phone last night and my phone randomly turned off. It will not come back on even when I have tried to hold the home button and the power button at the same time, while being plugged into the computer? What do I do?

    Plug it into power for at least 15 minutes.  If it doesn't automatically come on, try a reset... press the home and sleep (on/off) buttons until you see the Apple logo, ignoring the slider. Takes about 5-15 secs of button holding and you won't lose any data or settings.

  • I have a mac book pro running Lion 10.7.4 and every time I use Google Earth The computer crashes by lowering a black curtain and then asking me to hold the power button down until it closes and press the power button again to restart it. Can I fix this?

    I have a mac book pro running Lion 10.7.4 and every time I use Google Earth The computer crashes by lowering a black curtain and then asking me to hold the power button down until it closes and press the power button again to restart it. Can I fix this? It bugs me when I'm looking at real estate.

    I really don't have an answer for that one. I guess that while trying to get things working correctly, I would use the most basic monitor I had which in your case would be the Eizon using the Thunderbolt port and adaptor.
    When you boot into Safe Mode the startup is quite slow, but you should get the Apple logo and then the spinning gear below it (release the SHIFT key when it appears.) Then after a little more time you should see a gray progress bar appear below the spinning gear. When that disappears the computer will startup to a login screen.

  • Boot while holding the OPTION key doesn't work.

    This is really dumb.  I was thinking today my passwords were too weak, so I set out to put Keychains to use.  First thing I did was reset my login password - but then changed my mind and reset it again.  Didn't write any of this down and now I can't correctly type in an admin password. 
    SO I searched and found how to boot into the "Recovery Partition" by restarting while holding the OPTION key.  This worked!  I used the resetpassword in Terminal - and successfully reset the ROOT administrator password.  I figured that was me.  And my advisor (article I found on-line) didn't mention NOT to.
    I still need to reset my admin user password, but now when I try to do the Recovery Partition trick my display remains blank.  I can tell it's powered up, but no progress bar or apple logo...  One further clue is that if I give up and let go of the OPTION key (because nothing at all is happening) five minutes pass (not 20 seconds or so like the time it worked) and the computer starts up as usual.  No "OS X Utilities" window, just the everyday wallpaper and file folders.
    So that's my situation.  Many thanks in advance.
    I should mention, I'm using a mac Pro and the latest version of Yosemite.  And a hardwired keyboard and mouse...

    Is the key(s) stuck, or sticky or not very responsive?
    try another keyboard, any usb keyboard for windows or another mac should work.
    try flipping your keyboard over and letting it bang on the desktop, your r key could be gunked up and the contact might have failed. Depending on the model keyboard liquid or food or something else could be trapped, the older bondi-plastic ones do this more than the aluminum-plastic ones but the key could need a good smacking,.

  • My imac won't start even while holding the options key

    Can some one direct me to something to do.  My iMac, about 3 years old using the latest operating system won't bot up.  Initially I was geting the ?. but after tryint to restart while holding the "option" key, it just went to a bleank. but lit screen.

    It sounds like your HD or main logic board has failed. Try running Apple Hardware Test in Extended Mode. If no errors are reported on the first pass run it 2-3x to be sure. Running in Extended Mode is the most thorough however it is time consuming, don't be surprised if each pass takes 40-60 minutes. 

  • Everytime I start up my Mac mini I'll be able to use it only for a little while then the beach ball appears and it won't let me do anything I have to keep forcing it to turn off by holding the power button can someone help me?

    I have no external devices connected to my Mac mini but still everytime I use it after about half hour to an hour in whatever I'm using wether it's the Internet or iPhoto or iTunes the beach ball appears and I cannot get it to stop I always have to press and hold the power button and force it to switch off I then do a safe reboot and it starts up again fine but same thing again after a certain amount of time it will freeze. I have also had on some occasions a bright white screen with a folder and a flashing question mark appear but it's not because of any external devices as they have all been removed please can someone help me as I have no idea why this keeps happening to my computer and I'm worried that there's something seriously wrong it's only about 6 months old and I have no experience in dealing with computers ??

    EtreCheck version: 2.1.8 (121)
    Report generated 13 February 2015 15:33:46 GMT
    Download EtreCheck from http://etresoft.com/etrecheck
    Click the [Click for support] links for help with non-Apple products.
    Click the [Click for details] links for more information about that line.
    Hardware Information: ℹ️
        Mac mini (Late 2012) (Technical Specifications)
        Mac mini - model: Macmini6,1
        1 2.5 GHz Intel Core i5 CPU: 2-core
        4 GB RAM Upgradeable
            BANK 0/DIMM0
                2 GB DDR3 1600 MHz ok
            BANK 1/DIMM0
                2 GB DDR3 1600 MHz ok
        Bluetooth: Good - Handoff/Airdrop2 supported
        Wireless:  en1: 802.11 a/b/g/n
    Video Information: ℹ️
        Intel HD Graphics 4000
            LG TV spdisplays_1080p
    System Software: ℹ️
        OS X 10.10.2 (14C109) - Time since boot: 0:11:35
    Disk Information: ℹ️
        APPLE HDD ST500LM012 disk0 : (500.11 GB)
            EFI (disk0s1) <not mounted> : 210 MB
            Macintosh HD (disk0s2) / : 499.25 GB (398.54 GB free)
            Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
    USB Information: ℹ️
        Apple Inc. BRCM20702 Hub
            Apple Inc. Bluetooth USB Host Controller
        Apple, Inc. IR Receiver
    Thunderbolt Information: ℹ️
        Apple Inc. thunderbolt_bus
    Configuration files: ℹ️
        /etc/sysctl.conf - Exists
    Gatekeeper: ℹ️
        Mac App Store and identified developers
    Kernel Extensions: ℹ️
            /Applications/AVG AntiVirus.app
        [loaded]    com.avg.Antivirus.OnAccess.kext (2015.0 - SDK 10.8) [Click for support]
    Launch Agents: ℹ️
        [running]    com.avg.Antivirus.gui.plist [Click for support]
    Launch Daemons: ℹ️
        [loaded]    com.adobe.fpsaud.plist [Click for support]
        [running]    com.avg.Antivirus.infosd.plist [Click for support]
        [running]    com.avg.Antivirus.services.plist [Click for support]
    User Login Items: ℹ️
        iTunesHelper    Application  (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)
    Internet Plug-ins: ℹ️
        Silverlight: Version: 5.1.30514.0 - SDK 10.6 [Click for support]
        FlashPlayer-10.6: Version: 16.0.0.305 - SDK 10.6 [Click for support]
        Flash Player: Version: 16.0.0.305 - SDK 10.6 [Click for support]
        QuickTime Plugin: Version: 7.7.3
        Default Browser: Version: 600 - SDK 10.10
    3rd Party Preference Panes: ℹ️
        Flash Player  [Click for support]
    Time Machine: ℹ️
        Time Machine not configured!
    Top Processes by CPU: ℹ️
             5%    WindowServer
             1%    AVG
             0%    AppleSpell
             0%    fontd
             0%    cloudpaird
    Top Processes by Memory: ℹ️
        215 MB    com.apple.WebKit.WebContent
        125 MB    avgd
        107 MB    Safari
        90 MB    Messages
        69 MB    WindowServer
    Virtual Memory Information: ℹ️
        171 MB    Free RAM
        1.68 GB    Active RAM
        1.53 GB    Inactive RAM
        637 MB    Wired RAM
        1.34 GB    Page-ins
        2 MB    Page-outs
    Diagnostics Information: ℹ️
        Feb 13, 2015, 03:20:28 PM    Self test - passed
        Feb 6, 2015, 08:08:07 PM    /Library/Logs/DiagnosticReports/Kernel_2015-02-06-200807_[redacted].panic [Click for details]

  • My Macbook Pro *****! I have had it for 2 weeks now, got it brand new at the apple store, it freezes all the time, and reboots itself, sometimes when i start it, purple dots cover the screen and i have to hold the power button.

    I have had it for 2 weeks now, got it brand new at the apple store, it freezes all the time, and reboots itself, sometimes when i start it, purple dots cover the screen and i have to hold the power button. a 2 week old computer is not supposed to do this! it wastes all its time being so flashy that it just craps out all the time. sometimes i feel like i should have stayed with my virus covered PC. at least when it shut down randomly you could turn it back on, but with the macbook pro, it just keeps restarting itself over and over. need help with this, any answers?

    Here's a novel thought. Take it back to the vendor. Should have done that one week ago.

  • When i click on my external hard drive the screen goes dark and a msg pops up saying i have to shut down my computer by holding the power button and then restart it. when i do that i get the same result every time. it worked perfectly last night..

    when i click on my external hard drive the screen goes dark and a msg pops up saying i have to shut down my computer by holding the power button and then restart it. when i do that i get the same result every time. it worked perfectly last night..

    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Ifou don't see any reports listed, but you know there was a panic, you may have chosen Diagnostic and Usage Messages from the log list. Choose DIAGNOSTIC AND USAGE INFORMATION instead.
    In the Console window, select
              DIAGNOSTIC AND USAGE INFORMATION ▹ System Diagnostic Reports
    (not Diagnostic and Usage Messages) from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar.
    There is a disclosure triangle to the left of the list item. If the triangle is pointing to the right, click it so that it points down. You'll see a list of reports. A panic report has a name that begins with "Kernel" and ends in ".panic". Select the most recent one. The contents of the report will appear on the right. Use copy and paste to post the entire contents—the text, not a screenshot.
    If you don't see any reports listed, but you know there was a panic, you may have chosen Diagnostic and Usage Messages from the log list. Choose DIAGNOSTIC AND USAGE INFORMATION instead.
    In the interest of privacy, I suggest that, before posting, you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header of the report, if it’s present (it may not be.)
    Please don’t post other kinds of diagnostic report.
    I know the report is long, maybe several hundred lines. Please post all of it anyway.

  • I-phone shuts off, I have to hold the home and power button at the same time to get the icon to show up.  Then have to hold the home button.  I'm restoring my phone multiple times a day just to get it to work. help!

    i-phone shuts off, I have to hold the home and power button at the same time to get the icon to show up.  Then have to hold the home button.  I'm restoring my phone multiple times a day just to get it to work. help!

    Are you restoring as new?

  • Blackberry 9320 gets hang while receiving the call

    Hello Team,
    I have took th Blackberry just 4 days back and i am facing a problem already and it was my dream to buy the blackberry but after buying just after 4 days my cell hangs while recieving the call, only trackpad works and i cannot unlock the phone as well and i have to remove battery and restart the phone to make it work please suggest me what has to be done to make my phone to work properly do i have to take it servise centre or any suggestion which i can do to solvethis issue.... Blackberry is my dream phone and this bug has dissapointed me a lot just after 4 days after purchasing i am facing the issue.. Please help me....
    Thank you,
    Lohith

    Hey lohithkavali,
    Welcome to the BlackBerry Support Community Forums.
    Thanks for the question.
    I would suggest reloading the software and then test the issue prior to restoring any data.  Follow the steps in this KB article: www.blackberry.com/btsc/KB11320
    Let me know if you have any more questions.
    Cheers.
    -ViciousFerret
    Come follow your BlackBerry Technical Team on Twitter! @BlackBerryHelp
    Be sure to click Like! for those who have helped you.
    Click  Accept as Solution for posts that have solved your issue(s)!

  • HT1533 I have tried a hundred times pressing or holding the d key at power up and nothing happens ! What is the secret ?

    I have tried a hundred times pressing or holding the d key at power up and nothing happens ! What is the secret ?

    At the top of this page is a link to the startup key combinations.
    Learn about Startup key combinations for Intel-based Macs

  • Adpatch hangs while compiling the PLL's in 11i

    Hi All,
    My Adpatch session hangs at the stage while compiling PLL's without any error in adpatch log,worker log and alert log.
    the worker state shows in running state and will not change the state then after.
    We will all the f60gen process keep running at the backend without completion.
    When we manually compile and issue the same f60gen command it works.
    Please some one help on the issue.Support is nothing to help on this.
    Thx,
    Raghu

    Pl do not post duplicates - adpatch hangs while compiling the PLL's in 11i

  • Apple charged me 8 times $1 while changing the country and purchase from app stores. Help pls

    Hi all
    Apple charged me 8 times $1 while changing the country and purchase from app stores.
    Help pls, I want my money back

    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • My macbook won't start up i have used the option command p r while holding down power button but not done.. please help guys

    my macbook won't start up i have used the option command p r while holding down power button but not done.. please help guys

    It not polite to repost asking fro more help three minutes after initial post.
    Recovery mode is Command & R keys after depressing and releasing the Power button  for a normal startup.
    OS X: About OS X Recovery - Apple Support
    That only works for Lion and later.
    What exactly happens when your try to boot to Recovery?
    Try starting in Safe Mode resetting the SMC and NVRAM/PRAM
    OS X: What is Safe Boot, Safe Mode?
    Intel-based Macs: Resetting the System Management Controller (SMC)
    About NVRAM and PRAM
    What model MacBook Pro and what OSX version was on the Mac?
    Have you tried booting from an OSX install DVD?
    When you try to start doe the Power light light?
    This is the Mac Pro desktop forum. I requested your post be moved to the MacBook Pro laptop forum.

Maybe you are looking for