الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

أريد كود لجميع حالات inputbox

بدأه Visual Studio في 4 مارس 2014 · 5 رد · 708 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

 

عندي inputbox وأريد عندما يضغط المستخدم زر cancel فإنه يلغي العملية وعندما يضغط ok فإنه ينظر إذا كان المدخل فارغ يظهر له رسالة بأنه غير مسموح بادخال بيان فارغ وإن كان المدخل أي شيء مكتوب فإنه يقوم بتنفيذ الكود

 

قمت بكتابة الكود التالي لكنه لا يظهر رسالة عند ادخال شيء فارغ

 Dim Str As String

        Str = InputBox("Please Input The Project Name")


        If Str Is Nothing Then
            MsgBox("cannot save empty data")
            Exit Sub

        Else
            txt_Name.Text = Str
        End If
#2

Dim Str As String

Str = InputBox("Please Input The Project Name")

If Str = "" Then

MsgBox("cannot save empty data")

Exit Sub

Else

txt_Name.Text = Str

End If

VB.NET and C# Comparison

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

002.gif

=-=-=-=-=-=-=
ذو العلم يشقى فى النعيم بعلمه .:. واخو الجهالة فى الشقاوة ينعم
=-=-=-=-=-=-=
يا من بدنياه اشتغل . قد غره طول الأمل . فالموت يأتى بغتة . والقبر صندوق العمل
=-=-=-=-=-=-=
ان لم تستطع ان تجد ما تفعله فافعل ما لم تسطع ان تجده

screen_shot_2011-05-19_at_12.44.49_pm.pn

#4

عند الضغط على cancel  فان الداله تعود بـempty string فلا يمكن معرفة اذا تم الضغط على ok  بدون ادخال او cancel مع ادخال ا,,و بدون على كل الهدف من هذه الميثود هو الحصول على ادخال لا يهم اذا كان فارغ او cancel  فالنتيجة واحدة

اذا كان من الضرورى معرفة الحالاات الثلاث... انشئ customized control  بهذه الوظيفة

VB.NET and C# Comparison

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

002.gif

=-=-=-=-=-=-=
ذو العلم يشقى فى النعيم بعلمه .:. واخو الجهالة فى الشقاوة ينعم
=-=-=-=-=-=-=
يا من بدنياه اشتغل . قد غره طول الأمل . فالموت يأتى بغتة . والقبر صندوق العمل
=-=-=-=-=-=-=
ان لم تستطع ان تجد ما تفعله فافعل ما لم تسطع ان تجده

screen_shot_2011-05-19_at_12.44.49_pm.pn

#5

مثال سريع لعمل Custom InputBox

كود InputBoxEX  وهو dll Library

Public Class InputBox
    Public ReadOnly Property Input As String
        Get
            Input = TextBoxInput.Text.Trim
        End Get
    End Property
    Shared Function ShowInput(Optional ByVal message As String = "", Optional ByVal title As String = "") As Dictionary(Of Integer, String)
        Dim input = New InputBox
        input.LabelTitle.Text = message
        input.Text = title

        Dim result As New Dictionary(Of Integer, String)
        result.Add(input.ShowDialog(), input.Input)


        Return result
    End Function

   
End Class

كود Test Project

Imports InputBoxEx.InputBox
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim result As New Dictionary(Of Integer, String)
        result = ShowInput("enter data", "here is title")
        If result.Keys.FirstOrDefault = 1 Then
            If result.Item(1).Length <> 0 Then
                MessageBox.Show("your input is: " + result.Item(1))
            Else
                MessageBox.Show("cannot save empty data")
            End If
        Else
            MessageBox.Show("Cancle or close button clicked")
        End If
    End Sub
End Class

InputBoxEx.rar

VB.NET and C# Comparison

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

002.gif

=-=-=-=-=-=-=
ذو العلم يشقى فى النعيم بعلمه .:. واخو الجهالة فى الشقاوة ينعم
=-=-=-=-=-=-=
يا من بدنياه اشتغل . قد غره طول الأمل . فالموت يأتى بغتة . والقبر صندوق العمل
=-=-=-=-=-=-=
ان لم تستطع ان تجد ما تفعله فافعل ما لم تسطع ان تجده

screen_shot_2011-05-19_at_12.44.49_pm.pn

مواضيع مشابهة