Choosing between two sets of tootips - vb.net

Working with the vbnet form editor, I have instancied 2 times the tooltip class: one for English Langage, one for French langage. (you can also imagine: short version /extended version)
How to choose dynamically between the to instancies at runtime?

I found this way to handle the topic:
Private Sub Tip_En_CheckedChanged(sender As Object, e As EventArgs) Handles Tip_En.CheckedChanged
If Tip_En.Enabled Then
Me.ToolTip_Fr.Active = False
Me.ToolTip_en.Active = True
End If
ToolTip_en.IsBalloon = True
End Sub
Private Sub Tip_Fr_CheckedChanged(sender As Object, e As EventArgs) Handles Tip_Fr.CheckedChanged
If Tip_Fr.Enabled Then
Me.ToolTip_en.Active = False
Me.ToolTip_Fr.Active = True
End If
End Sub
Could surely be shortened and factorized...

You can use 1 instance, only changing the text displayed at runtime.
You can use an extra class like ToolTipTranslationTexts that holds all the text translations after setting a language this class knows what language you have set.
Put a method like PopulateToolTipText into it, from which you change all tooltip texts to the right language.
This is one approach I could think off, but there are many more.
That way you can also add more languages only by adding text to this class.

Related

Perform Load upon after click button

I am trying to use the panel and buttons to load 2 different forms along with entity framework and ado model stuff. I am trying to load the 2nd form this picture, using the codes running on the first form since they have the same table. but what happen is whenever I close the 2nd form and try to switch on the second user from this form(driverlist), I am still getting the results that I created before on the first user, I kinda think that the 2nd form is not being loaded although I put some code:
Private Sub DriverLicense_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim user_id As Integer = Driverlist.tbxUser_id.Text
Driverlist.db = New [Emme_Subic_Transport_Corporation_Payroll].EmmeSubicEntities
Driverlist.db.UserDetails.Where(Function(c) c.isDeleted <> 1 And c.Id = user_id).Load()
UserDetailBindingSource.DataSource = Driverlist.db.UserDetails.Local
If Driverlist.tbxUser_id.Text.Count < 1 Then
MessageBox.Show("Please Select an Employee ID First", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Drivertest.Panelswitch(Driverlist)
Else
Me.Show()
End If
End Sub
Private Sub DriverLicense_Activated(sender As Object, e As EventArgs) Handles Me.Activated
Dim user_id As Integer = Driverlist.tbxUser_id.Text
Driverlist.db = New [Emme_Subic_Transport_Corporation_Payroll].EmmeSubicEntities
Driverlist.db.UserDetails.Where(Function(c) c.isDeleted <> 1 And c.Id = user_id).Load()
UserDetailBindingSource.DataSource = Driverlist.db.UserDetails.Local
End Sub
I binded the 2nd form through other resources of data binding from the properties but still on the same resources as the first form. Im pretty new to this so please stop putting negatives on my questions. If you think I am bad at this, I know and I am sorry. by the way this is the code from the buttons and panel if that helps. Thanks everyone.
Sub Panelswitch(Panel As Form)
PanelControl.Controls.Clear()
Panel.TopLevel = False
PanelControl.Controls.Add(Panel)
Panel.Show()
End Sub
Private Sub Btntest_Click(sender As Object, e As EventArgs) Handles Btntest.Click
Panelswitch(Driverlist)
End Sub
Private Sub Btntest2_Click(sender As Object, e As EventArgs) Handles btntest2.Click
Panelswitch(DriverLicense)
End Sub
There are number of things I would avoid, just looking at your pictures, but that goes beyond your question.
Secondly, agreed with the comment, you should revise your question further (I see you tried, but still, it's neither complete or clear).
If I understand correctly, you have container PanelControl, which you fill either with a form DriverList or DriverLicence. I just want to make sure - are you sure you have your instances corectly set? Because I would expect that the switch would act only for displaying correct form, but should behave differently for the [persistent] list DriverList and DriverLicence, which should be probably a new instance every time you want to add a licence. But this code is not shown, just guessing the problem might be along those lines. There are quite few design possibilities, I guess.
Simplified, the point is:
Private Sub Btntest2_Click(sender As Object, e As EventArgs) Handles btntest2.Click
Dim DriverLicenceInstance as new DriverLicence
Panelswitch(DriverLicenseInstance)
End Sub
I also think, that you might have your binding set incorrectly for the 2nd form, the DriverLicence. I'm not proficient in .NET binding, but it seems to me that you declare the bindings as two separate things (comes from the copying the code?). But what you probably need to do is to use the same binding source for both parts. See here: A-Detailed-Data-Binding-Tutorial.

How can i build an expandable and collapsible panel in VB.net?

I am looking for a way to make a panel which can be expanded and collapsed with a little arrow or button. I tried to find some examples, nothing worked so far. I tried to resize a group to 0px but the problem was when i did that the panel below it stayed in a same place, and I wanted it to slide upside, to save screen real estate.
I have a bunch of labels and text boxes which provides me data, but takes up a lot of space, and i grouped them together.
All help would be appreciated.
David
Simple in window Form
Insert a button and write code
Simple Example:
Public Class Form1
Dim panelshow As Boolean = False
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If panelshow = False Then
panelshow = True
Panel1.Show()
Else
Panel1.Hide()
panelshow = False
End If
End Sub
End Class
You can change name of variables, buttons and panels.
Set the panelshow to false if on application start your panel is collapsed otherwise to true if your panel is visible on startup and want to hide later by user.
Most people have answered the question about the collapse and expand, but to answer your question about "animation" so that it really has a good slide feel. For winforms i recommend this library on github DotNet Transitions
you can then write very simple code to give it animated transition.
using the transitions library, this code would collapse the panel in half a second:
Transitions.Transition.run(pnl, "Height",
initialValue:=pnl.Height,
destinationValue:=0,
transitionMethod:=New TransitionType_EaseInEaseOut(500)
)
If you want to use animation in win forms like when panel collapsed and the additional space should be covered with content then you can use
Control.Top() And Control.Left() Property ' control = your control name on which content is written like label, textbox etc.
Or second choice
To resize your content (like increasing the size etc).
Depend on your choice as I can't see your form presentation but advise you on the base of my imagination.
For example my panel height is 100 and when i collapsed I want my next control should move upward by 100 (Just suppose)
Suppose, my next control is RichTextBox
Then, you can do change here :
Public Class Form1
Dim panelshow As Boolean = True
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If panelshow = False Then
panelshow = True
Panel1.Show()
RichTextBox1.Top = RichTextBox1.Top + 100
RichTextBox1.Height = RichTextBox1.Height - 100
Else
Panel1.Hide()
panelshow = False
RichTextBox1.Top = RichTextBox1.Top - 100
RichTextBox1.Height = RichTextBox1.Height + 100
End If
End Sub
End Class
Just add a method in addition to our previous code to do this thing.
Don't mind my grammar mistakes.
I am not perfect in English.
For more help comment or post your code (if you have any kind of problem)

How to make this more efficient?

Private Sub btnOne_Click(sender As Object, e As EventArgs) Handles btnOne.Click
txtAnswer.AppendText(1)
End Sub
So this is my code (It's for 0 through to 9 and a dot for decimal points).
I'm working on calculator for an assignment, my question is, can I make this more efficient so I don't have a lot code doing the same thing?
I had considered setting up a function to read the contents of the buttons and add them to the textbox, but then the operation buttons and clear buttons would just add to the textbox instead of performing the code assigned to them.
you can create one method for the numeric buttons and add their value to the Tag Object. Then you can just reference the tag object to append to the text
Private Sub NumericButtons_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim btn As Button
btn = sender
txtAnswer.AppendText(btn.Tag)
End Sub
You could create a function just like that, but it should read the number from the sender's Text property, and only assign the number buttons to that function in the OnClick event.
The other buttons will have their own OnClick methods, and you should make a generic function like in this case when you find a common behavior in some of them. Perhaps you could do another generic function for all + - / x operators, it that's appropriate.

How to disable/enable combo box using a checkbox in VB.NET?

I have a dropdown combo box containing a few options for the user. I also have a checkbox that allows the user to use a default value (also in the dropdown combo box). When the user checks the check box, I want to have the combo box become disabled.
My code should work in theory, but it doesn't.
Private Sub chkboxUseDefault_Click(sender As Object, e As System.EventArgs) Handles chkboxUseDefault.Click
If chkboxUseDefault.CheckState.Equals(1) Then
cmbSelectOptions.Enabled = False
Else
cmbSelectOptions.Enabled = True
End If
Can someone point out what my (potentially obvious) error is?
You're problem is with: If chkboxUseDefault.CheckState.Equals(1) Then
You're code will have the desired outcome if you change that line to:
If chkboxUseDefault.CheckState = CheckState.Checked Then
Or perhaps even more succinctly:
If chkboxUseDefault.Checked Then
Although, I am inclined to also agree with OneFineDay in that I find the chkboxUseDefault.CheckedChanged a more appropriate event for this endeavor, and his proposed code is more readable IMO, I felt you might like to know how to make as small a change as possible and achieve the desired result.
Lets simplify the check:
Private Sub chkboxUseDefault_CheckedChanged(sender As Object, e As System.EventArgs) Handles chkboxUseDefault.CheckedChanged
cmbSelectOptions.Enabled = Not chkboxUseDefault.Checked
End Sub
Private Sub chkboxUseDefault_CheckedChanged(sender As Object, e As EventArgs) Handles chkboxUseDefault.CheckedChanged
If chkboxUseDefault.Checked = True Then
cmbSelectOptions.Enabled = False
Else
cmbSelectOptions.Enabled = True
End If
End Sub
This enables and disables your combobox.

Why does my image not show properly after clicking? VB.NET

I'm having this code:
Private Sub FormatMouseOver_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormatMouseOver.MouseClick
FormatClicked.Enabled = True
FormatClicked.Visible = True
BigLettersNoClicked.Enabled = True
BigLettersNoClicked.Visible = True
FormatMouseOver.Visible = False
FormatMouseOver.Enabled = False
End Sub
all the variables are images stored in pictureBoxes. The first one mentioned (FormatClicked) does show and enables itself properly, however the secound one (BigLettersNoClicked) doesn't do anything. The two pictureBoxes overlap, the BigLettersNoClicked is exactly one layer above FormatClicked. I tried putting it on any other place in the project and it still doesn't work.
Just to clarify: FormatMouseOver disabling works fine, and there are no errors during debuging
Subsequent question: since i'm new to the vb.net, can anyone explain to me, what is the difference between MouseClick and Click events?
Thanks
As always, MSDN provides a good summary about that topic:
Maybe this helps you: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.click%28v=vs.110%29.aspx