473,465 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to change the Caption of a Borderless Form while Minimized using a Timer?

nicebasic
91 New Member
I have a VB project that has a Borderless form. I'm trying to update its caption while it has been minimized, but I can't.

The code in the "Form" is is follows:
Expand|Select|Wrap|Line Numbers
  1. Public myCounter As Integer
  2.  
  3. Private Sub cmdExit_Click()
  4.     End
  5. End Sub
  6.  
  7. Private Sub cmdMinimize_Click()
  8.     Me.WindowState = vbMinimized
  9. End Sub
  10.  
  11. Private Sub myTimer_Timer()
  12.     myCounter = myCounter + 1
  13.     Me.Caption = myCounter
  14. End Sub

When I click on its "Minimized Caption Bar" or when it Loses Focus, its caption will be updated with the code in the Timer. But this is not what I'm looking for. I'd like to have it updated with the code in the Timer without gaining or losing focus.

I tested other ways. For example, I changed the code in "Sub myTimer_Timer()" to this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub myTimer_Timer()
  2.     myCounter = myCounter + 1
  3.     Me.Show
  4.     Me.Caption = myCounter
  5. End Sub
or even to this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub myTimer_Timer()
  2.     myCounter = myCounter + 1
  3.     Me.SetFocus
  4.     Me.Caption = myCounter
  5. End Sub
Using these two tricks, I can have it updated according to the Interval set for the Timer. But the problem is that its "Minmized Caption Bar" blinks and is rather annoying.

How can I have it updated "Without Blinking"?

Thank you for your help.
Attached Files
File Type: zip Borderless.zip (1.4 KB, 98 views)
Jan 17 '11 #1

✓ answered by Guido Geurs

You can only change the caption if border is shown.
So if You minimize, set the border ON.
When You set the form back (resize), set the border back OFF.

Expand|Select|Wrap|Line Numbers
  1. Public myCounter As Integer
  2.  
  3. Private Sub cmdExit_Click()
  4.     End
  5. End Sub
  6.  
  7. Private Sub cmdMinimize_Click()
  8.     With Me
  9.       .WindowState = vbMinimized
  10.       .ZOrder
  11.       .BorderStyle = vbFixedSingle
  12.    End With
  13. End Sub
  14.  
  15. Private Sub Form_Resize()
  16.    Me.BorderStyle = vbBSNone
  17. End Sub
  18.  
  19. Private Sub myTimer_Timer()
  20.     myCounter = myCounter + 1
  21.       Me.Caption = myCounter
  22. End Sub

9 2320
Guido Geurs
767 Recognized Expert Contributor
You can only change the caption if border is shown.
So if You minimize, set the border ON.
When You set the form back (resize), set the border back OFF.

Expand|Select|Wrap|Line Numbers
  1. Public myCounter As Integer
  2.  
  3. Private Sub cmdExit_Click()
  4.     End
  5. End Sub
  6.  
  7. Private Sub cmdMinimize_Click()
  8.     With Me
  9.       .WindowState = vbMinimized
  10.       .ZOrder
  11.       .BorderStyle = vbFixedSingle
  12.    End With
  13. End Sub
  14.  
  15. Private Sub Form_Resize()
  16.    Me.BorderStyle = vbBSNone
  17. End Sub
  18.  
  19. Private Sub myTimer_Timer()
  20.     myCounter = myCounter + 1
  21.       Me.Caption = myCounter
  22. End Sub
Jan 18 '11 #2
nicebasic
91 New Member
Thank you, Mr. Guido Geurs,

You're a great expert. I applied your code to the project. Attached to this post, you'll find the "Modified Project". But, something is wrong.

When I minimize the form, its caption will be updated as I needed. But, something really odd happens. Every time, after minimizing the form, if you double click on the minimized form to restore it, it will be restored, but, unfortunately, it shrinks and gets smaller.

If you minimize and restore the form several times, you won't see anything when restoring the form. The form vanishes.
Attached Files
File Type: zip Borderless_2.zip (1.4 KB, 87 views)
Jan 18 '11 #3
nicebasic
91 New Member
I made some changes to the code to fix this bug. Here's the new code:
Expand|Select|Wrap|Line Numbers
  1. Public myCounter As Integer
  2. Public myFormWidth As Long
  3. Public myFormheight As Long
  4.  
  5. Private Sub cmdExit_Click()
  6.     End
  7. End Sub
  8.  
  9. Private Sub cmdMinimize_Click()
  10.     With Me
  11.         .WindowState = vbMinimized
  12.         .ZOrder
  13.         .BorderStyle = vbFixedSingle
  14.     End With
  15. End Sub
  16.  
  17. Private Sub Form_Load()
  18.     myFormWidth = Me.Width
  19.     myFormheight = Me.Height
  20. End Sub
  21.  
  22. Private Sub Form_Paint()
  23.     Me.Width = myFormWidth
  24.     Me.Height = myFormheight
  25. End Sub
  26.  
  27. Private Sub Form_Resize()
  28.     Me.BorderStyle = vbBSNone
  29. End Sub
  30.  
  31. Private Sub myTimer_Timer()
  32.     myCounter = myCounter + 1
  33.     Me.Caption = myCounter
  34. End Sub
Thanks to your help, nearly 90% of the job has been done.

There is only one problem. If you minimize the form, and then, double click on the "Minimized Caption Bar" to restore the form, at first, the Caption of the Form is visible and after a very very short time, it changes to nothing and becomes invisible.

Is there any method to fix this bug? I mean, when you double click on the "Minimized Caption Bar" to restore the form, prevent the Caption of the Form to be visible even for a very very short time?

Thank you for your great help.
Attached Files
File Type: zip Borderless_3.zip (1.5 KB, 75 views)
Jan 19 '11 #4
Guido Geurs
767 Recognized Expert Contributor
With the code=
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdMinimize_Click() 
  2.     With Me 
  3.         .WindowState = vbMinimized 
  4.         .ZOrder 
  5.         .BorderStyle = vbFixedSingle 
  6.     End With 
  7. End Sub 
  8.  
  9. Private Sub Form_Resize() 
  10.     Me.BorderStyle = vbBSNone 
  11. End Sub 
When The code does a Minimize then it takes (remembers) the size of the "No border" and set then the border "FixedSingle" with the size of "No Border".
When it Resizes, the borders will be the original min borderwidth and the titelbar !

With the code:
Expand|Select|Wrap|Line Numbers
  1. Public myCounter As Integer
  2.  
  3. Private Sub cmdExit_Click()
  4.     End
  5. End Sub
  6.  
  7. Private Sub cmdMinimize_Click()
  8.     With Me
  9.         .BorderStyle = vbFixedSingle
  10.         .WindowState = vbMinimized
  11.         .ZOrder
  12.     End With
  13. End Sub
  14.  
  15. Private Sub Form_Resize()
  16.          Me.BorderStyle = vbBSNone
  17.          Me.ZOrder
  18. End Sub
  19.  
  20. Private Sub myTimer_Timer()
  21.     myCounter = myCounter + 1
  22.     Me.Caption = myCounter
  23. End Sub
  24.  
It's OK : it sets first the frame back and then minimizes.
Jan 19 '11 #5
nicebasic
91 New Member
I changed the following parts of the code using your suggested code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdMinimize_Click()
  2.     With Me
  3.         .BorderStyle = vbFixedSingle
  4.         .WindowState = vbMinimized
  5.         .ZOrder
  6.     End With
  7. End Sub
  8.  
  9. Private Sub Form_Resize()
  10.          Me.BorderStyle = vbBSNone
  11.          Me.ZOrder
  12. End Sub
But, this way, the "Minimized Caption Bar" doesn't get updated. It only gets updated when losing and gaining focus.

You're a great expert. Thank you a million times for your kind help.

I'm so happy to see intelligent experts like you in Bytes.com (a really valuable and excellent website for programmers).

Best wishes for you.
Jan 19 '11 #6
Guido Geurs
767 Recognized Expert Contributor
Sorry for my inattention but I think this is finally the one:

Expand|Select|Wrap|Line Numbers
  1. Dim ORGWIDTH As Long
  2. Dim ORGHEIGHT As Long
  3. Public myCounter As Integer
  4.  
  5. Private Sub cmdExit_Click()
  6.     End
  7. End Sub
  8.  
  9. Private Sub cmdMinimize_Click()
  10.     With Me
  11.       .WindowState = vbMinimized
  12.       .ZOrder
  13.    End With
  14. End Sub
  15.  
  16. Private Sub Form_Load()
  17.    With Me
  18.       ORGWIDTH = .Width
  19.       ORGHEIGHT = .Height
  20.    End With
  21. End Sub
  22.  
  23. Private Sub Form_Resize()
  24.    With Me
  25.       If .WindowState = vbMinimized Then
  26.          .BorderStyle = vbFixedSingle
  27.       Else
  28.          .BorderStyle = vbBSNone
  29.          .Width = ORGWIDTH
  30.          .Height = ORGHEIGHT
  31.       End If
  32.       .ZOrder
  33.    End With
  34. End Sub
  35.  
  36. Private Sub myTimer_Timer()
  37.    myCounter = myCounter + 1
  38.    Me.Caption = myCounter
  39. End Sub
Jan 20 '11 #7
nicebasic
91 New Member
Thank you, sir.

You're so kind and attentive to this matter. I appreciate your help.

This is the code with your modifications. But, still the problem is there. When you "Double Click" on the "Minimized Caption Bar", it will be resized to the "Original Form Size", but at first, the Caption of the Form is visible. After a very short time, it disappears. This doesn't make any problems, though.

Again, thank you for your attention.
Attached Files
File Type: zip Borderless_4.zip (1.5 KB, 90 views)
Jan 20 '11 #8
Guido Geurs
767 Recognized Expert Contributor
After a few trays I think I have found the solution for resetting the border immediately ofter maximize: Only the code "Me.Caption = Me.Caption" will rebuild the border.
Not .Refresh, ... ore anything else!

So the code must be=
Expand|Select|Wrap|Line Numbers
  1. Dim ORGWIDTH As Long
  2. Dim ORGHEIGHT As Long
  3. Public myCounter As Integer
  4.  
  5. Private Sub Form_Load()
  6.    With Me
  7.       ORGWIDTH = .Width
  8.       ORGHEIGHT = .Height
  9.    End With
  10. End Sub
  11.  
  12. Private Sub Form_Resize()
  13.    With Me
  14.       If .WindowState = vbMinimized Then
  15.          .BorderStyle = vbFixedSingle
  16.       Else
  17.          .BorderStyle = vbBSNone
  18.          .Caption = .Caption
  19.          .Width = ORGWIDTH
  20.          .Height = ORGHEIGHT
  21.       End If
  22.       .ZOrder
  23.    End With
  24. End Sub
  25.  
  26. Private Sub cmdExit_Click()
  27.     End
  28. End Sub
  29.  
  30. Private Sub cmdMinimize_Click()
  31.     With Me
  32.       .WindowState = vbMinimized
  33.       .ZOrder
  34.    End With
  35. End Sub
  36.  
  37. Private Sub myTimer_Timer()
  38.    myCounter = myCounter + 1
  39.    Me.Caption = myCounter
  40. End Sub
Jan 22 '11 #9
nicebasic
91 New Member
Thank you, Mr. Guido Geurs,

Honestly, I have to say that you're a really great and talented Solution Developer. I can't believe that it has been solved.

Using your incredible method to solve this problem, I added one line to your final solution.

Now, thanks to your great solution, when I click on the "Minimized Caption Bar" to restore the program to its Original Size, the problem has been fixed. But, when I click on the Minimize Button to Minimize the program, a problem still exists. I mean, if you press the Minimize Button, the program will be minimized, but for a very very short time, you can see the Minimized Caption Bar has "Windows Classic Style", even if you use "Windows XP Style" theme on your computer.

This is a modification of Sub Form_Resize():
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Resize()
  2.    With Me
  3.       If .WindowState = vbMinimized Then
  4.          .BorderStyle = vbFixedSingle
  5.          .Caption = .Caption      '==> This line has been added!
  6.       Else
  7.          .BorderStyle = vbBSNone
  8.          .Caption = .Caption
  9.          .Width = ORGWIDTH
  10.          .Height = ORGHEIGHT
  11.       End If
  12.       .ZOrder
  13.    End With
  14. End Sub
Actually, I was disappointed and I thought it wasn't possible to solve this problem. But you made it possible.

You did a great job. Thank you very much, my dear friend.
Jan 22 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: plank | last post by:
Hey, I am new to C# and am trying to resize a borderless form with the mouse is pressed and dragged within a specified rectangle coordinates on the form. Any help would be much appreciated! ...
0
by: Nikki | last post by:
Hi, I m developing a window's application in c#. As due to non-rectangular forms, i m using borderless form. Now i need help in how to provide user with resizing facality of the form using mouse....
1
by: notregister | last post by:
hi, in VB6 i can change the caption of the form by using frmMain.Caption = "ABC" how do i change it in .NET?? the text i want to change is found at the form1's properties > Appearance> text
4
by: David Gouge | last post by:
Hi All, I have a borderless form that i can drag around fine when dragging anywhere on the form by using the following code: protected override void WndProc(ref Message m) { const int...
1
by: SeanR | last post by:
Hi, I wasn't happy with the customisability of the standard Windows form, so I decided to implement my own. Basically what I did was extend a borderless form and add my own borders and caption...
3
by: Rick | last post by:
I know I seen this before but IO cannot find it. How to you drag a borderless form in Vb.net 2005
8
by: James Arnold | last post by:
I currently have a borderless form, which I am subclassing to allow dragging & dropping: Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg Case 132 'Click & Drag Form...
5
by: sierra7 | last post by:
Hi I have been writing Access applications for some years now and have moved away from from the 'Switchboard' type of opening form to using a menubar accross the top of the screen and borderless...
2
by: plevintampabay | last post by:
I have a borderless form in C#. The form has an icon specified in its properties and I also have the same icon specified for the project in the project properties. When I had a border on the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.