القائمة الرئيسية

الصفحات

البرنامج التعليمي فيجوال بيسك 2010 : لوحة المفاتيح المرئية Screen Keyboard

السلام عليكم ورحمة الله تعالى وبركاته

نلتقي في درس جديد من دروس البرنامج التعليمي لفيجوال بيسك 2010 حيت سنطرح اليوم موضوع جديد وهو كيفية 
انشاء وبرمجة لوحة مفاتيح كايبورد مرئية من خلال الفيجوال بيسك 2010

اهم خطوة في هذا البرنامج التعليمي هو وضع وادراج المفاتيح داخل الفورم Form على النموذج ، ولقد قمت بادراج لكم خارطة لوضع المفاتيح وترتيبها داخل الفوم Form من اجل تنسيق الأزرار لتكن متوافقة مع الشكل التالي :

لوحة مفاتيح مرئية بالفيجوال بيسك


















ملاحظة : النص الاحمر يشير الى اسم الزر والنص المكتوب باللون الأسود يشير الى النص الذي يكتب بداخل الزر مثال : الزر الاول button1 لما نقوم بادراجه يكون مكتوب بداخله button1 لكن نحن نغير button1 المكتوب داخل الزر بـ 1 مثل ما هو موجود في المثال أعلاه

يجب ان يكون ترتيب الازرار وجميع الادوات مثل ما هو موضح في الصورة

في الأخير تكون النتيجة على الشكل : 

لوحة مفاتيح مرئية بالفيجوال بيسك

بعد إعداد النموذج وإضافة الأزرار الموجودة بنفس الترتيب في الصورة الأولى، دعونا نقوم ببرمجة الأزرار:

Typing Keys:

Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click, _
    Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button48.Click, Button47.Click, _
    Button46.Click, Button45.Click, Button44.Click, Button43.Click, Button42.Click, Button41.Click, _
    Button40.Click, Button4.Click, Button39.Click, Button38.Click, Button37.Click, Button36.Click, _
    Button35.Click, Button34.Click, Button33.Click, Button32.Click, Button31.Click, Button30.Click, _
    Button3.Click, Button29.Click, Button28.Click, Button26.Click, Button25.Click, Button24.Click, _
    Button23.Click, Button22.Click, Button21.Click, Button20.Click, Button2.Click, Button19.Click, _
    Button18.Click, Button17.Click, Button16.Click, Button15.Click, Button14.Click, Button13.Click, _
    Button12.Click, Button11.Click, Button10.Click, Button1.Click 
        If ShiftR.FlatStyle = FlatStyle.Flat Then
            TextBox1.Text = TextBox1.Text + sender.text
            ShiftR.PerformClick()
        Else
TextBox1.Text = TextBox1.Text + sender.text
        End If
       
    End Sub

Backspace Key
The following code will handle the Backspace button click event:
Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
        If TextBox1.Text < " " Then
            TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1 + 1)
        Else
            TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)
        End If
    End Sub


Enter Key
The following code will handle the Enter button click event:
Private Sub Enter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enter.Click
        TextBox1.Text = TextBox1.Text & Environment.NewLine 
    End Sub


Righ and Left Shift Keys
The following code will handle both right and left Shift keys:
Private Sub ShiftR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShiftR.Click, ShiftL.Click
If ShiftR.FlatStyle = FlatStyle.Flat Then
            ShiftR.FlatStyle = FlatStyle.Standard
            ShiftL.FlatStyle = FlatStyle.Standard
            For Each ctl As Control In Me.Controls
                If (ctl.Name.StartsWith("Button")) Then
                    Dim btn As Button = DirectCast(ctl, Button)
                    btn.Text = btn.Text.ToLower
                    Button1.Text = "1"
                    Button2.Text = "2"
                    Button3.Text = "3"
                    Button4.Text = "4"
                    Button5.Text = "5"
                    Button6.Text = "6"
                    Button7.Text = "7"
                    Button8.Text = "8"
                    Button9.Text = "9"
                    Button10.Text = "0"
                    Button11.Text = "-"
                    Button12.Text = "="
                    Button13.Text = "`"
                    Button14.Text = "\"
                    Button15.Text = "]"
                    Button16.Text = "["
                    Button29.Text = "'"
                    Button30.Text = ";"
                    Button28.Text = "/"
                    Button40.Text = "."
                    Button41.Text = ","
                End If 
            Next
        ElseIf ShiftR.FlatStyle = FlatStyle.Standard Then
            ShiftL.FlatStyle = FlatStyle.Flat
            ShiftR.FlatStyle = FlatStyle.Flat
            For Each ctl As Control In Me.Controls
                If (ctl.Name.StartsWith("Button")) Then
                    Dim btn As Button = DirectCast(ctl, Button)
                    btn.Text = btn.Text.ToUpper
                    Button1.Text = "!"
                    Button2.Text = "@"
                    Button3.Text = "#"
                    Button4.Text = "$"
                    Button5.Text = "%"
                    Button6.Text = "^"
                    Button7.Text = "&"
                    Button8.Text = "*"
                    Button9.Text = "("
                    Button10.Text = ")"
                    Button11.Text = "_"
                    Button12.Text = "+"
                    Button13.Text = "~"
                    Button14.Text = "|"
                    Button15.Text = "}"
                    Button16.Text = "{"
                    Button29.Text = """"
                    Button30.Text = ":"
                    Button28.Text = "?"
                    Button40.Text = ">"
                    Button41.Text = "<"
                End If
             Next
        End If
    End Sub


Caps Lock Key:
The followng code will handle the Caps Lock button click event:

Private Sub Caps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Caps.Click
        If Caps.FlatStyle = FlatStyle.Flat Then
            Caps.FlatStyle = FlatStyle.Standard
            Caps.BackColor = Color.FromKnownColor(KnownColor.Control)
            For Each ctl As Control In Me.Controls
                If (ctl.Name.StartsWith("Button")) Then
                    Dim btn As Button = DirectCast(ctl, Button)
                    btn.Text = btn.Text.ToLower
                    Button1.Text = "1"
                    Button2.Text = "2"
                    Button3.Text = "3"
                    Button4.Text = "4"
                    Button5.Text = "5"
                    Button6.Text = "6"
                    Button7.Text = "7"
                    Button8.Text = "8"
                    Button9.Text = "9"
                    Button10.Text = "0"
                    Button11.Text = "-"
                    Button12.Text = "="
                    Button13.Text = "`"
                    Button14.Text = "\"
                    Button15.Text = "]"
                    Button16.Text = "["
                    Button29.Text = "'"
                    Button30.Text = ";"
                    Button28.Text = "/"
                    Button40.Text = "."
                    Button41.Text = ","
                End If

            Next
        ElseIf Caps.FlatStyle = FlatStyle.Standard Then
            Caps.FlatStyle = FlatStyle.Flat
            Caps.BackColor = Color.LightGreen
            For Each ctl As Control In Me.Controls
                If (ctl.Name.StartsWith("Button")) Then
                    Dim btn As Button = DirectCast(ctl, Button)
                    btn.Text = btn.Text.ToUpper
                    Button1.Text = "!"
                    Button2.Text = "@"
                    Button3.Text = "#"
                    Button4.Text = "$"
                    Button5.Text = "%"
                    Button6.Text = "^"
                    Button7.Text = "&"
                    Button8.Text = "*"
                    Button9.Text = "("
                    Button10.Text = ")"
                    Button11.Text = "_"
                    Button12.Text = "+"
                    Button13.Text = "~"
                    Button14.Text = "|"
                    Button15.Text = "}"
                    Button16.Text = "{"
                    Button29.Text = """"
                    Button30.Text = ":"
                    Button28.Text = "?"
                    Button40.Text = ">"
                    Button41.Text = "<"
                End If

            Next
        End If
    End Sub


The Tab Key:
The following code will handle the Tab key click event:

Private Sub Tab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tab.Click
        TextBox1.Text = TextBox1.Text & "   "
    End Sub 


The space Key:
the following code will handle the Space key click event:

Private Sub Space_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Space.Click
        TextBox1.Text = TextBox1.Text & " "
    End Sub

نلتقي في تدوينة لاحقة 

لا تنسوا مشاركة الدرس مع الاصدقاء

تعليقات