Masked textbox

changing colour

Page 1 of 1

6 Replies - 8207 Views - Last Post: 10 June 2009 - 04:15 AM Rate Topic: -----

#1 saketh321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-October 07

Masked textbox

Posted 08 June 2009 - 05:26 PM

Hi,
I have an assignment in which i have to do a masked textbox for the canadian postal code. So under the mask settings i set it to L0L 0L0. My teacher wants me to make it in such a way that if the user clicks on the postal code textbox and doesn't enter any values in and click in another text box, the box should be highlighted in yellow. I am able to do it for regular textboxes using
If txtcity.Text = "" Then

			txtcity.BackColor = Color.Yellow
		Else
			txtcity.BackColor = Color.White

But when i try to the same thing for a masked textbox the colour does not change. This is what i have entered for the masked textbox

Private Sub mtxtpostalcode_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles mtxtpostalcode.MaskInputRejected

		If mtxtpostalcode.MaskFull = "" Then

			mtxtpostalcode.BackColor = Color.Yellow
		Else
			mtxtpostalcode.BackColor = Color.White

		End If
	End Sub


Any help will be appreciable. Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Masked textbox

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,480
  • Joined: 29-May 08

Re: Masked textbox

Posted 08 June 2009 - 05:38 PM

Should the user not enter any text the the .text isn't empty it has the format of the mask.
A better property to check is .MaskCompleted
Edit: mtxtpostalcode.MaskFull is a Boolean checking against "" will always be False
as False<>"" and True<>""

This post has been edited by AdamSpeight2008: 08 June 2009 - 05:40 PM

Was This Post Helpful? 0
  • +
  • -

#3 saketh321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-October 07

Re: Masked textbox

Posted 08 June 2009 - 06:01 PM

hmm i have the same exact project my teacher did and he put it up online to use as a reference. He put it up as an .exe file, is there a way i can upload that to give you a better idea?
Was This Post Helpful? 0
  • +
  • -

#4 saketh321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-October 07

Re: Masked textbox

Posted 08 June 2009 - 10:43 PM

I also have another question. I need to make the program so that if a person enters the value in the postal then and only then another dialog box activates and i can enter text in it. Until i enter anything into the postal code box it is greyed out.
Was This Post Helpful? 0
  • +
  • -

#5 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Masked textbox

Posted 09 June 2009 - 05:42 AM

Hi,

Put your code into the textchanged event from your maskedtextbox and then use this snippet.

Private Sub mtxtpostalcode_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mtxtpostalcode.TextChanged
	   If mtxtpostalcode.MaskFull Then

			mtxtpostalcode.BackColor = Color.Yellow
		Else
			mtxtpostalcode.BackColor = Color.White

		End If

	End Sub

Was This Post Helpful? 0
  • +
  • -

#6 saketh321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-October 07

Re: Masked textbox

Posted 09 June 2009 - 11:10 PM

View PostLuc001, on 9 Jun, 2009 - 04:42 AM, said:

Hi,

Put your code into the textchanged event from your maskedtextbox and then use this snippet.

Private Sub mtxtpostalcode_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mtxtpostalcode.TextChanged
	   If mtxtpostalcode.MaskFull Then

			mtxtpostalcode.BackColor = Color.Yellow
		Else
			mtxtpostalcode.BackColor = Color.White

		End If

	End Sub


Thanks Luc but that still doesn't work. Any new ideas?


i have another question. How do you write a code so that unless you enter text in a certain textbox a textbox besides it doesn't get activated to put text in?
Was This Post Helpful? 0
  • +
  • -

#7 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Masked textbox

Posted 10 June 2009 - 04:15 AM

Hi saketh321,

Quote

that still doesn't work. Any new ideas?


I've tested it with my maskedtextbox and is working well.

For your other question you can use this:

TextBox2.Enabled = false


and then after you have some text in the postal textbox this:

Textbox2.Enabled = true

This post has been edited by Luc001: 10 June 2009 - 04:16 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1