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. MSpaint TextBox..

MSpaint TextBox..

Scheduled Pinned Locked Moved C#
csharptutorial
4 Posts 3 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.
  • J Offline
    J Offline
    jk chan
    wrote on last edited by
    #1

    Hi all :cool: I am C# programmer.. For my project i want to create a textbox like in Mspaint,which restrict the entering of characters upon reaching the Size. I tried with MeasureString.. But not works Pls tell if anyone knows how to do it.. Warm regards Krishnan If u can Dream... U can do it

    H 1 Reply Last reply
    0
    • J jk chan

      Hi all :cool: I am C# programmer.. For my project i want to create a textbox like in Mspaint,which restrict the entering of characters upon reaching the Size. I tried with MeasureString.. But not works Pls tell if anyone knows how to do it.. Warm regards Krishnan If u can Dream... U can do it

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      MeasureString is graphics, which is why it's defined on the Graphics class. To limit text in a TextBox, you can post-validate the control (which fires when the focus is lost for that control) by handling the Validating event. If you want to limit which characters will even work, override the IsInputChar method for the TextBox:

      public class NumericTextBox : TextBox
      {
      protected override bool IsInputChar(char charCode)
      {
      return charCode >= '0' &&charCode <= '9';
      }
      }

      This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      J 1 Reply Last reply
      0
      • H Heath Stewart

        MeasureString is graphics, which is why it's defined on the Graphics class. To limit text in a TextBox, you can post-validate the control (which fires when the focus is lost for that control) by handling the Validating event. If you want to limit which characters will even work, override the IsInputChar method for the TextBox:

        public class NumericTextBox : TextBox
        {
        protected override bool IsInputChar(char charCode)
        {
        return charCode >= '0' &&charCode <= '9';
        }
        }

        This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        J Offline
        J Offline
        jk chan
        wrote on last edited by
        #3

        In my case i want to know how many charcaters can be enter in the textbox . How it can be know. So when reaching that number i can disable entering characters.. The problem here is to find the number of characters that can be enter in the text box (No scrolls).. What u think ? Regards Krishnan If u can Dream... U can do it

        L 1 Reply Last reply
        0
        • J jk chan

          In my case i want to know how many charcaters can be enter in the textbox . How it can be know. So when reaching that number i can disable entering characters.. The problem here is to find the number of characters that can be enter in the text box (No scrolls).. What u think ? Regards Krishnan If u can Dream... U can do it

          L Offline
          L Offline
          Luis Alonso Ramos
          wrote on last edited by
          #4

          The MaxLength property of the TextBox lets you set a maximum number of characters that the user can enter, no matter the width (it can be 10 m's or 10 i's). But if you set the TextBox to be, say, 100 pixels wide, and you want only 100 pixels of letters, be it 5 m's or 8 i's, it's a bit more difficult. As an option, try using the MaxLength property and making the TextBox wide enough. But if you absolutely need to allow only a certain width of characters, try getting the font of the control, and using some graphics function (MeasureString could be, I am no expert.) to measure the current contents plus the new character in the KeyDown event, and if the new text is wider than the control, don't accept the key. I hope to have given you some pointers. Good luck! -- LuisR


          Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

          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