Overview of problem
I am facing this issue when I try to hide some Labels, TextBoxes and a Button: all these Control flicker as they hide but other Control that are not involved are fine. I do not want this effect.
Also, this doesn't happen for Show(), only happens for Hide().
What I have tried:
Removing the background image resolved this problem but I do want my background image visible.
When I searched the Web, I learnt how to create this effect intentionally, however I could not find a solution to remove it.
Others stated that this is just a hardware limitation however I do have a capable CPU.
VB.NET Code:
Its just some <element>.Hide()s
Private Sub GetTaskNameButton_Click(sender As Object, e As EventArgs) Handles GetTaskNameButton.Click
GetTaskNameButton.Hide()
TaskInputTextBox.Hide()
TaskNameInputLabel.Hide()
TaskTimeLabel.Hide()
TaskHourLabel.Hide()
TaskHoursBox.Hide()
TaskMinutesLabel.Hide()
TaskMinsBox.Hide()
TasksCheckedListBox.Items.Add(TaskInputTextBox.Text + " >Time: " + TaskHoursBox.Text + "Hr " + TaskMinsBox.Text + "Min")
TaskInputTextBox.Text = ""
TaskHoursBox.Text = ""
TaskMinsBox.Text = ""
End Sub

Nothing to do with CPU limitations. This is related to the rendering of the Background of a Form and the content of its child Controls.
Read a description here: How to fix the flickering in User Controls.
(but
WS_EX_COMPOSITEDwon't help you here).Since you have some Controls that a combined functionality, you can build a UserControl to group the single Controls into a specialized entity that provide the functionality and contains all the logic required to perform this Task and notify when a choice has been made (all input values are validated and the submit Button is cliecked).
To handle the transparency of this UserControl, you have to tweak its standard behavior a little bit, since just setting
BackColor = Color.Transparentis not enough when you have a Form with a background Image: the Transparency would be simulated considering the Form'sBackgroundColor, not the content of the background Image (an Image is not a Color).You can make your UserControl actually transparent, preventing its background from being painted.
ControlStyles.OptimizedDoubleBuffertoFalse: this UserControl cannot useDoubleBufferingof course, otherwise we're back at square one (the Parent Control's background is used to build the BufferedGraphcs object)WS_EX_TRANSPARENTto the extended styles of the UserControl Window, so the System won't interfere, letting other windows behind the UserControl draw their content first (but we won't draw ours after).WS_CLIPCHILDRENStyle needs to be removed (since the base class,Control, adds it) otherwise the UserControls's child Controls may disappear when the Form is resized.When the
Add TaskButton is clicked, the UserControl can raise a public event, passing in a custom EventArgs object - after validation - the values entered.The Form can subscribe to this event and read the custom EventArgs Properties when the event is raised.
DoubleBuffered = True.This is how it looks like:
The Image shown here has a size of
3840x2560(it's freely downloadable from the Web).Try to resize the Form without double-buffering it :)
A PasteBin of the complete UserControl, in case it's needed: Transparent UserControl
Assuming the UserControl (
AddNewTask) added to a Form is namedAddNewTask1, you can add an event handler to itsAddTaskClickedevent, using the Designer or in code, in the Form Constructor:The
AddNewTaskUserControl: