VB.net prevent a tooltip from showing - vb.net

In my program i use tooltips to help new users have some idea of what the icon buttons do. I also have an option to turn tooltips off.
There appears to be a tooltip.hide method, but i don't quite understand how to use it.
So how do i get a tooltip to not display if a boolean value is set to false.

Using the Active property should meet your needs, it's more simple than using the Hide and Show methods.
'Hide ToolTip
ToolTip.Active = False
'Show ToolTip
ToolTip.Active = True

tooltip.Hide() is used to hide the ToolTip while is being shown.
If you want the tooltips now showing you can put a condition when calling to the point that shows them:
If Not chkBoxNoToolTips.Checked Then
tooltip1.Show()
End If
Or you can remove the tooltips from its controls if they are automatically set:
tooltip1.SetToolTip(label1, "")

Call SetToolTip and pass through your control and an empty string, you could probably pass through a null reference also but I haven't tried it myself.
This should remove the tooltip for you
ToolTip1.SetToolTip(txtBox1, "")
Hope it helps

Related

Conditional visibility on MS Access Form - how to write in VBA or Macro

I have some very (very) basic MS Access knowledge. I'm trying to expand a bit into either VBA or macros as I'd like to put in some conditional visibility for my form. Basically, I have a checkbox. If it's checked, I want three or four more fields to pop up. Someone was able to point me to a basic VBA formula of if (this checkbox) = true then, (fieldx).visible = true, else, (fieldx).visibility = false, end if.
But I'm so new to this that I need more help and explanation. I tried putting it in but couldn't get it to work (no error message, just nothing changed at all).
Specific questions:
-Does this formula seem right?
-If I want multiple fields to be visible, can I combine them into one formula or should I create a new "if" statement for all?
-Where do I enter this code? I'm running the Office 365 version. For all I know, I'm not even putting it in the right place.
-How do I determine the field names to replace the (this checkbox) and (fieldx) in the formula? I tried entering the name I title the fields as, but with the spaces in the name I got an error message, and without the spaces nothing happened. Is there a specific naming convention to turn the field names into formula-appropriate titles? Is the name listed somewhere?
-Once I get the formula entered, is there something I have to do to get it to run/take effect? I tried saving, closing and reopening with no changes.
-Is this the best way to go about this?
If there's anything else you think I should know, I would love to hear it - but please keep in mind I'm very new to this so if you could keep it at "dummy" or ELI5 levels of explanation, I'd appreciate it!
after creating a form with 4 textboxes and a checkbox put the form in design mode (lower right corner has design mode selected, select a textbox and hit property sheet on the ribbon (or f4).
On the property sheet note the visible property. set the visible property to false. Now the textbox will be invisible when the form starts.
Tip you can select all the textboxes at the same time and set their properties all at once.
Every control on the form and even the various parts of the form have properties you can set and play with. For instance you can give any name you want to any control. On the property sheet go to the other tab and set the name property.
Tip: choose a name you you will remember without having to look it up and describes the controls function.
Next select the checkbox (not the checkbox's label). On the property sheet go to the event tab and select the on click event. hit the ellipsis and choose code builder. Access is Event Driven. We want the textboxes to appear when the checkbox is selected so we put that code in the checkbox click event.
after choosing code builder we get the code window where we can browse among all the events for all our forms. for now all you should see is something like:
Private Sub mycheckbox_Click()
End Sub
So insert some code to handle the checkboxes like:
Private Sub mycheckbox_Click()
If mycheckbox = True Then
txtbox1.Visible = True
txtbox2.Visible = True
txtbox3.Visible = True
txtbox4.Visible = True
Else
txtbox1.Visible = False
txtbox2.Visible = False
txtbox3.Visible = False
txtbox4.Visible = False
End If
End Sub
now when the checkbox is not checked no textboxes are visible.
but when the checkbox is checked they appear

Word - how to uncheck checkboxes?

I have 4 checkboxes but we need to restrict selection to just a single one, meaning if you check the first, the other 3 will go unchecked. I know we could use ActiveX radio buttons but we'd prefer to avoid ActiveX if possible, plus with check boxes we have more control over the layout.
I've set the name of the checkbox appropriately to Check1:
And then I've put this very basic script into the Visual Basic section:
Private Sub Check1_Click()
Check1.Enabled = True
Check2.Enabled = False
Check3.Enabled = False
Check4.Enabled = False
End Sub
But unfortunately checking the first box doesn't uncheck the next 3.
Any ideas please? Thank you!
If these are Content Controls, as you indicate, then they do not have a CLICK event. Nor can they be identified by VBA by their Title property. The code you show us is for ActiveX controls, which you say you don't want to use...
Working with content control events is not as simple and intuitive as with ActiveX controls. Similar to form fields, Content Controls only have "editing" events that trigger on the user entering and exiting the content control. These events are available in the ThisDocument module, in the Document category.
The same ContentControlOnExit event triggers for ALL content controls in the document, so you need a Select Case or If conditional to query the ContentControl argument in order to know which content control was exited.
In order to address the other checkboxes you need to use the Document.SelectContentControlsByTitle (or ...ByTag) method which returns an array of all content controls with that title (or tag).
If you really want to emulate a "click" event then you need to insert a Custom XML Part in the document with nodes linked to the content controls. When the user changes the state of the control the ContentControlBeforeStoreUpdate event will trigger, letting you take action.
The property you need is Value, not Enabled.
The purpose of property Enabled is to prevent a control from being changed by user.
Additionaly, you need to prevent it from the events cascade. It means that when you change programatically the value of Check2, this will trigger Private Sub Check2_Click() and so on.
In order to make it work you should change your code like that:
Private Sub Check1_Click()
If Check1.Value Then
Check1.Value = True
Check2.Value = False
Check3.Value = False
Check4.Value = False
End If
End Sub
and similarly for the other check boxes.
For your purpose radio buttons will be better choice. Radio buttons have built-in functionality to uncheck currently selected button if other one is checked.

ListView Not Displaying Added Text

Background:
Hello everyone, I'm not new to visual basic or programming. I just find it the fastest to make a GUI in visual basic for various programs; however, I'm having a recent issue.
I have a form with a ListView control that I populate using a textbox and a button.
the code I use for the button is:
Code:
listview1.items.add(textbox2.text)
Pretty simple code that has always worked. I changed a few properties on my ListView as well, and I will list them. I just don't know what is going on.Here's a list of the properties changed (everything else is default):
Properties:
BackColor = DarkGray
BorderStyle = FixedSingle
HeaderStyle = None
MultiSelect = False
View = Details
All properties were changed via the properties tab and not through code. I want to be able to add text to the control. I'm not adding any subitems either. I'm just confused because this code has always worked, and I've never had this issue. I'm also using Visual Basic 2010 Express Edition if that helps.
If the added item in ListView is not displaying then check the ListView.View property. if this property has set to Detail view then Columns must be added in that listView control otherwise added item will not display.
Make sure item is added correctly.
Dim item As ListViewItem = listView1.Items.Add("Item Text") ' This text will be displayed in first column. The column index will be 0
' Further values will be added in SubItem
item.SubItems.Add("Sub Item1")
item.SubItems.Add("Sub Item2")
item.SubItems.Add("Sub Item3")

Run through all the controls in a form

I have a form and I am running through all the controls in that form.
My code is OK and is get all the controls with all their properties.
So for example I have a TabControl with 2 TabPages and 2 textboxes in each tabPage.
The problem is that for the tabPage that isn't selected , the textboxes' property visible is False, although I have set it to True.
I tried to solve this problem with Control.Select and Control.Focus , but Visible is still False:
Private Sub createXML(ByVal cnt As Control, ByVal elem As XElement)
Try
cnt.Select()
cnt.Focus()
Select Case cnt.Controls.Count
Case Is = 0
'Code here to write XElement to an XDocument
'Check Controls properties
Case Is > 0
For Each childCnt As Control In cnt.Controls
childCnt.Select()
childCnt.Focus()
Dim childElem As New XElement(childCnt.GetType.ToString)
Select Case childCnt.Controls.Count
Case Is = 0
'Code here to write XElement to an XDocument
'Check Controls properties
Case Is > 0
createXML(childCnt, childElem)
End Select
Next
End Select
Any ideas?
Note that I don't know what controls I have to run through each time
Your problem in this case is that a TabControl sets everything to invisble unless they are present in the currently selected tabpage. And when you change tab the controls are set to visible and previous ones dissapeares. So how does the tabcontrol keep track of a control that is manually set to visible false, so that it doesn't light up when the tab is changed? Well the visible property is not really based on a boolean value. It's merely an easy way to interpret it for us programmers. Either you see it or you don't, no rules to keep in mind or settings to mess up. Visible or not simple as that.
So what to do with your issue. Basically, my first thought when I see this is that you want to create a "open the program so it looks the same as when it was closed"-function. Which of course is not working properly at the moment since your parser probably set everything to visible=false, which at previously stated means not visible ever. Hence not showing after Tab control page change when loaded.
So solutions:
1. Add a tag to the controls in the tab control. This way you can look for the tag when saving. If it's there, set the visible property to true. (Easy to understand for you when maintaining in the future)
2. Use reflection to get the actual visible state. Look at SO thread and read about reflection: Using control.Visible returns False if it's on a tab page that is not selected (Not so easy to understand when maintaining in future)

Determine if an item is selected in a listview box

Using VB.net 2010 i am trying to figure out if an item was selected or not. Reason being is that if the user clicks on an item and pushes a button then everything works just fine. However, if the user selects an item and then clicks on a blank spot on the bottom of the listview and then clicks the button then it crashes.
My code is this:
If (lstMaster.SelectedItems(0).SubItems(1).Text) Is Nothing Then
MsgBox("test")
End If
Any help would be great! :o)
David
Ensure that something is selected first by checking that SelectedItems is not empty.
lstMaster.SelectedItems.Count > 0
check lstMaster.SelectedItems(0).Selected
Not sure if I've understood you correctly - Try using the ListView MouseMove event and check that lstMaster.SelectedItems.Count > 0 if you want to change the Enable property of a Button based on whether a row has been selected or not within your ListView control.
Use this checking with "If/EndIf" construction:
ListView1.Items(0).Selected = True