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. Remove empty textbox spaces

Remove empty textbox spaces

Scheduled Pinned Locked Moved C#
databasequestion
18 Posts 4 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.
  • F ferronrsmith

    just one value for each text field. I have the address one under the other and there are making my page look bad. I want to format the empty spaces out

    Ferron

    L Offline
    L Offline
    Lodeclaw
    wrote on last edited by
    #5

    I'm no expert, so there's only one solution I could think of that would work:

    if (textbox1.TextLength < 1)
    {
    textbox2.Location.Y -= [int HeightOfTextbox];
    }

    I think the location 0,0 is in the upperleft corner, so this should be the right equation, but don't quote me on it. I haven't actually tested this.

    modified on Wednesday, February 11, 2009 4:45 PM

    D 1 Reply Last reply
    0
    • L Lodeclaw

      I'm no expert, so there's only one solution I could think of that would work:

      if (textbox1.TextLength < 1)
      {
      textbox2.Location.Y -= [int HeightOfTextbox];
      }

      I think the location 0,0 is in the upperleft corner, so this should be the right equation, but don't quote me on it. I haven't actually tested this.

      modified on Wednesday, February 11, 2009 4:45 PM

      D Offline
      D Offline
      Deresen
      wrote on last edited by
      #6

      Just for some extra info, you can do this slightly better: Use pre tags for instance. And do it like this:

      if(String.IsNullOrEmpty(textbox1.Text))
      {
      textbox.Visible = false;
      }

      F 1 Reply Last reply
      0
      • M Muammar

        Hey there, Lodeclaw was right, why don't you handle it while filling it "your database", anyways, you can use the DECODE function from the database

        DECODE(ColumnName,' ',''); //Finds a space and replace it with an empty string

        Or in the forms

        YourTextBox.Text = YourTextBox.Text.Replace(" ",""); //Which does the same but at the form level


        All generalizations are wrong, including this one! (\ /) (O.o) (><)

        F Offline
        F Offline
        ferronrsmith
        wrote on last edited by
        #7

        thanks guys for the help. It was gladly appreciated

        Ferron

        1 Reply Last reply
        0
        • D Deresen

          Just for some extra info, you can do this slightly better: Use pre tags for instance. And do it like this:

          if(String.IsNullOrEmpty(textbox1.Text))
          {
          textbox.Visible = false;
          }

          F Offline
          F Offline
          ferronrsmith
          wrote on last edited by
          #8

          visible doesn't remove the space there. jst don't show

          Ferron

          L 1 Reply Last reply
          0
          • F ferronrsmith

            visible doesn't remove the space there. jst don't show

            Ferron

            L Offline
            L Offline
            Lodeclaw
            wrote on last edited by
            #9

            He was commenting on the formatting of my post, but you should note how he set up his if-statement. :)

            F 1 Reply Last reply
            0
            • L Lodeclaw

              He was commenting on the formatting of my post, but you should note how he set up his if-statement. :)

              F Offline
              F Offline
              ferronrsmith
              wrote on last edited by
              #10

              I was trying to move some the labels with the location.Y method but it doesn't seem to be working. Any help on how get rid of the empty labels as well?

              Ferron

              L 1 Reply Last reply
              0
              • F ferronrsmith

                I was trying to move some the labels with the location.Y method but it doesn't seem to be working. Any help on how get rid of the empty labels as well?

                Ferron

                L Offline
                L Offline
                Lodeclaw
                wrote on last edited by
                #11

                Use the visible property shown in Deresen's post to hide labels you don't want shown. The labels should be able to move the same as your textboxes.

                if (String.IsNullOrEmpty(textbox.Text))
                {
                textbox.Location.Y -= textbox.Height;
                label.Location.Y -= textbox.Height;
                }

                modified on Wednesday, February 11, 2009 6:01 PM

                F 2 Replies Last reply
                0
                • L Lodeclaw

                  Use the visible property shown in Deresen's post to hide labels you don't want shown. The labels should be able to move the same as your textboxes.

                  if (String.IsNullOrEmpty(textbox.Text))
                  {
                  textbox.Location.Y -= textbox.Height;
                  label.Location.Y -= textbox.Height;
                  }

                  modified on Wednesday, February 11, 2009 6:01 PM

                  F Offline
                  F Offline
                  ferronrsmith
                  wrote on last edited by
                  #12

                  --------info-------- i want to remove the space created by the empty textbox/label or move it to another location where it doesn't take up space

                  Ferron

                  L D 2 Replies Last reply
                  0
                  • F ferronrsmith

                    --------info-------- i want to remove the space created by the empty textbox/label or move it to another location where it doesn't take up space

                    Ferron

                    L Offline
                    L Offline
                    Lodeclaw
                    wrote on last edited by
                    #13

                    I understand. In theory I figured it would work to move the controls below the empty textboxes up to fill in the gap, however I can't seem to get it working. Hopefully someone a little more knowledgeable will swing by. In the meantime I'll try and figure it out myself and let you know if I come up with anything. I'm still a newbie, myself.

                    1 Reply Last reply
                    0
                    • L Lodeclaw

                      Use the visible property shown in Deresen's post to hide labels you don't want shown. The labels should be able to move the same as your textboxes.

                      if (String.IsNullOrEmpty(textbox.Text))
                      {
                      textbox.Location.Y -= textbox.Height;
                      label.Location.Y -= textbox.Height;
                      }

                      modified on Wednesday, February 11, 2009 6:01 PM

                      F Offline
                      F Offline
                      ferronrsmith
                      wrote on last edited by
                      #14

                      Error 646 'System.Web.UI.WebControls.Label' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'System.Web.UI.WebControls.Label' could be found (are you missing a using directive or an assembly reference?)

                      That's the error is got when i tried using the Location.Y method

                      Ferron

                      L 1 Reply Last reply
                      0
                      • F ferronrsmith

                        Error 646 'System.Web.UI.WebControls.Label' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'System.Web.UI.WebControls.Label' could be found (are you missing a using directive or an assembly reference?)

                        That's the error is got when i tried using the Location.Y method

                        Ferron

                        L Offline
                        L Offline
                        Lodeclaw
                        wrote on last edited by
                        #15

                        Ah, I think I've figured it out. Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx[^] And you should understand why you have to do it like this:

                        if (String.IsNullOrEmpty(textbox.Text))
                        {
                        textbox.Location = new Point(textbox.Location.X,(textbox.Location.Y - textbox.Height));
                        label.Location = new Point(textbox.Location.X, (textbox.Location.Y - textbox.Height));
                        }

                        Again, I think it should work but I could be wrong. Hahaha...

                        D 1 Reply Last reply
                        0
                        • F ferronrsmith

                          --------info-------- i want to remove the space created by the empty textbox/label or move it to another location where it doesn't take up space

                          Ferron

                          D Offline
                          D Offline
                          Deresen
                          wrote on last edited by
                          #16

                          So you have this: line 1 line 2 line 4 and you want to have it like this: line 1 line 2 line 4 If I understand you well, you would like to have it is above. If that is what you want, you have to program dynamically. This is what I always do when it is about dynamic programming:

                          String[] myLines = {"line 1", "line 2", "", "line4"};
                          int lineheight = 23;//pixels between the labels
                          int top = 10;//align from top
                          int left = 20;//left align
                          int width = 200;
                          Label l;

                          foreach(String myLine in lines)
                          {
                          if(!String.IsNullOrEmpty(myLine))
                          {
                          l = new Label();
                          l.Location = new Point(left, top);
                          l.Width = width;
                          l.Text = myLine;
                          this.Controls.Add(l);//this will only work if the class you're working in is a Control class like form
                          top += lineheight;
                          }
                          }

                          1 Reply Last reply
                          0
                          • L Lodeclaw

                            Ah, I think I've figured it out. Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx[^] And you should understand why you have to do it like this:

                            if (String.IsNullOrEmpty(textbox.Text))
                            {
                            textbox.Location = new Point(textbox.Location.X,(textbox.Location.Y - textbox.Height));
                            label.Location = new Point(textbox.Location.X, (textbox.Location.Y - textbox.Height));
                            }

                            Again, I think it should work but I could be wrong. Hahaha...

                            D Offline
                            D Offline
                            Deresen
                            wrote on last edited by
                            #17

                            textBox.Location.X is the same as textBox.Left and textBox.Location.Y is the same as textBox.Top It's not that your code is bad, because it's the same. But it's a little shorter.

                            L 1 Reply Last reply
                            0
                            • D Deresen

                              textBox.Location.X is the same as textBox.Left and textBox.Location.Y is the same as textBox.Top It's not that your code is bad, because it's the same. But it's a little shorter.

                              L Offline
                              L Offline
                              Lodeclaw
                              wrote on last edited by
                              #18

                              Ah, I see! Thanks Deresen, that will be handy to know! :laugh:

                              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