Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. masked textbox

masked textbox

Scheduled Pinned Locked Moved C#
helpcsharpcssdotnetdesign
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KrunalC
    wrote on last edited by
    #1

    My question is based on functionality in Masked Textbox control which is available only in .Net framework 2.0 onwards. I want the kind of functionality provided by MaskedTextbox control but I can't use this control as I'm currently working on framework 1.1. So I have decided to make one for me on my own. I derived the control from Text box. I was able to implement Mask dialog and validations but stuck up with text property implementation of control. For the Masked Textbox, if you implement telephone no. mask with format (___)___-____, then text property value initially will be blank. But on the form, Masked TextBox text will show format i.e. "(___)___-____". Also, if I write 333 in property grid for text property then in property Grid I will be able to see value as "333" while in the Control on the form it will display me a text like "(333)___-____". So in a way two different values for the same text property in property grid and control. So this is bit confusing and don't know how to implement this thing in a same way as provided by Masked Text box. I tried to implement this by overriding the text property and giving different implementation for design time and run time. But its not helping me. Can anyone help me by providing some ideas on how to do above things. I hope I'm clear with my question. If reading above, you are not clear about the question pls write back to me or check the working of Masked Textbox control for better understanding. Regards, KC

    M 1 Reply Last reply
    0
    • K KrunalC

      My question is based on functionality in Masked Textbox control which is available only in .Net framework 2.0 onwards. I want the kind of functionality provided by MaskedTextbox control but I can't use this control as I'm currently working on framework 1.1. So I have decided to make one for me on my own. I derived the control from Text box. I was able to implement Mask dialog and validations but stuck up with text property implementation of control. For the Masked Textbox, if you implement telephone no. mask with format (___)___-____, then text property value initially will be blank. But on the form, Masked TextBox text will show format i.e. "(___)___-____". Also, if I write 333 in property grid for text property then in property Grid I will be able to see value as "333" while in the Control on the form it will display me a text like "(333)___-____". So in a way two different values for the same text property in property grid and control. So this is bit confusing and don't know how to implement this thing in a same way as provided by Masked Text box. I tried to implement this by overriding the text property and giving different implementation for design time and run time. But its not helping me. Can anyone help me by providing some ideas on how to do above things. I hope I'm clear with my question. If reading above, you are not clear about the question pls write back to me or check the working of Masked Textbox control for better understanding. Regards, KC

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, I think in that case only a workaround does the trick! Because Text property of TextBox seems to be special case. Therefore I would use an additional "newText" property and hide the "Text" property.

      	private string \_newText="";
      
      	\[DefaultValue("")\]
      	public string NewText
      	{
      		get
      		{
      			return \_newText;
      		}
      		set
      		{
      			if(value!=\_newText)
      			{
      				\_newText = value;
      				Text = \_newText+" I'm formated";
      			}
      		}
      	}
      
      	\[Browsable(false)\]
      	public new string Text
      	{
      		get
      		{
      			return base.Text;
      		}
      		set
      		{
      			if(value!=base.Text)
      			{
      				base.Text = value;
      			}
      		}
      	}
      

      Hope it helps!

      All the best, Martin

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups