Windows button appearance in a VB 2008 application - vb.net

I am creating a Win32-application in Visual Basic 2008. I would like to have a button in the form, with custom color (BackColor), on MouseEnter event. This works fine, but as you can see below, this custom color doesn't cover the whole area of the button. The button border remains as standard (Windows 7). Can I somehow have this color for the whole button? I don't want to use Flat button style, I prefer this Standard style, which has the normal Windows look.

What I typically do is this I first gather two buttons that look similar, such as this Pic A and B.
Then I will put in those two picture into my Resources.
After I begin coding the function such as the Example I have made down below.
Now their are two ways of going about this. There is a hover option as seen below:
Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles PictureBox1.MouseHover
PictureBox1.Image = My.Resources.Button1
End Sub
or there is this option which has way better response times when moving your mouse:
Private Sub PictureBox1_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox1.MouseEnter
PictureBox1.Image = My.Resources.Button1
End Sub
Then you need this to set things back to normal:
Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
PictureBox1.Image = My.Resources.Button
End Sub
Real simple code but in a realistics thats all you need! I typically hate the buttons! I find myself messing with the button look more then I actually code, really simple to just go to Photoshop and make a easy button that looks good!
I read your Question don't worry but to be honest that style button looks old fashion the buttons I made are more up to date and Modern!

Related

How to Mix Form Fields and Graphics?

I am trying to use the circular progress bar solution that was provided at
Visual basic circular progress bar
However I am getting a lot of error messages when I try to incorporate it within a Windows Form that has textbox entries (have to do with System.EventArgs versus PaintEventArgs and MyBase.Load versus Me.Paint).
I tried "mixing" both handles like this:
Private Sub LoginForm1_Load(ByVal sender As System.Object, e As System.EventArgs, g as PaintEventArgs) Handles MyBase.Load, Me.Paint
but of course that bombed out. Can someone please advise what are my alternatives here?
Thanks
You're taking something very easy and making it hard. ALL drawing gets done in the Paint event handler or a method called from the Paint event handler. That's it, that's all when it comes to drawing. You already know how to do that because you already have the code to do it from another question. Use that code.
If the code that does the drawing needs to get data from elsewhere to know what to draw then do that. There's nothing magical about a method using the value of one or more fields to do its work. The data in that field(s) can be put there by any other method, e.g. the Load event handler of the form, the TextChanged event handler of a TextBox or the Click event handler of Button.
Here's a simple example that will draw whatever is in a TextBox as the user types:
Private textToDraw As String
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.Text
textToDraw = TextBox1.Text
'Force a Paint event to be raised.
Invalidate()
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.DrawString(textToDraw, Font, Brushes.Black, PointF.Empty)
End Sub
Put the data where it can be accessed, raise a Paint event, do the drawing. Simple!
The main point to note there is that calling Invalidate with no arguments will cause the entire control it's called on (the form, in this case) to be repainted and that should be avoided if possible. You should calculate and specify the smallest area possible that has or could have changed and pass that when calling Invalidate. That way, parts of the control that definitely haven't changed will not be repainted, speeding up the process. You draw everything every time but the actual repainting of pixels on the screen is the slow part of the operation and so should be minimised. You might read this for more information.

How to detect a collision in a Windows Store apps?

This is my first question on Stack Overflow's possible that I'll make mistakes. (and I use a internet translator)
I do not know how to detect collision in Windows Store apps. On Windows Forms it looks like this:
If Player.Bounds.IntersectsWith (Enemy1.Bounds) Then
'do something
End If
Please give me function that returns a boolean. Thank you for all the answers.
You can give me c# code i will convert it!
This is just a function with a boolean value as result. You can try this with two simple controls, with buttons for example.
You can create a new project, add two buttons and put them away, then launch the window app, then overlap them and relaunch the app.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Button1.Bounds.IntersectsWith(Button2.Bounds) Then 'this return true/false
MsgBox("Collision detected")
End If
end sub

VB.Net: How to display groupbox on right click?

I am making a VB.Net web browser, and to make the whole thing look nice, when the user right clicks, I want a groupbox to show up where the mouse was right clicked. I am using the ChromeWebBrowser.Net project on SourceForge and when I add the following code:
Private Sub ChromeWebBrowser1_MouseUp(sender As Object, e As MouseEventArgs) Handles ChromeWebBrowser1.MouseUp
If e.Button = Windows.Forms.MouseButtons.Right Then
GroupBox1.Location = (e.Location)
GroupBox1.Visible = True
Else
End If
End Sub
It should be working, but when I test it and right click on the web browser control, it does not show up. When I add the same code to the main forms code, it works fine, it just is not working on the browsing control. No errors or anything, it will just not show up. Is there something special I need to do, or can there be a workaround to this?
Thanks so much!
Honestly, this sounds more like you should be using a ContextMenuStrip. You can drop one onto your form(then add items to it), and finally after that you can set the webbrowser's contextmenustrip property to be the one you just designed.

Custom hotkey even with unfocused form

I am having a bit problems trying this. I must admit that I am still novice programming. Well, I managed for do this in this way (VB.NET):
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If My.Computer.Keyboard.CtrlKeyDown Then
MORE IRRELEVANT CODE HERE
End If
End Sub
But with this way, even if it work, it dont let me customice the key shortcut (only Control, shift and others).
I did this too for try differents things:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = GlobalVariables.own_key Then
MORE IRRELEVANT CODE HERE
End If
End Sub
I give value to GlobalVariables.own_key from other button. This work perfectly, but only if program have the focus.
So... With the first code program work even if it haven't the focus but only with few keys... And with the second it let me use any key, but don't work if it haven't the focus.
I tryed understand the "keyboard hook" but I must admit that I didn't understad it and couldn't manage for work any of them.
Using VB.net 2012.
Really thanks so much for your help
It may not be an answer you like but it is the answer. In .NET, you cannot get notification of keys when your application does not have focus and you cannot get mouse events outside your applications windows. If you looked into the "Keyboard Hook", you should have read that little important fact regarding VB.
Global hooks are not supported in the .NET Framework

Make form always stick to desktop like Win 7 gadget (VB.net)

Ok, I'm aware there's a lots of topis about this, but I haven't found anything that works for me.
My program generates a small picture that i would like to keep in a WinForm that's always at the bottom, "with the desktop". Something like the gadgets in windows 7.
How do i tell my form to always stay here, and just can't be visible over any other form/window?
Should'nt this be doable like in the form_load function for this window?
Like this
Private Sub Sticky_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeepMeAtTheBottomUntillIAmClosed
End Sub
If you create a form that has no border and no controlbox, the user will not be able to resize or move it. Then add your own button to allow it to close, tell it where you want it to be and tada!
You can even add some mouse over functionality to make the tools appear when you are over the form.