Results 1 to 9 of 9

Thread: Checkbox and Textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Checkbox and Textbox

    Hi all i need help with it, I'm trainig to make a program, when you check 2 different Checkbox it add on textbox. The textbox need create a other line witout delete the fist.

    I dont have problems when checkbox it add on textbox but i dont make me a new line it's all togheter.

    Thankx

    ps: sorry for my bad english

  2. #2
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    Re: Checkbox and Textbox

    There are many methods to this... One that I came up with is: Put your Checkboxes in a Groupbox (make it invisible if necessary). Then use a For...Each loop to check how many are checked:

    Code:
    Dim n as Short
    For Each chkbox as Checkbox in GroupBox1.Controls
    If chkbox.Checked = True Then n+=1
    Next
    If n >=2 Then 'add whatever you wanted here
    Please tell me that I understood your question correctly and this is what you want

  3. #3
    New Member
    Join Date
    Nov 2010
    Location
    U.S.
    Posts
    15

    Re: Checkbox and Textbox

    I think I'm down a similar road here. I would have had it here much sooner, but I keep getting logged out for some reason.

    Try this;

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, _
    4.     ByVal e As System.EventArgs) Handles MyBase.Load
    5.         TextBox1.Text = "Hello World!"
    6.         TextBox1.Multiline = True
    7.     End Sub
    8.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
    9.     ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged
    10.         If CheckBox1.Checked And CheckBox2.Checked = True Then
    11.             'new text is the text you will add on new line
    12.             TextBox1.Text = (TextBox1.Text & vbCrLf & "Nice to see You!")
    13.         End If
    14.     End Sub
    15.    
    16. End Class

  4. #4
    New Member
    Join Date
    Nov 2010
    Location
    U.S.
    Posts
    15

    Re: Checkbox and Textbox

    actually, the line
    TextBox1.Multiline = True Code:
    1. TextBox1.Multiline = True
    is not necessary.
    You have to change the textbox property to multiline in the "Properties" window to accomplish this, then stretch the textbox vertically.
    Or you could code it to change size with each additional line.

    This demonstrates the send approach;


    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.Text = "Hello World!"
    TextBox1.Multiline = True
    End Sub
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged
    If CheckBox1.Checked And CheckBox2.Checked = True Then
    'new text is the text you will add on new line
    TextBox1.Size = New Size(TextBox1.Width, TextBox1.Height + 15)
    TextBox1.Text = (TextBox1.Text & vbCrLf & "Nice to see You!")
    End If
    End Sub

    End Class

    Sorry, I cant get the code to format to vb this time!
    Last edited by docfnt; Oct 3rd, 2011 at 06:30 PM. Reason: Cant get the edit to highlight correctly

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Re: Checkbox and Textbox

    Quote Originally Posted by docfnt View Post
    I think I'm down a similar road here. I would have had it here much sooner, but I keep getting logged out for some reason.

    Try this;

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, _
    4.     ByVal e As System.EventArgs) Handles MyBase.Load
    5.         TextBox1.Text = "Hello World!"
    6.         TextBox1.Multiline = True
    7.     End Sub
    8.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
    9.     ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged
    10.         If CheckBox1.Checked And CheckBox2.Checked = True Then
    11.             'new text is the text you will add on new line
    12.             TextBox1.Text = (TextBox1.Text & vbCrLf & "Nice to see You!")
    13.         End If
    14.     End Sub
    15.    
    16. End Class

    It's good the problem is i already have a group of checkbox but i have 2
    the fist group have names and the senc have numbers where it say "nice to see you" I need add other checkbox's

  6. #6
    New Member
    Join Date
    Nov 2010
    Location
    U.S.
    Posts
    15

    Re: Checkbox and Textbox

    This adds a new checkbox. You should be able to get it from here on...

    vb Code:
    1. Public Class Form1
    2.  
    3.     'CheckBox1 location = (12, 12)
    4.     'CheckBox1 location = (12, 35)
    5.     'textbox1.location = (12, 121)
    6.  
    7.     Private Sub Form1_Load(ByVal sender As System.Object, _
    8.     ByVal e As System.EventArgs) Handles MyBase.Load
    9.         TextBox1.Text = "Hello World!"
    10.         TextBox1.Multiline = True
    11.     End Sub
    12.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
    13.     ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged
    14.         If CheckBox1.Checked And CheckBox2.Checked = True Then
    15.             'new text is the text you will add on new line
    16.             TextBox1.Size = New Size(TextBox1.Width, TextBox1.Height + 15)
    17.             TextBox1.Text = (TextBox1.Text & vbCrLf & "Nice to see You!")
    18.             Dim CheckBox3 As New CheckBox
    19.             CheckBox3.Location = New Point(12, 58)
    20.             CheckBox3.Size = New Size(81, 17)
    21.             CheckBox3.Text = "CheckBox3"
    22.             Me.Controls.Add(CheckBox3)
    23.  
    24.             AddHandler CheckBox3.CheckedChanged, AddressOf CheckBox3_CheckedChanged
    25.         End If
    26.     End Sub
    27.  
    28.     Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, _
    29.     ByVal e As System.EventArgs)
    30.         'whatever you want here
    31.         TextBox1.Size = New Size(TextBox1.Width, TextBox1.Height + 15)
    32.         TextBox1.Text = (TextBox1.Text & vbCrLf & "Same Goes")
    33.     End Sub
    34.  
    35. End Class

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Re: Checkbox and Textbox

    Quote Originally Posted by docfnt View Post
    This adds a new checkbox. You should be able to get it from here on...

    vb Code:
    1. Public Class Form1
    2.  
    3.     'CheckBox1 location = (12, 12)
    4.     'CheckBox1 location = (12, 35)
    5.     'textbox1.location = (12, 121)
    6.  
    7.     Private Sub Form1_Load(ByVal sender As System.Object, _
    8.     ByVal e As System.EventArgs) Handles MyBase.Load
    9.         TextBox1.Text = "Hello World!"
    10.         TextBox1.Multiline = True
    11.     End Sub
    12.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
    13.     ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged
    14.         If CheckBox1.Checked And CheckBox2.Checked = True Then
    15.             'new text is the text you will add on new line
    16.             TextBox1.Size = New Size(TextBox1.Width, TextBox1.Height + 15)
    17.             TextBox1.Text = (TextBox1.Text & vbCrLf & "Nice to see You!")
    18.             Dim CheckBox3 As New CheckBox
    19.             CheckBox3.Location = New Point(12, 58)
    20.             CheckBox3.Size = New Size(81, 17)
    21.             CheckBox3.Text = "CheckBox3"
    22.             Me.Controls.Add(CheckBox3)
    23.  
    24.             AddHandler CheckBox3.CheckedChanged, AddressOf CheckBox3_CheckedChanged
    25.         End If
    26.     End Sub
    27.  
    28.     Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, _
    29.     ByVal e As System.EventArgs)
    30.         'whatever you want here
    31.         TextBox1.Size = New Size(TextBox1.Width, TextBox1.Height + 15)
    32.         TextBox1.Text = (TextBox1.Text & vbCrLf & "Same Goes")
    33.     End Sub
    34.  
    35. End Class

    Nop look what my checkbox say, every checkbox what i have say somthing i need just a new line in textbox

    look my code:

    If CheckBox2.Checked And CheckBox8.Checked = True Then
    TextBox1.Text = "bind kp_downarrow m41a"

    when they check both check it add on textbox then in the textbox need a new line with other 2 checkbox

  8. #8
    New Member
    Join Date
    Nov 2010
    Location
    U.S.
    Posts
    15

    Re: Checkbox and Textbox

    Can you be a little clearer on that please, I can't understand you.

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Re: Checkbox and Textbox

    Quote Originally Posted by docfnt View Post
    Can you be a little clearer on that please, I can't understand you.
    Yes, the fist check box choise a weapon, and che second checkbox choise the number, when they chose fist wearopn and number it add on textbox
    in the textbox it make a new line, without deleted the fist, and when you choise differenct it add on the textbox

    If CheckBox2.Checked And CheckBox8.Checked = True Then
    TextBox1.Text = "bind kp_downarrow m41a"


    Checkbox2 = "m41a" and checkbox8 = "kp_downarrow" (number 2 on key pad)
    them it add on the textbox like it: "bind kp_downarrow m41a"
    When it's add(txtbox) it make a new line witouth deleted.


    If CheckBox2.Checked And CheckBox8.Checked = True Then
    TextBox1.Text = "bind kp_downarrow m41a" & vbCrLf & (other checkbox's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width