Datetimepicker displayed wrong after disable then enable - vb.net

I have a checkbox. On checkbox_CheckedChanged I set datetimepicker.Enabled like this:
Private Sub checkbox_CheckedChanged(sender As Object, e As EventArgs) Handles checkbox.CheckedChanged
If Me.checkbox.Checked Then
Me.txt1.Enabled = True
Me.dtp1.Enabled = True
Else
Me.txt1.Enabled = False
Me.dtp1.Enabled = False
End If
End Sub
At fisrt, dtp1 look like this:
When checkbox checked = False, dtp1 look like this:
When checkbox checked = True, dtp1 look like this:
And after enabled again, when tabstop on dtp1 is not hightlight anymore and the border color displayed wrong.
Can anyone explain that? I want the dtp1 look like at first when enabled again. Can any one tell me how to do that?

Related

Only the checkbox have Backcolor "RED" will be enabled true

I have a 3 checkboxes and my checkboxes is .enabled = False. I want when I click a button, only the checkboxes with a red BackColor will be set to enabled = True
How to do that?
You can do this with something like this :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each CB As CheckBox In Controls.OfType(Of CheckBox)
If CB.BackColor = Color.Red Then
CB.Enabled = True
End If
Next
End Sub
This will loop through all the controls in the form and if the control is of type CheckBox then it will check its BackColor property and then change to fit your needs, hope you understood the code, because Stackoverflow is not about giving out ready/full codes, if you didn't understand anything in the code, please feel free to ask about it.
Hope that helped :)

VB 2010 .NET ComboBox How To Controll Object Whit This?

I want to ask how to control objects with a combobox in VB.
So I have a combobox with two choices On and Off.
How can I enable and disable a textbox with an combobox?
you can try something like this
private Sub OrainsComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles OrainsComboBox3.SelectedIndexChanged
If OrainsComboBox3.SelectedText = "On" Then
OrainsTextBox7.Enabled = True
OrainsTextBox8.Enabled = True
End If
If OrainsComboBox3.SelectedText = "Off" Then
OrainsTextBox7.Enabled = False
OrainsTextBox8.Enabled = False
End If
End Sub

Checkbox does does not work in VB.Net form

I have two checkboxes for two groupboxes to enable visibility or invisibility of each one at a time but somehow one is working(chboNew) the other one(chboIssue) doesn't!
here is the code I have written for it, any help would be appreciated:
Private Sub chboIssue_CheckStateChanged(sender As Object, e As EventArgs) Handles chboIssue.CheckStateChanged
If chboIssue.Checked = True Then
gbIssueSearch.Visible = True
gbNewSearch.Visible = False
chboNew.Checked = False
ElseIf chboIssue.Checked = False Then
gbIssueSearch.Visible = False
End If
End Sub
Private Sub chboNew_CheckStateChanged(sender As Object, e As EventArgs) Handles chboNew.CheckStateChanged
If chboNew.Checked = True Then
gbNewSearch.Visible = True
gbIssueSearch.Visible = False
chboIssue.Checked = False
ElseIf chboIssue.Checked = False Then
gbNewSearch.Visible = False
End If
End Sub
If user has to choose between new issue and issue search,one at a time.
Then you should use radio buttons, instead of checkbox.
Checkbox gives idea that user can choose both checkboxes at same time.
Which in your case is not true.
Changing the name of the checkboxes is not going to solve your issue. I noticed that for your chboNew.CheckStateChanged event handler in your elseif clause you are checking if chboIssue is checked, whereas in your other handler for chboIssue both your if/else clauses look at chboIssue. I'm thinking that may be part of your issue. Also, if only one of these boxes is supposed to be checked at a time, you may want to add logic to automatically uncheck the other whenever one is checked. For instance, in your chboNew handler, "If chboNew.Checked = True Then chboIssue = False", and the inverse in your chboIssue handler. Hope this helps.

Switch enabled-property of lable with doubleClick-event

I have a lable and I want it to switch its enabled-property when doubleclicking on it. The code I wrote only works in one direction: if the label is enabled I can set enabled=false by doubleclicking, but if the label is not enabled I can't set enabled=true by doubleclicking. Here is my code:
Private Sub Label1_DoubleClick_1(sender As Object, e As EventArgs) Handles Label1.DoubleClick
If Me.Label1.Enabled = True Then
Me.Label1.Enabled = False
Else
Me.Label1.Enabled = True
End If
End Sub
How can I solve this problem? Thank you in advance!
The nature of the Enabled property is to prevent user interaction with a control. You can emulate the behavior you're looking for in a couple of ways:
Instead of disabling the control, manually change its appearance
If (Label1.ForeColor = Color.Black) Then
'"disable" control
Label1.ForeColor = Color.Gray
Else
'"enable" control
Label1.ForeColor = Color.Black
End If
Overlay the label with a transparent panel. Receive the DoubleClick event on the panel, but enable/disable the label below.

show/hide another combobox, with the help of combobox items

I have a little problem that i'm creating a simple search application which have a TEXT box and some combo boxes and radio buttons and a search button.
radio button names "Videos", "Audios", "Pics" etc..
when radiobutton of video is selected, a combobox is appear having options "YouTube", "Metacafe" etc
I want that when i click "Metecafe" item in combobox of video, an other combo box appear having items Like "Entertainment", "How To", "+18" etc(categories of video search).
so "HOW TO SHOW/HIDE AN OTHER COBOBOX WITH THE HELP OF A COMBOBOX ITEM"
hope you have understood my problem.
screen shoot
i don't know it is possible or not becux i'm beginner in VB
my English is not so good so please see below code:)
if combobox1.SelectedItem = "PAKISTAN" Then
combobox2.Visible = True
End if
if combobox1.SelectedItem = "INDIA" Then
combobox3.visible = true
combobox2.visible = false
End if
Obviously this code is wrong, this is a example that what i want to do
Thanks to all in advance..
NOTE:
i have try this codes but its not working..
if ComboBox1.Items(ComboBox1.SelectedIndex).ToString() = "PAKISTAN" Then
ComboBox2.Visible = True
End if
sorry for spell and grammatical mistakes:(
Try using the SelectedItem Property like this
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem.ToString = "PAKISTAN" Then
ComboBox2.Visible = True
End If
End Sub
Since you are wanting to check for multiple country's you can use a Select Case Statement like this
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.SelectedItem.ToString
Case "PAKISTAN"
ComboBox2.Visible = True
ComboBox3.Visible = False
Case "INDIA"
ComboBox3.Visible = True
ComboBox2.Visible = False
Case Else
ComboBox2.Visible = False
ComboBox3.Visible = False
End Select
End Sub
Two things are important here:
(a) Which event you're using to /detect/ that the combobox has changed, and
(b) The code you're using to detect what is selected.
I haven't tested this, and I'm coming from a C# / VB6 background, so bear with me if this isn't 100% correct, but I believe using the following should work:
Inside the SelectedIndexChanged event of ComboBox1, insert your code above, EXCEPT.. Change instances like
combobox1.SelectedItem = "PAKISTAN"
to
ComboBox1.Text = "PAKISTAN"
The SelectedItem property outputs the selected item object itself, which is a variable type that can't be displayed.. not the /text/ of the currently selected item. There are other ways to access the text associated to that item, but ComboBox1.Text is the easiest. ComboBox1.SelectedItem.ToString() would work also.
If ComboBox1.Items(ComboBox1.SelectedIndex).ToString() = "PAKISTAN" Then
ComboBox2.Visible = True
End If
Btw is this a web client or window client?
Assuming if you are implementing a web client app and the conditional logic are simple, you may need to trigger a page reload which can be achieve in your markup by specifying an event and set the property for reload to enable. My initial on this from reading your post is that your GUI might not be refreshing or reloading unless it's your intension to not reload the page or refresh the GUI then this should be handle with javascript instead.
I hope I'm interpreting the issue correctly and hopefully this will give you some idea on how to tackle the issue.