הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Thursday, September 15, 2011 4:21 PM
Hi everybody.
I need help with this task: how i can put a control (like a checkbox) or a simple button in a form's title bar using VB 2010 and Windows 7? i already studied http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/6b850175-3525-4b5c-9c2f-9ec4e7229bc2 but code samples here just work with WinXP (samples designed in VS2003 & VS2005), no vista nor Win7. Any ideas? help will be appreciated. Thanks.
Bernardo Salazar
All replies (12)
Monday, September 19, 2011 8:11 PM ✅Answered
Hi Liliane, thanks for your interest. During weekend i solved my problem. Exist currently two ways of reaching the solution (sharing here to help others)
-First: making a "borderless" window and trying to mimic a titlebar. Its not a elegant solution, but have as advantage, works in all version of windows and you can make sizable forms. I found a nice .net library that help. Not is perfect, but is enough for now. (im using this option). http://www.codeproject.com/KB/miscctrl/gTitleBar.aspx
-Second: Using Windows Vista and 7's DWM (Desktop Window Manager), you can "extend" the "user area" to cover borders and titles, and make custom titlebar. Disadvantage: works only in Vista and 7 Windows OSes. Another disadvantage is that is very complex to implement, you need to redraw by yourself everything (app icons, title, buttons..). By other side is a elegant and high-tech solution. Here 2 links about this way: http://msdn.microsoft.com/en-us/library/bb688195(VS.85).aspx and http://www.codeproject.com/KB/dialog/AeroNonClientAreaButtons.aspx
I hope this information can be useful to another. If you find is useful, please mark as answer! ;)
Bernardo Salazar
Venezuela
Bernardo Salazar
Thursday, September 15, 2011 6:26 PM
I think that method should work on Vista/7 if Aero theme style is disabled.
You may have to look into DwmExtendFrameIntoClientArea API Function from dwmapi.dll if you want to redraw the whole titilebar.
<DllImport("dwmapi.dll")> Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarinset As MARGINS) As Integer
End Function
Try this article from MSDN on DWM API http://msdn.microsoft.com/en-us/library/bb688195(VS.85).aspx
kaymaf
CODE CONVERTER SITE
http://www.carlosag.net/Tools/CodeTranslator/.
http://www.developerfusion.com/tools/convert/csharp-to-vb/.
Thursday, September 15, 2011 6:29 PM | 1 vote
I Kaymaf. Currently im searching if i can disable aero just for one window (my app comtains several windows). Effectively, if i turn off aero, the samples that already tried works, so, now im trying to draw just one window without using the aeroglass, but not turning off aero globally. It can be done? Thanks anyway for your interest mr Kaymaf.Bernardo Salazar
Thursday, September 15, 2011 6:36 PM
lol you could always take a screenshot of a blank windows form that doesnt have control boxes and then set that as the background image of a borderless form and manually place your control buttons. Won't work if its a sizable window though.
You then could program in the code to move it manually...
Something like this for code to move the window from the titlebar:
Public Class Form2
Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer
Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If MousePosition.X > Me.Left And MousePosition.X < Me.Left + Me.Width Then
If MousePosition.Y > Me.Top And MousePosition.Y < Me.Top + 30 Then
drag = True
mousex = Windows.Forms.Cursor.Position.X - Me.Left
mousey = Windows.Forms.Cursor.Position.Y - Me.Top
End If
End If
End Sub
Private Sub Form2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If drag Then
Me.Top = Windows.Forms.Cursor.Position.Y - mousey
Me.Left = Windows.Forms.Cursor.Position.X - mousex
End If
End Sub
Private Sub Form2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
drag = False
End Sub
End Class
If you want something you've never had, you need to do something you've never done.
Thursday, September 15, 2011 6:45 PM
Hi Paul.. unfortunalety the forms in my app, all are sizable. :(
Because of this, im searching a way to put a button or any kind of control in the Title. Thanks!
Bernardo Salazar
Thursday, September 15, 2011 6:47 PM
You could cheeze it by making a seperate small(borderless) form with your control on it and topmost set to true, and whenever you move your main form, you change the left and top position of the small form so it APPEARS to be in the titlebar, when in truth it is just always above it.
I know... cheeze solution, but it may work for your need... unless your main forms have topmost
If you want something you've never had, you need to do something you've never done.
Thursday, September 15, 2011 6:58 PM
Hi again Paul. the small borderless topmost window sounds like a solution... not a professional or perfect solution, but, solution at all. Now im studying de DWM schema of WinVista/7 to make a custom frame window (little complicated). If i can found my solution here, i will post my code to share with others since its very difficult or near impossible find information about this task. In other hand, if i fail making DWM work with VB 2010, i will use the small window. Stay tuned! hehehe. Greetings from Venezuela mr Paul.Bernardo Salazar
Thursday, September 15, 2011 7:03 PM
If for example, you are putting a checkbox on that form, set the form and the checkbox's back color to gold, and the form's transparency key to gold, and then it will appear to the user as if your control is inside the form.
Heres Some more properties you may want to set:
form3(your control).topmost = true
Form3.shownintaskbar = false
form3.borderstyle = none
form3.backcolor = gold
Form3.Control.Backcolor = gold
form3.transparencykey = gold
Heres some Events you might want to set on the form containing the control in the titlebar:
Private Sub Form2_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
Form3.TopMost = True
Form3.Top = Me.Top + 5
Form3.Left = Me.Left + 90
End Sub
You could put this in a timer on your small control form
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.WindowState = Form2.WindowState
End Sub
If you want something you've never had, you need to do something you've never done.
Thursday, September 15, 2011 7:05 PM
I only promised it was cheezy lol not professional, but it does work on the otherhand... food for thought...If you want something you've never had, you need to do something you've never done.
Monday, September 19, 2011 3:06 AM
Hi Bernardo,
I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions? If you have any concerns, please feel free to follow up.
Have a nice day.
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, September 20, 2011 1:54 AM
Hi Bernardo,
Glad to see you have resolved this issue and thanks for your sharing. This could be beneficial to other community members as well.
Have a nice day.
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, January 14, 2013 6:44 PM
Hello Bernardo Salazar
i have a question:
in your first solution, how do you enable the drag to top to maximize/ minimize function that win7 and win8 has
Bart de Lange