I'm coding in Visual Basic. I have a file in Access that I am using as my Data Source. I have the form I am creating that is completely Read Only, so the user will not be able to edit any of the information.
My question is, I have created a button also on the form that I would like to put the form into edit mode when the user clicks the button, so the user will be able to make changes.
How would i go about doing that?
I'm not sure if this level of simplicity is what you're looking for or not...
Private Sub Form1_Load(sender As System.Object, e As EventArgs) Handles Me.Load
GroupBox1.Enable = False
End Sub
Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
GroupBox1.Enable = True
End Sub
I highly recommend you read this thought for the future:
https://stackoverflow.com/help/how-to-ask
I'd also recommend watching tutorial videos and reading MSDN documentation on VB.NET.
Related
Winforms App - VB.Net 4.6.1
I have a data table that I fill when my form loads as follows:
Private Sub OnFormLoad(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ApGetMratesListTableAdapter.Fill(Me.DsMRatesList.apGetMratesList)
End Sub
On the form I have textbox bound (Me.ApGetMratesListBindingSource) to a field in this datatable . I want to catch some sort of "RowChanged" event when the value in the textbox changes so I can set a "dirty" flag. Unfortunately after an hour of Googling and reading page after page with no examples of how to write the method I'm asking for help. Basically I cannot figure out how to refer to the event i.e. the part after HANDLES.
Private Sub SetDirty(ByVal sender As System.Object,
ByVal e As DataRowChangeEventArgs) Handles ?
m_IsDirty = True
End Sub
I've experimented until I ran out of options. If anyone can clue me as to how to write the event for the above Sub I'd be very grateful. If the signature isn't correct please clue me on that as well. Thank you!
I am currently working on a project and decided to create a user interface for it using visual studio with a windows forms application(Visual Basic).
The problem I'm facing is that the user interface doesn't respond as quickly and smoothly as I'd like it to.
Mainly, I am using pictures as buttons to make the user form look more modern.
However, when I hover my mouse over a "button" it takes a while until the "highlighted button" appears.
P1 is the picture of the "normal button" and P2 is the picture of the "highlighted button".
Here is the short code I have for now:
Public Class Main
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles P1.MouseHover
P1.Visible = False
P2.Visible = True
End Sub
Private Sub P2_MouseClick(sender As Object, e As MouseEventArgs) Handles P2.MouseClick
'Call cmdInit()
'Call cmdConnectRobot()
'Call cmdUnlock()
End Sub
Private Sub Main_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
If P2.Visible = True Then
P2.Visible = False
P1.Visible = True
End If
End Sub
Private Sub P4_Click(sender As Object, e As EventArgs) Handles P4.Click
End Sub
End Class
Another problem I'm facing is that when I call other subs, the user form becomes unresponsive while the sub is running.
I researched and found that I could implement multi threading or async tasks but I'm a bit lost and would be extremely grateful if someone could guide me or point me in the right direction.
Thanks in advance!!
In this case your UI is responsive, however the MouseHover event is only raised once the mouse cursor has hovered over the control for a certain amount of time (default is 400 ms), which is what is causing the delay.
What you are looking for is the MouseEnter event, which is raised as soon as the cursor enters ("touches") the control:
Private Sub P1_MouseEnter(sender As Object, e As EventArgs) Handles P1.MouseEnter
P1.Visible = False
P2.Visible = True
End Sub
You can then use that together with the MouseLeave event on the second picture box to switch back to the non-highlighted image:
Private Sub P2_MouseLeave(sender As Object, e As EventArgs) Handles P2.MouseLeave
P1.Visible = True
P2.Visible = False
End Sub
However switching picture boxes like this is not optimal. I recommend you to look into how you can use Application Resources, then modify your code to only switch the image that one picture box displays.
Here are the basic steps:
Right-click your project in the Solution Explorer and press Properties.
Select the Resources tab.
To add an image either:
a. Drag and drop the image onto the resource pane.
b. Click the arrow next to the Add Resource... button and press Add Existing File....
Now, in your code add this right below Public Class Form1:
Dim ButtonNormal As Image = My.Resources.<first image name>
Dim ButtonHighlighted As Image = My.Resources.<second image name>
Replace <first image name> and <second image name> with the names of your button images.
Now you only need one picture box for the button:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
P1.Image = ButtonNormal
End Sub
Private Sub P1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles P1.MouseEnter
P1.Image = ButtonHighlighted
End Sub
Private Sub P1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles P1.MouseLeave
P1.Image = ButtonNormal
End Sub
I'll start by saying i'm not a programmer by trade, and i'm sure someone will point out better ways of doing these things, but in regards to the threading question it's fairly simple to implement.
Imports System.Threading
Public Class Form1
Dim WorkerThread As New Thread(AddressOf DoWork)
'WorkerThread' can be any name you like, and 'DoWork' is the name of the sub you want to run in the new thread, and is launched by calling:
WorkerThread.start()
However there is a catch, the new thread is not able to interact directly with the GUI, so you cannot change textbox text etc... I find the easiest way to get changes made to the GUI is to drag a timer onto your form, and have the new thread change variables (pre-defined just below Public Class Form1), then use the Timer1 Tick event to monitor the variables and update the GUI if there are any changes.
I have been struggling to figure out on how to fill in the email and password on the page and click a button to log into Microsoft, but I cant figure it out. I am very new to VB.net and would like some help to get better at and to learn. so far I have:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("https://login.live.com/")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim elements = WebBrowser1.Document.GetElementsByTagName("input")
For Each element As HtmlElement In elements
If element.GetAttribute("type") = "submit" Then
element.InvokeMember("click")
Exit For
End If
Next
End Sub
I have tried to use the GetElementById("").SetAttribute("value", TextBox1.Text), but I'm having a hard time finding it. Could some one please point me in the right direction or show me some code on how to do this. Thanks so much!!!
If you want to type your username and password automatically, then you may have to take a look on AutoIt. It is a scripting anguage. You can easily do this with built-in functions. There is a COM version for AutoIt. So you can add reference to your vb.net project and import it to your class. And you can easily call almost all useful function from there. Give try. Here is the link
https://www.autoitscript.com/site/
how can i make my application goes to function after certain usage
like if i click an button 10 times, then button is disabled
just like trial program,
so far, i can do that on run-time only,
how can i make it count clicks without using Registry?
my program is very simple: convert strings to Base64
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = Convert.ToBase64String(New System.Text.ASCIIEncoding().GetBytes(TextBox1.Text))
End Sub
You probably need Settings. Easily Save and Retrieve Application and User Settings in VB.NET or C# Apps. First create ClickCouter of type integer with value 0 in settings (see the article).
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.ClickCouter +=1
My.Settings.Save()
If My.Settings.ClickCouter>=10 then Button1.Enabled = False
End Sub
It is necessary to check ClickCouter also in Form_Load. The value is stored in a file in a user profile so the solution is not too "hacker proof" (but is fool proof :-D ).
VB Windows form Application.. I am developing an application of which part of the program is around configuration settings allowing the user to enter configuration items. When the menubar item for configuration menu is clicked on the main form the menu opens. This is fine but the mainform should not become active again until the configuration menu has closed. This does not happen right now and the mainform simply comes to the foreground and the configuration form goes to the background... I realize that coding an event on the Child form to handle this would not work because the child window loses control and the main form gains control.. I thought of coding a function as follows on the main form but it does not seem logical because i would have to add to it for everyform and do checking to make sure the child is actually open before trying to close it..
Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
MailSettingsWindow.Close()
RentalSettingsWindow.Close()
End Sub
I did away with the above sub routine and used the below code as per the recomendation of using showdialog which works just as i was looking for.
Private Sub MailingAndEmailSettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MailingAndEmailSettingsToolStripMenuItem.Click
Dim MailConfig As New MailSettingsWindow()
MailSettingsWindow.Showdialog()
End Sub
I did away with the above sub routine and used the below code as per the recommendation of using ShowDialog which works just as I was looking for.
My code is as follows:
Private Sub MailingAndEmailSettingsMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MailingAndEmailSettingsMenuItem.Click
Dim MailConfig As New MailSettingsWindow()
MailSettingsWindow.ShowDialog()
End Sub