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

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

Related

How to prevent scrollbar resetting to top of panel when a checkbox is pressed

I wanted to tick a checkbox that is on a panel but the scrollbar resets to the top of the panel (Image of this in attachments) so I have to scroll back to check it again for each checkbox. Ideally, it should just tick the box without moving the scrollbar back up. When looking this issue up, I came up on this post Don't autoscroll on button click and it said to make a custom class that inherits the panel class and override the panel class and use that. So I tried messing around with this (Image 2 and 3) but have had no success, would be really grateful if I could get some helpenter image description here
enter image description here
enter image description here

vb.net winforms datagridview how to tell where the user clicked in a cell

I am adding a custom column to a custom datagridview. One of the options this new datagridcolumn has is the ability show a value and then a button to allow the user to click on the button and something will happen. The button only takes up the right portion of the cell and the rest is a value. This button and value are displayable always and the button should always be able to be clicked on. In datagridview's display mode the value and button are painted. What I need help on is how to tell whether the user clicked on the button portion of the cell. Can someone please provide example code on how to do this?
Thanks,
Greg
Never mind I figured it out. I just put some logic in the cellclick event of the datagridview to get the GetCellDisplayRectangle and converted that to screen points and got where the mouse is on the screen and did a bounds test with the rectangle contains method.

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.

Update image on button 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.

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