SetAttribute refusing to work with TextArea? - vb.net

Hi, new here so I am trying to keep it specific as possible but if it's not, please just tell me nicely and I'll give more info below. :)
I'm currently making a automated message sender for the game ROBLOX, and I had it working before but they recently changed the interface and basically the entire site design / build so it broke and I'm running into a issue.
So I am familiar with SetAttribute, and that's what it used before the update. But clearly something is not working here
I currently have this:
Private Sub connect_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles connect.DocumentCompleted
Try
connect.Document.GetElementById("subject").SetAttribute("value", Form1.subject.Text)
connect.Document.GetElementById("body").SetAttribute("value", Form1.enter.Text) ' This is the line I'm having issues with
connect.Document.GetElementById("send-btn").InvokeMember("click")
Catch ex As Exception
MsgBox(ErrorToString())
End Try
End Sub
End Class
The subject line and the button are working fine, but it's not filling in the the TextArea for "enter"
This is the code for the textarea on the ROBLOX site, remember I don't work there so I cannot change it to fit my needs.
<textarea rows="2" cols="20" id="body" class="messages-reply-box text-box text" style="padding:5px;width:675px;"></textarea>
So I'm not quite sure why it's not working, I have the ID right and it works with the other textbox (the subject)
This is Visual Basic, FYI.

The "value" of a textarea is not an attribute, but the InnerText (HtmlElement.InnerText property) of the textarea-element (value is between the opening and closing tags).
Change
connect.Document.GetElementById("body").SetAttribute("value", Form1.enter.Text)
To
connect.Document.GetElementById("body").InnerText = Form1.enter.Text

Related

Visual Basic Auto Scroll with RichTextBox

I want my Richtextbox to be always at the bottom and "autoscroll" to the end.
I found this with some google searches:
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox1.ScrollToCaret()
End Sub
This seems to work but as the text updates it jumps to the top of the box and with another update to the bottom. Can someone help me out? Or is there a better method to keep the Textbox at the end?
Thanks,
Max
Your code kind of works- What I would suggest to solve your initial problem is to alter your code slightly and add
RichTextBox1.SuspendLayout()
at the beginning of your sub, and
RichTextBox1.ResumeLayout()
at the end.
However, if your cursor isn't on the last line and you type something, the character will appear at the cursor before moving to the end of the text. I'm guessing you don't want that behaviour - In which case you should add the code into a KeyPress event.
There are several possible behaviours. Do you want to be able to type anywhere, or only at the end of the text? Or just to place the cursor at the end under certain circumstances - for example when the RichTextBox is first populated with a bunch of text? Or maybe something else.
The simplest solution would be for the user just to press the keys Ctrl-End. That doesnt need any code at all.

How to hide a DataGridViewButtonCell

I have a DataGridViewButtonCell in my DataGridView and I wanted to set the property Visible to True.
I have tried:
DataGridView1.Rows("number of row i want").Cells("number of cell i want").Visible = True
Unfortunately it says that the property visible is read only.
Here is the code:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
'does not work
DataGridView1.Rows(e.RowIndex).Cells(6).Visible = True
End Sub
Does anyone knows how I can achieve this?
Thanks.
There is no actual way to hide a DataGridViewButtonCell. Currently I can only see two options:
Use padding to move the button over as shown here. I will provide similar VB.NET code
Set the Cell to a DataGridViewTextBoxCell and set the ReadOnly property to True
Use Padding:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If DataGridView1.Rows(e.RowIndex).Cells(6).GetType() Is GetType(DataGridViewButtonCell) Then
Dim columnWidth As Integer = DataGridView1.Columns(e.ColumnIndex).Width
Dim newDataGridViewCellStyle As New DataGridViewCellStyle With {.Padding = New Padding(columnWidth + 1, 0, 0, 0)}
DataGridView1.Rows(e.RowIndex).Cells(6).Style = newDataGridViewCellStyle
End If
End Sub
Use DataGridViewTextBoxCell:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If DataGridView1.Rows(e.RowIndex).Cells(6).GetType() Is GetType(DataGridViewButtonCell) Then
Dim newDataGridViewCell As New DataGridViewTextBoxCell
DataGridView1.Rows(e.RowIndex).Cells(6) = newDataGridViewCell
newDataGridViewCell.ReadOnly = True
End If
End Sub
Both of these should give you the effect of not showing the button.
This is really a perspective issue. From a programmer’s perspective, simply ignoring the button clicks on the buttons I want to disable is very easy to do and takes just a few lines of code.
From a user perspective, this situation would play out like this… the user clicks what appears to be a valid enabled button, and nothing happens. The user did not write the code for this… so at best the user will think the computer is not responding to the button click or at the worst… would think your coding skills are dubious!
The same situation happens if the button is missing. The user is not going to know why it is missing… but will most likely come to the same conclusion described above with a non-working button.
In another very simple approach, let say that all the buttons are enabled and we have a list of the button indexes we want to disable. The users presses one of the buttons, we check the disabled button list and if the clicked button is one that is disabled, simply display a message box to indicate why this button is disabled. This approach says to the user… “Here are a bunch of buttons, guess which ones are enabled”…
The DataGridViewDisableButtonCell and DataGridViewDisableButtonColumn wrappers solve all of the above issues… the button is visible so the user wont question where the button went if you set it to invisible and it is greyed out. “Greyed out” is something most users understand and will relieve the user of having to “guess” which buttons are enabled.
You can create a wrapper for two classes: the DataGridViewButtonCell and the DataGridViewButtonColumn.
The link How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control to the MS example is one I have used before using C#, however there is a VB implementation at the link also.
Below is a picture of the result of using the two wrappers described in the MS link. For testing, the picture below uses the check boxes to left of the button to disable the button on the right.
IMHO, using this strategy is user friendly. If you simply make the button invisible or read only, then the user is possibly going to think your code is messed up and not have a clear understanding of WHY the button is missing or doesn’t work. A disabled button indicates to the user that the button is not available for that item. An option would be to have a mouse roll-over indicating why the button is disabled.

Error Handling in vb 2015 click event

I am just learning vb 2015. I have developed a windows application to give lookup capability to an Access database by ID, Name, Company and Phone #. The user selects the type of lookup via a radio button. I then bring up a second form that asks for the user input in a textbox and displays a datagridview of the matching rows. When the user presses the button to accept the input the click event does extensive validation of the input and shows a message box if the input is invalid. At that point I want to clear the textbox and give it focus so the user can reenter the ID, phone #, etc. I have googled and tried an number if options with no joy. If I set the .clear and .focus in the click event and then return the focus is not in the textbox. The user can click into the text box and enter a new request but it seems more elegant to put the focus back in the textbox.
Where does the control return to after a click event? Is there a standard way of handling this in vb.net?
It is possible that you are throwing an exception during your validation code.
Try putting any risky operations in a Try...Catch block, and do any necessary operations in the Finally area. This will also make sure that clearing, and re-focusing is the last thing you do.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
' Validation code
Catch ex As Exception
' Handle exception
Finally
TextBox1.Clear()
TextBox1.Focus()
End Try
End Sub

Showing MsgBox() with nowait (no user input) is not the real issue

I had searched a lot how to display a Msgbox that will not wait the user input (pressing ok or cancel).
I found 3 solutiuons to this.
1- Display the MsgBox() in another thread or using BackgroundWorker()
2- Create a form that display the message, then closed the form by a timer and use it instead of Msgbox()
3- Using the API MessageBoxA()
Let say I have a loop from 1 to 100, and I want display a message for the i(counter)
When I test above 3 ways, I found that this is not the right way of doing it, I don't need a msgbox() to close by it self after showing the message, because that will display 100 dialog.
What I realy want is to display ONLY 1 MsgBox() and change the text accordingly.
I managed to do this using a a Form() as class and I did it using Application.DoEvents
I know it can be done using BackgroundWorker or Threading since alot of people advice against using Application.Doevents
Here is my code
Dim oWW As New WaitWindow With {.TopLevel = True,.TopMost = True,.StartPosition = FormStartPosition.CenterScreen}
oWW.Show(Me)
For i = 1 to 100
Threading.Thread.Sleep(500) ' Just to slowdown execution
oWW.SetMessage("Counter = " + i.ToString)
Next
oWW.Dispose()
Public Class WaitWindow
Sub SetMessage(ByVal Message As string)
lbl_message.Text = Message
Application.DoEvents
End Sub
End Class
WaitWindow is not more than a Form base class with a label (lbl_message)
That code works fine (display WaitWindowForm on center of currently displayed form only once, then I change the text)
I have 3 questions :
1- How to display the WaitWindowForm in the top right corner of my working form?
2- Is it possible to display the normal MsgBox() or MessageBox.Show() only once, then capture the text displayed and change it?
3- Which one is suitable for my issue (BackGroundWorker or Threading) and what the code in WaitWindow class I post will be if I decided to use Backgroundworker or Threading instead of Application.DoEvents (Changing the label text not showing new form with new text) ?
3 questions in one post.. humm.. who cares, I am not the one who will answer lol :)
Thanks in advance.
I think the issue that you're really encountering is that you're trying to use a message box for something it's not suited for. If you want to have text that constantly changes just add a text box in the upper right corner of your application and adjust it every time a new message needs to be shown.
You can also look up dialogu windows (search ".showdialog() vb.net" in google) might help as well.

VB.net strange textbox behavior

A customer of mine is having a problem with a text box. When he clicks on the string in the text box the cursor always jumps to the end of the string. This is a standard VB.net 2005 text box with multi-line true. On my development machine it works correctly. I click in the middle of a string and can edit where I click. Can anyone suggest what is wrong?
He has run the program both under terminal server and locally on his lap top and has the same problem.
TIA,
John
Is it possible to observe the user? For example, the user might be pressing shift-tab when they are past the text-box, and refering to that as "clicking" the text box.
You can always force behavior like:
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.SelectionStart = 0
End Sub