Click here to Skip to main content
15,886,026 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionForce prompt UAC via button Pin
Brandon-X1200028-Apr-12 7:53
Brandon-X1200028-Apr-12 7:53 
AnswerRe: Force prompt UAC via button Pin
Richard MacCutchan28-Apr-12 21:40
mveRichard MacCutchan28-Apr-12 21:40 
AnswerRe: Force prompt UAC via button Pin
Eddy Vluggen30-Apr-12 1:01
professionalEddy Vluggen30-Apr-12 1:01 
AnswerRe: Force prompt UAC via button Pin
Bernhard Hiller2-May-12 0:28
Bernhard Hiller2-May-12 0:28 
Questioncreating quarterly alerts Pin
Member 889779127-Apr-12 21:16
Member 889779127-Apr-12 21:16 
AnswerRe: creating quarterly alerts Pin
Richard MacCutchan27-Apr-12 23:34
mveRichard MacCutchan27-Apr-12 23:34 
AnswerRe: creating quarterly alerts Pin
ZurdoDev30-Apr-12 10:37
professionalZurdoDev30-Apr-12 10:37 
QuestionKeyDown Event and Focus Command not working Pin
Midnight Ahri26-Apr-12 21:40
Midnight Ahri26-Apr-12 21:40 
i found some messenger code, modify and use it,

my problem is, txtMessage keydown event that will automatically click button send is not working,
and again everytime my form loads, focus is on txtDisplay, not on txtMessage.

i copied some of the code below.
is this caused by add handler and thread?

VB
Option Strict On
Imports System.Windows.Forms
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text
Imports DevExpress.XtraEditors

Namespace Forms
    Public Class Messenger

        Delegate Sub AddMessage(ByRef message As String)

        Private Const port As Integer = 33333
        Private Const broadcastAddress As String = "255.255.255.255"

        Private receivingClient As UdpClient
        Private sendingClient As UdpClient
        Private receivingThread As Thread

        Public Sub New()
            ' This call is required by the designer.
            InitializeComponent()
            ' Add any initialization after the InitializeComponent() call.
            AddHandler btnSend.Click, AddressOf btnSend_Click
        End Sub

        Private Sub txtMessage_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs)
            Select Case e.KeyCode
                Case Keys.Enter
                    btnSend.PerformClick()
            End Select
        End Sub

        Private Sub Messenger_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            Objects.Classes.Universal.Variables.formMessenger = True

            InitializeSender()
            InitializeReceiver()

            Me.txtMessage.Text = ""
            Me.txtMessage.Focus()
        End Sub

        Private Sub btnSend_Click(sender As System.Object, e As System.EventArgs)
            txtMessage.Text = txtMessage.Text.Trim()

            Dim toSend As String =
                "(" +
                DateTime.Now.ToString("HH:mm") +
                ")" +
                Objects.Classes.Universal.Variables.Username + " > " + txtMessage.Text
            Dim data() As Byte = Encoding.ASCII.GetBytes(toSend)
            sendingClient.Send(data, data.Length)
            Me.txtMessage.Text = ""
            Me.txtMessage.Focus()
        End Sub

        Private Sub MessageReceived(ByRef message As String)
            txtDisplay.Text += message + vbNewLine
        End Sub

        Private Sub InitializeSender()
            sendingClient = New UdpClient(broadcastAddress, port)
            sendingClient.EnableBroadcast = True
        End Sub

        Private Sub InitializeReceiver()
            receivingClient = New UdpClient(port)

            Dim start As ThreadStart = New ThreadStart(AddressOf Receiver)
            receivingThread = New Thread(start)
            receivingThread.IsBackground = True
            receivingThread.Start()
        End Sub

        Private Sub Receiver()
            Dim endPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, port)
            Dim messageDelegate As AddMessage = AddressOf MessageReceived

            While (True)
                Dim data() As Byte
                data = receivingClient.Receive(endPoint)
                Dim message As String = Encoding.ASCII.GetString(data)
                Invoke(messageDelegate, message)
            End While
        End Sub

    End Class
End Namespace

AnswerRe: KeyDown Event and Focus Command not working Pin
Simon_Whale27-Apr-12 5:14
Simon_Whale27-Apr-12 5:14 
AnswerRe: KeyDown Event and Focus Command not working Pin
Midnight Ahri27-Apr-12 14:57
Midnight Ahri27-Apr-12 14:57 
AnswerRe: KeyDown Event and Focus Command not working Pin
Newbie5130-Apr-12 6:09
Newbie5130-Apr-12 6:09 
AnswerRe: KeyDown Event and Focus Command not working Pin
Midnight Ahri30-Apr-12 18:01
Midnight Ahri30-Apr-12 18:01 
QuestionVB 2010 and MIDI device input Pin
dmt194026-Apr-12 5:29
dmt194026-Apr-12 5:29 
AnswerRe: VB 2010 and MIDI device input Pin
Richard MacCutchan26-Apr-12 22:03
mveRichard MacCutchan26-Apr-12 22:03 
GeneralRe: VB 2010 and MIDI device input Pin
dmt194027-Apr-12 2:08
dmt194027-Apr-12 2:08 
GeneralRe: VB 2010 and MIDI device input Pin
Richard MacCutchan27-Apr-12 2:32
mveRichard MacCutchan27-Apr-12 2:32 
QuestionVB6 Pin
PLAAHemantha26-Apr-12 5:04
PLAAHemantha26-Apr-12 5:04 
AnswerRe: VB6 Pin
Eddy Vluggen26-Apr-12 10:17
professionalEddy Vluggen26-Apr-12 10:17 
AnswerRe: VB6 Pin
Dave Kreskowiak26-Apr-12 10:56
mveDave Kreskowiak26-Apr-12 10:56 
GeneralRe: VB6 Pin
Brandon-X1200027-Apr-12 2:28
Brandon-X1200027-Apr-12 2:28 
GeneralRe: VB6 Pin
Dave Kreskowiak27-Apr-12 3:19
mveDave Kreskowiak27-Apr-12 3:19 
SuggestionRe: VB6 Pin
Eddy Vluggen27-Apr-12 5:03
professionalEddy Vluggen27-Apr-12 5:03 
QuestionNeed Help with this program Pin
gamemaker82525-Apr-12 18:06
gamemaker82525-Apr-12 18:06 
AnswerRe: Need Help with this program Pin
Richard MacCutchan25-Apr-12 21:29
mveRichard MacCutchan25-Apr-12 21:29 
AnswerRe: Need Help with this program Pin
riced25-Apr-12 23:36
riced25-Apr-12 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.