Update image on button VB.net - vb.net

I’m trying to make a button that displays an image, that’s easy, but the image is an editable icon so I want the image on the button to be updated every time the form is started how can this be done?

I am making the assumption that you are using WinForms and saving your editied icon to a file.
Take a look at this MSDN page on ButtonBase.Image Property.
From above link:
button1.Image = Image.FromFile("C:\Graphics\MyBitmap.bmp")
You can put this in the New Subroutine after the InitializeComponent Statement. or in your Form Load event.

Use Graphics method and also handle the Paint event of Button. You can add text and primitive drawing on Image or Button region.

Related

VBA: Can't change Image Control picture after click on element

Setup
I have an Excel VBA UserForm with an Image Control element. When clicking on buttons in the form, the Image Control's Picture source is set / updated with the following code:
Set MyForm.imgControl.Picture = LoadPicture(pathToFile)
Problem
When the user clicks on the Image Control, updating its Picture source doesn't work anymore. The problem occurs, no matter when in the workflow the Image Control is clicked:
Example 1: User clicks a button to set the Picture (and pictures sets correctly). User clicks on Image Control. User clicks a different button to change the Picture -> displayed picture doesn't change.
Example 2: User clicks on Image Control right after Form load. User clicks on button to change the Picture -> displayed picture doesn't change.
If the user never clicks on the Image Control, everything works perfectly smoothly. It's worth noting that clicking on the Image Control doesn't visibly focus it.
Question
Clicking on the Image Control shouldn't make a difference in whether or not the Picture can be updated or not. How can this be done? Or, at least, does anyone know why the explained behavior is happening, or is it just a bug?
The Control does have Click / MouseDown / ... events (which are empty), but they don't take a Cancel parameter.
It does sound like a bug, as you say, but as a workaround, I'd suggest forcing a repaint after changing the picture:
Set MyForm.imgControl.Picture = LoadPicture(pathToFile)
MyForm.Repaint

Slow label and picturebox event firing which are child of Button

i have developed custom control which inherits Button control, actually i`m creating button with one picturebox and label on Button(picturebox and label are child controls). I created same method and wired child controls to behave as clicking on parent(Button), it works but its slow no mather what i do(tried with InvokeOnClick, me.performclick, Me.OnClick(New EventArgs()), tried with same method for all events), but clicking on label or picture box is slow, i need it to be fast as clicking directly on button cause in my application is very important to be able to click on button twice in second for example, if you click on label or picturebox twice at second it will fire just one time not 2.
What i have been thinking of is to make label and picturebox invisible for event is it possible or anyother idea ?
Thanks in forward
You are doing battle with ControlStyles.StandardDoubleClick. Which is turned on for the PictureBox and Label controls but turned off for Button.
So when you are clicking rapidly on either the picturebox or the label then they'll generate the DoubleClick event instead of the Click event. You'll interpret that as "slow" since you probably didn't write a handler for that event. Subscribing the event and calling Me.OnClick is a workaround.
Just don't do this. PictureBox and Label are point-and-click convenience controls but they are extraordinarily wasteful. It takes just two lines of code in the button's OnPaint() method override to get the exact same outcome, minus the overhead and the event problems. Use e.Graphics.DrawImage() to draw the pb's image and TextRenderer.DrawText() to draw the label's text.
Using MouseDown event ensures the event is triggered once per click, regardless of click/doubleclick.

Change the button hover color in VB.net

I'm creating a windows store app and i want to
change the button color when the mouse hover on the button
use an image as a button
I am using VS 2012 and using VB.net.
Thanks
You can create a mousehover event in your code behind and in that you can do whatever you want.
A perfect and precise answer of both of your questions is the following video
Click here

Visual Basic Background Image Flicker on PRESSING TAB

I am making an application using VB.NET 2010 and I have set a background image which flickers every time I open any new Form or hit tab for jumping from textbox to textbox
By pressing (tab) it only flickers once but always flicker when ever I close the form and open again.
I have tried everything; background image set to, STRETCHED, CENTRE, ZOOM but still it's the same.
Only thing is when I remove my background all is well, can you help me; what could be the reason of this?
Screenshot is attached please have look
You could try setting the form's DoubleBuffered property to True. However, by looking at your screenshot, it seems like you'd be better off just using a PictureBox control to contain the image.

Simulate Winforms Button Click Animation

I have a button and inside my button I have an image control. When the users click on the image I'd like to animate the button so it appears the button was pressed. I don't really care whether the actual button press event fires or not--it's the illusion of a button press I want to see.
Note: the only options I see on the web involve writing directly to the Windows API--a level of complexity and non-upgradability I really don't want to get into.
Why not just use two different images, one for a normal state, and another for when your button is being pressed.
If you want to go for more complicated route try using GDI+. Here is a quick sample tutorial on how to do this.
Why are you using an image control inside your button control instead of using the button control's Image property?
Using the Image property of the button will give you a button with an image that the user can press and that will raise the OnClick event without doing any extra work or re-implementing features that are already available.
I ended up making my picturbox look like a button by giving it a raised border style. Then on the mouseclick event I simulate the look of a button press by changing the border style for a few hundred miliseconds.
Private Sub simulateButtonPress(ByRef pictureBox As Infragistics.Win.UltraWinEditors.UltraPictureBox)
pictureBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Inset
Application.DoEvents()
System.Threading.Thread.Sleep(400)
pictureBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Raised
Application.DoEvents()
End Sub