Compare strings disregard case

November 26, 2013 on 7:50 pm | In Programming | No Comments

Found this on one of the many forums looking for a way to find out if a string is present within another one, without having to worry about lower case or upper case.

string title = “STRING”
if (title.IndexOf(“string”, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
{ // The string exists in the original }

Put focus on a control

February 27, 2009 on 10:40 pm | In Programming | 7 Comments

If you want to put the focus on a control immediately after the form loads, you need to show the form first.

Example:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Button2.Focus()
End Sub

Increase TextBox size

February 12, 2009 on 5:49 pm | In Programming | 2 Comments

This is a trick I might need more often since we sometimes work with large logs. And the default size of a TextBox seems to be 32767
Code to change and check the size:

Dim instance As TextBox
Dim value As Integer
instance.MaxLength = value
value = instance.MaxLength

Found that here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.maxlength.aspx

Drag and Drop to get filepath

February 9, 2009 on 6:04 pm | In Programming | 1 Comment

These pieces of code allow you to drag and drop a file into a picturebox and it will display the full path in a TextBox.

Private Sub exelreader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘exelreader is the Form name and pb is the name of the PictureBox
pb.AllowDrop = True
End Sub

Private Sub pb_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pb.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub

Private Sub pb_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pb.DragDrop
Dim filePaths As String() = {“”}
Try
filePaths = CType(e.Data.GetData(DataFormats.FileDrop), String())
Catch ex As Exception
TextBox1.Text = ex.Message
TextBox1.Text &= “Error Doing Drag/Drop”
End Try
For Each filename In filePaths
TextBox1.Text = filename
Next
End Sub

Convert to all CAPS

February 6, 2009 on 4:50 pm | In Programming | 2 Comments

To rewrite the users input to capitals.

Dim startcode As String = TextBox1.Text
Dim letters As Char()
Dim counter As Byte = startcode.Length
Dim i As Byte = 0
If startcode <> “” Then
letters = startcode.ToCharArray()
For i = 0 To (counter – 1)
letters(i) = Char.ToUpper(letters(i))
Next
Dim endcode As String = letters
End If

Add controls on the fly

February 4, 2009 on 1:24 pm | In Programming | 4 Comments

To add controls to your form (for example if a condition is met)

Dim RadioButton4 As New RadioButton()
Dim Label12 As New Label
RadioButton4.Text = “option 2”
RadioButton4.Appearance = Appearance.Button
RadioButton4.FlatAppearance.CheckedBackColor = Color.BlueViolet
If choice = “option 2” Then
RadioButton4.Checked = True
End If
RadioButton4.Location = New Point(287, 114)
RadioButton4.Size = New Size(95, 23)
Me.Controls.Add(RadioButton4)

Label12.Text = “explanation of choices”
Label12.Location = New Point(287, 16)
Label12.Size = New Size(95, 13)
Label12.Font = New Font(label12.Font, FontStyle.Bold)
Me.Controls.Add(Label12)

Execute command line utilities

February 2, 2009 on 7:31 am | In Programming | 1 Comment

A very usefull set of lines if you want to make a command line utility easier to use and manipulate the output.

Dim process As New Process()
process.StartInfo.UseShellExecute = False
process.StartInfo.FileName = path & “filename.exe”
process.StartInfo.CreateNoWindow = True
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
Dim parameters As String = ” /?”
process.StartInfo.Arguments = parameters
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.Start()
Dim SR As System.IO.StreamReader = process.StandardOutput
TextBox1.Text = SR.ReadToEnd
SR.Close()

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^