Is it possible to use ToolStrip Controller as TabMenu in VB.net? - vb.net

i am new at VB.net.. i am making one Application for my friend. but i have one problem while using toolstrip...
i want to use toolstrip menu as tabmenu... like if i select any button from toolstrip menu, than form content change..just like while we change tab then form content will change which is inside that tab...is it possible to do so?
I don't have any code at the moment so i can not attach it..i have tried googling my problem but i didn't found any solution of this problem...hope you guys understand my problem..thank you!

If I understand you correctly, for each "tab" you could create a panel on your form and set the Visible property of each to False. Then for each button click event in your ToolStrip, you could make them all Visible=False apart from the one you want to show.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = False
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Panel1.Visible = True
Panel2.Visible = False
Panel3.Visible = False
End Sub
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
Panel1.Visible = False
Panel2.Visible = True
Panel3.Visible = False
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = True
End Sub
End Class

Related

Autoscroll inconsistent

Im having a hardtime figuring What went wrong ,My program Has 3 buttons (Bread,Coffe,Pasta) and a panel, each buttons show a different form,
I currently set the Panel's autoscroll to true
MenuPanel.AutoScroll = True
The Coffee,bread and pasta button function is
Private Sub btnCoffee_Click(sender As Object, e As EventArgs) Handles btnCoffee.Click
MenuPanel.Controls.Clear()
CoffeeForm.TopLevel = False
CoffeeForm.WindowState = FormWindowState.Maximized
CoffeeForm.Visible = True
MenuPanel.Controls.Add(CoffeeForm)
CoffeeForm.Show()
End Sub
Private Sub btnBread_Click(sender As Object, e As EventArgs) Handles btnBread.Click
MenuPanel.Controls.Clear()
BreadForm.TopLevel = False
BreadForm.WindowState = FormWindowState.Maximized
BreadForm.Visible = True
MenuPanel.Controls.Add(BreadForm)
BreadForm.Show()
End Sub
Private Sub btnPasta_Click(sender As Object, e As EventArgs) Handles btnPasta.Click
MenuPanel.Controls.Clear()
PastaForm.TopLevel = False
PastaForm.WindowState = FormWindowState.Maximized
PastaForm.Visible = True
MenuPanel.Controls.Add(PastaForm)
PastaForm.Show()
End Sub
The autoscroll works for the first time and after Some clicks on the The buttons (Maybe 4-5 clicks and scrolled with Mousewheel)
the Vertical Scrollbar disappear from the panel
what went wrong?
I am currently using vb.net 2019
1:

How to uncheck other checkboxes by checking a checkbox?

When I press the chkCP1, it unchecks chkYP but chkCP doesn't display its checked state2; I need to double click chkCP before it displays its checked state3.
I used these codes:
Private Sub chkCP_CheckedChanged(sender As Object, e As EventArgs) Handles chkCP.CheckedChanged
chkYP.Checked = False
End Sub
Private Sub chkYP_CheckedChanged(sender As Object, e As EventArgs) Handles chkYP.CheckedChanged
chkCP.Checked = False
End Sub
Figure 1:
Figure 2:
Figure 3:
I would personally use radiobuttons for this as this is what they were intended to do. However, I have seen a time where the option was to select neither option like you can easily do with checkboxes. That being said, You should be able to achieve the desired result by just simply moving your original code into the click event of the checkboxes instead of the checkchanged event. The reason is that when you click one, it triggers the checkchanged event which sets it to false which in turn triggers that controls checkchanged event. Try replacing your original code with
Private Sub chkCP_Click(sender As Object, e As EventArgs) Handles chkCP.Click
chkYP.Checked = False
End Sub
Private Sub chkYP_Click(sender As Object, e As EventArgs) Handles chkYP.Click
chkCP.Checked = False
End Sub
edit:
I tried using if statements and it worked! However, I cannot uncheck the checkbox anymore.
Private Sub chkCP_CheckedChanged(sender As Object, e As EventArgs) Handles chkCP.CheckedChanged
If chkYP.Checked = True Then
chkYP.Checked = False
Else
chkCP.Checked = True
End If
End Sub
Private Sub chkYP_CheckedChanged(sender As Object, e As EventArgs) Handles chkYP.CheckedChanged
If chkCP.Checked = True Then
chkCP.Checked = False
Else
chkYP.Checked = True
End If
End Sub
You might have some issues with recursive event handlers here. If you set chkYP.Checked in chkCP_CheckedChanged, chkYP_CheckedChanged will be triggered. This sets chkCP.Checked, which triggers chkCP_CheckedChanged again.
You might try something like this:
Private _checking As Boolean
Private Sub chkCP_CheckedChanged(sender As Object, e As EventArgs) Handles chkCP.CheckedChanged
If Not _checking Then
_checking = True
chkYP.Checked = False
_checking = False
End If
End Sub
Private Sub chkYP_CheckedChanged(sender As Object, e As EventArgs) Handles chkYP.CheckedChanged
If Not _checking Then
_checking = True
chkCP.Checked = False
_checking = False
End If
End Sub
It may not win a beauty contest, but it might just do the job.
Using Radio Buttons might be a better solution if you want only one of N options selected.
Edit:
Charles May's answer is way more elegant. He handles the Click event instead of the CheckedChanged event. And that also seems to work fine when using the keyboard (pressing the spacebar to toggle the checkbox).

Tray application not displaying properly

Below I have the code for a framework I am working with. The problem I am having is that the Icon will not show up in the system tray unless the commented code is included. The weirdest part is that the other lines of code for the notifyicon1 properties will then work. Can someone please help me understand what is going on?
Public Class Main
Public WithEvents notifyicon1 As New NotifyIcon
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Width = 1200
Height = 850
ShowIcon = True
Me.Text = "V1.0.0.0"
' icon
Icon = My.Resources.icon_4
'set the form properties
BackColor = Color.White
Dim start As New startup()
End Sub
Private Sub Main_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
notifyicon1.Visible = True
Me.Hide()
Icon = My.Resources.icon_4
notifyicon1.Visible = True
notifyicon1.BalloonTipText = "Hi from right system tray"
notifyicon1.ShowBalloonTip(500)
'With notifyicon1
' .Icon = My.Resources.icon_4
' .Visible = True
' .ShowBalloonTip(500)
'End With
End If
End Sub
Private Sub NotifyIcon1_DoubleClick(sender As Object, e As MouseEventArgs) Handles notifyicon1.DoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
notifyicon1.Visible = False
End Sub
End Class
As Hans pointed out, you need to set the notifyicon1's Icon property, which you do in the With statement, but not in the code above.
Change the Icon = My.Resources.icon_4 with notifyicon1.Icon = My.Resources.icon_4, as you don't seem to be using the Icon property anywhere.

vb.net radiobutton progromatically setting 'Checked' and not cause 'Click' event

I am loading a form with values from stored settings from the registry
Typically :
If sFormat = TG_ReportFormatDft Then
RadioButton1.Checked = True
........
Else
RadioButton2.Checked = True
..........
End If
TG_ReportFormatDft is a string constant and is of no significance. The radio buttons are grouped correctly and manually clicked behave correctly.
Later in the procedure I check if there has been a manual change :
'Follow what the user is doing
Private Sub RadioButton1_Click(sender As Object, e As EventArgs) Handles RadioButton1.Click
msReports_Format2 = TG_ReportFormatDft
DoButtons(True)
End Sub
Private Sub RadioButton2_Click(sender As Object, e As EventArgs) Handles RadioButton2.Click
msReports_Format2 = TG_ReportFormatAlt
DoButtons(True)
End Sub
Imagine my surprise when these downstream subroutines are triggered without a mouse click. It would appear that :
RadioButton1.Checked = True --- triggers the mouse click event.
I can understand an 'On Change' event but the mouse click has not happened.
How can I prevent this 'click' event from propagating ?
Declare a class level boolean variable "ClickedFromCode". Now when you are setting the values from code set the boolean to true. See below sample code.
Private ClickedFromCode As Boolean
Private Sub Intialize
ClickedFromCode = True
If sFormat = TG_ReportFormatDft Then
RadioButton1.Checked = True
Else
RadioButton2.Checked = True
End If
ClickedFromCode = False
End Sub
Private Sub RadioButton1_Click(sender As Object, e As EventArgs) Handles RadioButton1.Click
If ClickedFromCode Then
Return
End If
msReports_Format2 = TG_ReportFormatDft
DoButtons(True)
End Sub
Private Sub RadioButton2_Click(sender As Object, e As EventArgs) Handles RadioButton2.Click
If ClickedFromCode Then
Return
End If
msReports_Format2 = TG_ReportFormatAlt
DoButtons(True)
End Sub

Enable and disable TextBox with a checkbox in visual basic

I've 6 TextBox and 6 CheckBox. Now I want to disable the TextBox1 with a CheckBox1 and reactivate it with the Same CheckBox.
How a can do it?
Edit1 15.55 14/02/2013
I have done so to solve my problem!
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = False
ElseIf CheckBox1.Checked = False Then
TextBox1.Enabled = True
End If
End Sub `
This will work, just add more for the other check boxes
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
What this does: if checkbox1 is check, the checked_changed event fires and the code inside is ran. The if statement looks to see if the checkbox is checked or not. If it is checked, then it sets the textbox1 to enabled, if not it sets it to disabled. Be sure to set the enabled property to either enabled or disabled when you create your program. If you want it to be enabled from the start, that is the default....otherwise set it to disabled in its properties view.
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
TextBox1.Enabled = CheckBox1.Checked
End Sub
Take a look at this tutorial below. After, look at the checkbox control's events and choose the most fitting one. The property you will be changing on the textbox is Enabled.
http://www.youtube.com/watch?v=4PbUryXqZ50
This works if you have a layer built in that you can send objects behind (therefore hide things). I use this as a way to make text boxes and other items appear and disappear depending on other selections.
Private Sub checkbox_Click()
If (checkbox = True) Then
ActiveSheet.Shapes("textbox").ZOrder msoSendToFront
ActiveSheet.Shapes("textbox").ZOrder msoSendToFront
Else
ActiveSheet.Shapes("textbox").ZOrder msoSendToBack
ActiveSheet.Shapes("textbox").ZOrder msoSendToBack
End If
End Sub
This worked for me:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Enabled = False
If Not TextBox1.Enabled Then
TextBox1.BackColor = Color.White
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
End Class