Enable/Disable Print Button

imti

Member
Joined
Jun 15, 2005
Messages
7
Programming Experience
Beginner
[hi there
a text box and a print button in group box.. when we dont type in text box i want the print button to disable ..but no longer we start typing in text box the print button will enable and then if we click on print then it will print .
how its to be done ...????pls help me ..i m a new learner and any help from u will be appriciated
thx
imti

*** how to sumit a new post here ????
 
The code should look like:

VB.NET:
 Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Form1_Load([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles [/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Load
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].Button1.Enabled = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] TextBox1_TextChanged([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] TextBox1.TextChanged
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].Button1.Enabled = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Button1.Click
 
MessageBox.Show("Printing ... !")
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].Button1.Enabled = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub

but as i suspect it's understandable ... i also attached demo and you can take a look at that ... Cheers ;)

Added: Hey, welcome to the forum :)
 

Attachments

  • EnableDisablePrintButton.zip
    23.2 KB · Views: 34
hi kulrom

thxa lot for ur quick reply ..my first post and my first answer ...and what sud i say abt ur mail ....its vary nice ... i m enjoying here now ...probably u 've already some idea about my skill ..lol ..coz i asked a very simple problem regarding ur knowledge of programming skill ....but i will keep asking u as long as u dont mind ... i m learning ...lol...
lastly thx a lot agin for ur assisting ...
best regards
imti
 
kulrom's post does work, but there's at least one thing that isnt checked for:

VB.NET:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

If TextBox1.Text.Length <> 0 Then Me.Button1.Enabled = True
 
End Sub
 
JuggaloBrotha said:
kulrom's post does work, but there's at least one thing that isnt checked for:

VB.NET:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
 
If TextBox1.Text.Length <> 0 Then Me.Button1.Enabled = True
 
End Sub

Let's say i will stay with attitude "no comment" JK :D
Well, all that he could additionally check out is whether user has typed blank space and it should be done like this:

VB.NET:
 [size=2][color=#0000ff]
Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] TextBox1_TextChanged([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] TextBox1.TextChanged

[/size][size=2][color=#0000ff]If[/color][/size][size=2] TextBox1.Text.Trim = [/size][size=2][color=#0000ff]String[/color][/size][size=2].Empty [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]MessageBox.Show("First type something")

TextBox1.Text = [/size][size=2][color=#0000ff]String[/color][/size][size=2].Empty

[/size][size=2][color=#0000ff]Exit[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub

[/color][/size][size=2][/size][size=2][color=#0000ff]Else

[/color][/size][size=2][/size][size=2][color=#0000ff]Me[/color][/size][size=2].Button1.Enabled = [/size][size=2][color=#0000ff]True

[/color][/size][size=2][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub

[/color][/size]


Cheers ;)
 
How about:
VB.NET:
	Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
		Me.printButton.Enabled = (Me.TextBox1.Text.Trim() <> String.Empty)
	End Sub
 
Back
Top